From c6d9848d0878e17f2503cc45a99eafb19adfa270 Mon Sep 17 00:00:00 2001 From: asivache Date: Fri, 27 Mar 2009 14:15:44 +0000 Subject: [PATCH] synchronizing latest changes git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@212 348d0f76-0448-11de-a6fe-93d51630548a --- .../playground/indels/IndelInspector.java | 38 ++++++++++--------- .../indels/IndelRecordPileCollector.java | 23 +++++------ .../sting/playground/indels/PileBuilder.java | 7 +--- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/java/src/org/broadinstitute/sting/playground/indels/IndelInspector.java b/java/src/org/broadinstitute/sting/playground/indels/IndelInspector.java index ebee842f7..7b7184ce3 100755 --- a/java/src/org/broadinstitute/sting/playground/indels/IndelInspector.java +++ b/java/src/org/broadinstitute/sting/playground/indels/IndelInspector.java @@ -26,7 +26,7 @@ public class IndelInspector extends CommandLineProgram { @Option(shortName="V",doc="Verbosity level: SILENT, PILESUMMARY, ALIGNMENTS", optional=true) public String VERBOSITY_LEVEL; @Option(doc="Output file (sam or bam) for non-indel related reads and indel reads that were not improved") public String OUT1; @Option(doc="Output file (sam or bam) for improved (realigned) indel related reads") public String OUT2; - @Option(doc="[paranoid] Output \"control\" file (sam or bam): all reads picked and processed by this tool will be also saved, unmodified, into this file", optional=true) public String OUTC; + @Option(doc="[paranoid] If true, all reads that would be otherwise picked and processed by this tool will be saved, unmodified, into OUT1", optional=true) public boolean CONTROL_RUN; @Option(doc="Error counting mode: MM - count mismatches only, ERR - count errors (arachne style), MG - count mismatches and gaps as one error each") public String ERR_MODE; @Option(doc="Maximum number of errors allowed (see ERR_MODE)") public Integer MAX_ERRS; // @Option(shortName="R", doc="Reference fasta or fasta.gz file") public File REF_FILE; @@ -63,23 +63,26 @@ public class IndelInspector extends CommandLineProgram { IndelRecordPileCollector col = null; PassThroughWriter ptWriter = new PassThroughWriter(OUT1,samReader.getFileHeader()); - PileBuilder pileBuilder = new PileBuilder(OUT2,samReader.getFileHeader(),ptWriter); - - SAMFileWriter controlWriter = null; - if ( OUTC != null ) controlWriter = new SAMFileWriterFactory().makeSAMOrBAMWriter(samReader.getFileHeader(),false,new File(OUTC)); + PileBuilder pileBuilder = null; + if ( ! CONTROL_RUN ) pileBuilder = new PileBuilder(OUT2,samReader.getFileHeader(),ptWriter); try { - col = new IndelRecordPileCollector(ptWriter, pileBuilder, controlWriter ); + if ( CONTROL_RUN ) col = new IndelRecordPileCollector(ptWriter, new DiscardingPileReceiver() ); + else col = new IndelRecordPileCollector(ptWriter, pileBuilder ); } catch(Exception e) { System.err.println(e.getMessage()); } if ( col == null ) return 1; - if ( VERBOSITY_LEVEL == null ) VERBOSITY_LEVEL = new String("SILENT"); - if ( VERBOSITY_LEVEL.toUpperCase().equals("SILENT")) pileBuilder.setVerbosity(pileBuilder.SILENT); - else if ( VERBOSITY_LEVEL.toUpperCase().equals("PILESUMMARY") ) pileBuilder.setVerbosity(pileBuilder.PILESUMMARY); - else if ( VERBOSITY_LEVEL.toUpperCase().equals("ALIGNMENTS") ) pileBuilder.setVerbosity(pileBuilder.ALIGNMENTS); - else { - System.out.println("Unrecognized VERBOSITY_LEVEL setting."); - return 1; + col.setControlRun(CONTROL_RUN); + + if ( ! CONTROL_RUN ) { + if ( VERBOSITY_LEVEL == null ) VERBOSITY_LEVEL = new String("SILENT"); + if ( VERBOSITY_LEVEL.toUpperCase().equals("SILENT")) pileBuilder.setVerbosity(pileBuilder.SILENT); + else if ( VERBOSITY_LEVEL.toUpperCase().equals("PILESUMMARY") ) pileBuilder.setVerbosity(pileBuilder.PILESUMMARY); + else if ( VERBOSITY_LEVEL.toUpperCase().equals("ALIGNMENTS") ) pileBuilder.setVerbosity(pileBuilder.ALIGNMENTS); + else { + System.out.println("Unrecognized VERBOSITY_LEVEL setting."); + return 1; + } } String cur_contig = null; @@ -97,7 +100,7 @@ public class IndelInspector extends CommandLineProgram { contig_seq = reference.get(r.getReferenceIndex()); String refstr = new String(contig_seq.getBases()); col.setReferenceSequence(refstr); - pileBuilder.setReferenceSequence(refstr); + if (!CONTROL_RUN) pileBuilder.setReferenceSequence(refstr); System.out.println("loaded contig "+cur_contig+" (index="+r.getReferenceIndex()+"); length="+contig_seq.getBases().length+" tst="+contig_seq.toString()); } } @@ -137,13 +140,14 @@ public class IndelInspector extends CommandLineProgram { } - pileBuilder.printStats(); + if ( ! CONTROL_RUN ) { + pileBuilder.printStats(); + pileBuilder.close(); + } System.out.println("done."); col.printLengthHistograms(); samReader.close(); - pileBuilder.close(); ptWriter.close(); - if ( controlWriter != null ) controlWriter.close(); return 0; } diff --git a/java/src/org/broadinstitute/sting/playground/indels/IndelRecordPileCollector.java b/java/src/org/broadinstitute/sting/playground/indels/IndelRecordPileCollector.java index eb01d5d08..5d98c5fca 100755 --- a/java/src/org/broadinstitute/sting/playground/indels/IndelRecordPileCollector.java +++ b/java/src/org/broadinstitute/sting/playground/indels/IndelRecordPileCollector.java @@ -89,7 +89,7 @@ public class IndelRecordPileCollector implements RecordReceiver { private RecordReceiver defaultReceiver; // we will send there records that do not overlap with regions of interest private RecordPileReceiver indelPileReceiver; // piles over indel regions will be sent there - private SAMFileWriter controlWriter; + private boolean controlRun = false; private String referenceSequence; @@ -99,12 +99,8 @@ public class IndelRecordPileCollector implements RecordReceiver { //+" Bndries="+mIndelRegionStart +":"+ mIndelRegionStop; } - public IndelRecordPileCollector(RecordReceiver rr, RecordPileReceiver rp) throws java.io.IOException { - this(rr,rp,null); - } - - public IndelRecordPileCollector(RecordReceiver rr, RecordPileReceiver rp, SAMFileWriter cw) throws java.io.IOException { + public IndelRecordPileCollector(RecordReceiver rr, RecordPileReceiver rp) throws java.io.IOException { mRecordPile = new LinkedList(); mAllIndels = new TreeSet >( new CountedObjectComparatorAdapter(new IntervalComparator())); @@ -120,7 +116,6 @@ public class IndelRecordPileCollector implements RecordReceiver { defaultReceiver = rr; indelPileReceiver = rp; referenceSequence = null; - controlWriter = cw; setWaitState(); } @@ -136,6 +131,8 @@ public class IndelRecordPileCollector implements RecordReceiver { mState = WAIT_STATE; // got to do this if we were in avoid_region state } + public void setControlRun(boolean c) { controlRun = c; } + public void setReferenceSequence(String contig) { referenceSequence = contig; } @@ -154,7 +151,6 @@ public class IndelRecordPileCollector implements RecordReceiver { SAMRecord r = i.next(); if ( r.getAlignmentEnd() <= pos ) { defaultReceiver.receive(r); - if ( controlWriter != null ) controlWriter.addAlignment(r); i.remove(); } else break; } @@ -170,7 +166,6 @@ public class IndelRecordPileCollector implements RecordReceiver { SAMRecord r = i.next(); if ( r.getAlignmentStart() >= pos ) { defaultReceiver.receive(r); - if ( controlWriter != null ) controlWriter.addAlignment(r); i.remove(); } else break; } @@ -204,7 +199,12 @@ public class IndelRecordPileCollector implements RecordReceiver { public void receive(final SAMRecord r) throws RuntimeException { if ( r.getReadUnmappedFlag() ) return; // read did not align, nothing to do - + + if ( controlRun ) { + defaultReceiver.receive(r); + return; + } + int currContig = r.getReferenceIndex(); int currPos = r.getAlignmentStart(); @@ -262,7 +262,6 @@ public class IndelRecordPileCollector implements RecordReceiver { // no indels or avoiding indels in bad region: send all records to defaultReceiver and clear the pile for ( SAMRecord r : mRecordPile ) { defaultReceiver.receive(r); - if ( controlWriter != null ) controlWriter.addAlignment(r); } setWaitState(); return; @@ -338,11 +337,9 @@ public class IndelRecordPileCollector implements RecordReceiver { System.out.print(finalPile.size() + " reads in the pile;") ; System.out.println(formatRange(finalTrain)); indelPileReceiver.receive(finalPile); - if ( controlWriter != null ) for ( SAMRecord r : finalPile ) controlWriter.addAlignment(r); } else { for ( SAMRecord r : finalPile ) { defaultReceiver.receive(r); - controlWriter.addAlignment(r); } } finalPile.clear(); diff --git a/java/src/org/broadinstitute/sting/playground/indels/PileBuilder.java b/java/src/org/broadinstitute/sting/playground/indels/PileBuilder.java index 72926831d..c3c661ad7 100755 --- a/java/src/org/broadinstitute/sting/playground/indels/PileBuilder.java +++ b/java/src/org/broadinstitute/sting/playground/indels/PileBuilder.java @@ -336,8 +336,8 @@ public class PileBuilder implements RecordPileReceiver { failedPileReceiver.receive(r); // nothing to do, send failed piles directly for writing continue; } - // we improved stuff!! let's reset the alignment parameters! + // we improved stuff!! let's reset the alignment parameters! int cons_offset = ma.getOffsetWrtConsensus(id); // offset of the read 'id' wrt multiple alignment's full consensus seq // offset of the realigned read r on the reference @@ -351,13 +351,10 @@ public class PileBuilder implements RecordPileReceiver { r.setAttribute("NM",new Integer(AlignmentUtils.numMismatches(r,referenceSequence))); - if ( r.getAlignmentStart() == 713655 ) { - System.out.println("!!!----> "+r.format()); - System.out.println("!!!----> "+AlignmentUtils.toString(cig) +" --- " +AlignmentUtils.toString(r.getCigar())); - } // System.out.println("writing " + id); samWriter.addAlignment(r); + } }