From 817278be4631f96680ad4f4843eb94dfc16b69fc Mon Sep 17 00:00:00 2001 From: kiran Date: Sun, 12 Apr 2009 19:42:24 +0000 Subject: [PATCH] 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 --- .../fourbasecaller/MatchSQTagToStrand.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 java/src/org/broadinstitute/sting/playground/fourbasecaller/MatchSQTagToStrand.java diff --git a/java/src/org/broadinstitute/sting/playground/fourbasecaller/MatchSQTagToStrand.java b/java/src/org/broadinstitute/sting/playground/fourbasecaller/MatchSQTagToStrand.java new file mode 100644 index 000000000..e9cd19f4d --- /dev/null +++ b/java/src/org/broadinstitute/sting/playground/fourbasecaller/MatchSQTagToStrand.java @@ -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; + } +}