vast speedup
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@729 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
6f1559bd77
commit
947bac5cdc
|
|
@ -18,17 +18,22 @@ public class CoverageBySample extends LocusWalker<String, String>
|
||||||
|
|
||||||
public boolean requiresReads() { return true; }
|
public boolean requiresReads() { return true; }
|
||||||
|
|
||||||
|
private SAMFileHeader header;
|
||||||
|
|
||||||
public void initialize()
|
public void initialize()
|
||||||
{
|
{
|
||||||
GenomeAnalysisEngine toolkit = this.getToolkit();
|
GenomeAnalysisEngine toolkit = this.getToolkit();
|
||||||
SAMFileHeader header = toolkit.getSamReader().getFileHeader();
|
this.header = toolkit.getEngine().getSAMHeader();
|
||||||
List<SAMReadGroupRecord> read_groups = header.getReadGroups();
|
List<SAMReadGroupRecord> read_groups = header.getReadGroups();
|
||||||
|
|
||||||
sample_names = new ArrayList<String>();
|
sample_names = new ArrayList<String>();
|
||||||
|
HashSet<String> unique_sample_names = new HashSet<String>();
|
||||||
|
|
||||||
for (int i = 0; i < read_groups.size(); i++)
|
for (int i = 0; i < read_groups.size(); i++)
|
||||||
{
|
{
|
||||||
String sample_name = read_groups.get(i).getSample();
|
String sample_name = read_groups.get(i).getSample();
|
||||||
|
if (unique_sample_names.contains(sample_name)) { continue; }
|
||||||
|
unique_sample_names.add(sample_name);
|
||||||
sample_names.add(sample_name);
|
sample_names.add(sample_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -36,30 +41,31 @@ public class CoverageBySample extends LocusWalker<String, String>
|
||||||
public String map(RefMetaDataTracker tracker, char ref, LocusContext context)
|
public String map(RefMetaDataTracker tracker, char ref, LocusContext context)
|
||||||
{
|
{
|
||||||
String line = context.getLocation().getContig() + " " + context.getLocation().getStart() + " " ;
|
String line = context.getLocation().getContig() + " " + context.getLocation().getStart() + " " ;
|
||||||
|
HashMap<String,Integer> counts = countReadsBySample(context);
|
||||||
for (int i = 0; i < sample_names.size(); i++)
|
for (int i = 0; i < sample_names.size(); i++)
|
||||||
{
|
{
|
||||||
int count = countReadsBySample(context, sample_names.get(i));
|
int count = counts.get(sample_names.get(i));
|
||||||
line += " " + count;
|
line += " " + count;
|
||||||
}
|
}
|
||||||
line += "\n";
|
line += "\n";
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countReadsBySample(LocusContext context, String sample_name)
|
private HashMap<String,Integer> countReadsBySample(LocusContext context)
|
||||||
{
|
{
|
||||||
int count = 0;
|
HashMap<String,Integer> counts = new HashMap<String,Integer>();
|
||||||
|
for (int i = 0; i < sample_names.size(); i++)
|
||||||
|
{
|
||||||
|
counts.put(sample_names.get(i), 0);
|
||||||
|
}
|
||||||
for (int i = 0; i < context.getReads().size(); i++)
|
for (int i = 0; i < context.getReads().size(); i++)
|
||||||
{
|
{
|
||||||
SAMRecord read = context.getReads().get(i);
|
SAMRecord read = context.getReads().get(i);
|
||||||
Integer offset = context.getOffsets().get(i);
|
|
||||||
String RG = (String)(read.getAttribute("RG"));
|
String RG = (String)(read.getAttribute("RG"));
|
||||||
String sample = read.getHeader().getReadGroup(RG).getSample();
|
String sample = header.getReadGroup(RG).getSample();
|
||||||
if (sample == sample_name)
|
counts.put(sample, counts.get(sample)+1);
|
||||||
{
|
|
||||||
count += 1;
|
|
||||||
}
|
}
|
||||||
}
|
return counts;
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTraversalDone()
|
public void onTraversalDone()
|
||||||
|
|
@ -82,7 +88,7 @@ public class CoverageBySample extends LocusWalker<String, String>
|
||||||
public String reduce(String line, String sum)
|
public String reduce(String line, String sum)
|
||||||
{
|
{
|
||||||
out.print(line);
|
out.print(line);
|
||||||
return sum + line;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue