In the new sharding system, if no read group is present, hallucinate one. Added

for test compatibility, but not sure whether we still need this feature.  TODO: Poll the group about this feature.


git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2949 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2010-03-07 23:01:34 +00:00
parent a7fe07c404
commit 9e107513d0
5 changed files with 46 additions and 9 deletions

View File

@ -305,8 +305,8 @@
<jvmarg value="-javaagent:${build.dir}/TestAgent.jar"/> <jvmarg value="-javaagent:${build.dir}/TestAgent.jar"/>
<formatter type="${testOutput}" usefile="${usefile}" /> <formatter type="${testOutput}" usefile="${usefile}" />
<classpath> <classpath>
<path refid="runtime.dependencies"/>
<pathelement location="build"/> <pathelement location="build"/>
<path refid="runtime.dependencies"/>
<pathelement location="${test.classes}"/> <pathelement location="${test.classes}"/>
<pathelement location="lib/junit-4.4.jar"/> <pathelement location="lib/junit-4.4.jar"/>
</classpath> </classpath>

View File

@ -415,6 +415,20 @@ public class BlockDrivenSAMDataSource extends SAMDataSource {
for(File readsFile: sourceInfo.getReadsFiles()) { for(File readsFile: sourceInfo.getReadsFiles()) {
SAMFileReader2 reader = new SAMFileReader2(readsFile,true); SAMFileReader2 reader = new SAMFileReader2(readsFile,true);
reader.setValidationStringency(sourceInfo.getValidationStringency()); reader.setValidationStringency(sourceInfo.getValidationStringency());
// If no read group is present, hallucinate one.
// TODO: Straw poll to see whether this is really required.
final SAMFileHeader header = reader.getFileHeader();
logger.debug(String.format("Sort order is: " + header.getSortOrder()));
if (reader.getFileHeader().getReadGroups().size() < 1) {
SAMReadGroupRecord rec = new SAMReadGroupRecord(readsFile.getName());
rec.setLibrary(readsFile.getName());
rec.setSample(readsFile.getName());
reader.getFileHeader().addReadGroup(rec);
}
readers.put(new SAMReaderID(readsFile),reader); readers.put(new SAMReaderID(readsFile),reader);
} }
} }

View File

@ -415,7 +415,7 @@ public class IndexDrivenSAMDataSource extends SAMDataSource {
private StingSAMIterator createIterator( DataStreamSegment segment ) { private StingSAMIterator createIterator( DataStreamSegment segment ) {
StingSAMIterator iterator = resourcePool.iterator(segment); StingSAMIterator iterator = resourcePool.iterator(segment);
StingSAMIterator malformedWrappedIterator = new MalformedSAMFilteringIterator( getHeader(), iterator, violations ); StingSAMIterator malformedWrappedIterator = new MalformedSAMFilteringIterator( getHeader(), iterator, violations );
StingSAMIterator readWrappingIterator = new ReadWrappingIterator(malformedWrappedIterator); StingSAMIterator readWrappingIterator = new ReadFormattingIterator(malformedWrappedIterator);
return readWrappingIterator; return readWrappingIterator;
} }
} }

View File

@ -12,7 +12,6 @@ import org.broadinstitute.sting.utils.sam.SAMReadViolationHistogram;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
import java.util.Map;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
@ -182,7 +181,7 @@ public abstract class SAMDataSource implements SimpleDataSource {
Boolean noValidationOfReadOrder, Boolean noValidationOfReadOrder,
Collection<SamRecordFilter> supplementalFilters) { Collection<SamRecordFilter> supplementalFilters) {
wrappedIterator = new MalformedSAMFilteringIterator(getHeader(),wrappedIterator,violations ); wrappedIterator = new MalformedSAMFilteringIterator(getHeader(),wrappedIterator,violations );
wrappedIterator = new ReadWrappingIterator(wrappedIterator); wrappedIterator = new ReadFormattingIterator(wrappedIterator);
// NOTE: this (and other filtering) should be done before on-the-fly sorting // NOTE: this (and other filtering) should be done before on-the-fly sorting
// as there is no reason to sort something that we will end of throwing away // as there is no reason to sort something that we will end of throwing away

View File

@ -1,17 +1,27 @@
package org.broadinstitute.sting.gatk.iterators; package org.broadinstitute.sting.gatk.iterators;
import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMRecord;
import net.sf.samtools.SAMTag;
import net.sf.samtools.SAMReadGroupRecord;
import org.broadinstitute.sting.gatk.Reads; import org.broadinstitute.sting.gatk.Reads;
import org.broadinstitute.sting.utils.sam.GATKSAMRecord; import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
import org.apache.log4j.Logger;
import java.util.List;
/** /**
* An iterator which wraps each SAMRecord inside a wrapper class, bringing new functionality to the read while * An iterator which does post-processing of a read, including potentially wrapping
* presenting the original SAMRecord interface. * the read in something with a compatible interface or replacing the read entirely.
* *
* @author mhanna * @author mhanna
* @version 0.1 * @version 0.1
*/ */
public class ReadWrappingIterator implements StingSAMIterator { public class ReadFormattingIterator implements StingSAMIterator {
/**
* Logger.
*/
protected static Logger logger = Logger.getLogger(ReadFormattingIterator.class);
/** /**
* Iterator to which to pass * Iterator to which to pass
*/ */
@ -21,7 +31,7 @@ public class ReadWrappingIterator implements StingSAMIterator {
* Decorate the given iterator inside a ReadWrappingIterator. * Decorate the given iterator inside a ReadWrappingIterator.
* @param wrappedIterator iterator * @param wrappedIterator iterator
*/ */
public ReadWrappingIterator(StingSAMIterator wrappedIterator) { public ReadFormattingIterator(StingSAMIterator wrappedIterator) {
this.wrappedIterator = wrappedIterator; this.wrappedIterator = wrappedIterator;
} }
@ -65,7 +75,21 @@ public class ReadWrappingIterator implements StingSAMIterator {
* no next exists. * no next exists.
*/ */
public SAMRecord next() { public SAMRecord next() {
return new GATKSAMRecord(wrappedIterator.next()); SAMRecord read = wrappedIterator.next();
// if we don't have a read group, set one.
// TODO: Straw poll to see whether this is really required.
if (read.getAttribute(SAMTag.RG.toString()) == null && read.getReader() != null) {
List<SAMReadGroupRecord> readGroups = read.getReader().getFileHeader().getReadGroups();
if (readGroups.size() == 1) {
read.setAttribute(SAMTag.RG.toString(), readGroups.get(0).getReadGroupId());
read.setAttribute(SAMTag.SM.toString(), readGroups.get(0).getReadGroupId());
} else {
logger.warn("Unable to set read group of ungrouped read: unable to pick default group, there are " + readGroups.size() + " possible.");
}
}
return new GATKSAMRecord(read);
} }
/** /**