If a SAMRecord is on the negative strand, reverse complement the SQ tag.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@370 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
kiran 2009-04-12 19:42:24 +00:00
parent 1d5a22cacf
commit 817278be46
1 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,50 @@
package org.broadinstitute.sting.playground.fourbasecaller;
import org.broadinstitute.sting.utils.cmdLine.CommandLineProgram;
import org.broadinstitute.sting.utils.QualityUtils;
import java.io.File;
import net.sf.samtools.SAMFileReader;
import net.sf.samtools.SAMFileWriter;
import net.sf.samtools.SAMFileWriterFactory;
import net.sf.samtools.SAMRecord;
public class MatchSQTagToStrand extends CommandLineProgram {
public static MatchSQTagToStrand Instance = null;
public File SAM_IN;
public File SAM_OUT;
public static void main(String[] argv) {
Instance = new MatchSQTagToStrand();
start(Instance, argv);
}
protected void setupArgs() {
m_parser.addRequiredArg("sam_in", "I", "Input SAM file", "SAM_IN");
m_parser.addRequiredArg("sam_out", "O", "Output SAM file", "SAM_OUT");
}
protected int execute() {
SAMFileReader sf = new SAMFileReader(SAM_IN);
sf.setValidationStringency(SAMFileReader.ValidationStringency.SILENT);
SAMFileWriter sw = new SAMFileWriterFactory().makeSAMOrBAMWriter(sf.getFileHeader(), true, SAM_OUT);
for (SAMRecord sr : sf) {
if (sr.getReadNegativeStrandFlag()) {
byte[] sq = (byte[]) sr.getAttribute("SQ");
sq = QualityUtils.reverseComplementCompressedQualityArray(sq);
sr.setAttribute("SQ", sq);
}
sw.addAlignment(sr);
}
sw.close();
return 0;
}
}