Fix for Mark: get rid of old program tags whose IDs clash with the recalibrator/realigner tag (including if the id has a .1 at the end, etc.). Keeping them around is dangerous because we don't know which one refers to the latest run of the tool on the bam.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3798 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2010-07-15 19:13:50 +00:00
parent 6bf5df4eb5
commit ab84ed8c68
2 changed files with 25 additions and 6 deletions

View File

@ -58,7 +58,8 @@ import java.util.*;
public class IndelRealigner extends ReadWalker<Integer, Integer> {
public static final String ORIGINAL_CIGAR_TAG = "OC";
public static final String ORIGINAL_START_TAG = "OS";
public static final String ORIGINAL_START_TAG = "OS";
public static final String PROGRAM_RECORD_NAME = "GATK IndelRealigner";
@Argument(fullName="targetIntervals", shortName="targetIntervals", doc="intervals file output from RealignerTargetCreator", required=true)
protected String intervalsFile = null;
@ -214,10 +215,18 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
header.setSortOrder(SAMFileHeader.SortOrder.queryname);
if ( !NO_PG_TAG ) {
final SAMProgramRecord programRecord = new SAMProgramRecord("GATK IndelRealigner");
final SAMProgramRecord programRecord = new SAMProgramRecord(PROGRAM_RECORD_NAME);
final ResourceBundle headerInfo = TextFormattingUtils.loadResourceBundle("StingText");
programRecord.setProgramVersion(headerInfo.getString("org.broadinstitute.sting.gatk.version"));
header.addProgramRecord( programRecord );
List<SAMProgramRecord> oldRecords = header.getProgramRecords();
List<SAMProgramRecord> newRecords = new ArrayList<SAMProgramRecord>(oldRecords.size()+1);
for ( SAMProgramRecord record : oldRecords ) {
if ( !record.getId().startsWith(PROGRAM_RECORD_NAME) )
newRecords.add(record);
}
newRecords.add(programRecord);
header.setProgramRecords(newRecords);
}
SAMFileWriter writer = factory.makeBAMWriter(header, false, file, compressionLevel);

View File

@ -80,6 +80,8 @@ import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
@Requires({ DataSource.READS, DataSource.REFERENCE, DataSource.REFERENCE_BASES }) // This walker requires -I input.bam, it also requires -R reference.fasta
public class TableRecalibrationWalker extends ReadWalker<SAMRecord, SAMFileWriter> {
public static final String PROGRAM_RECORD_NAME = "GATK TableRecalibration";
/////////////////////////////
// Shared Arguments
/////////////////////////////
@ -89,7 +91,7 @@ public class TableRecalibrationWalker extends ReadWalker<SAMRecord, SAMFileWrite
// Command Line Arguments
/////////////////////////////
@Argument(fullName="output_bam", shortName="outputBam", doc="The output BAM file", required=true)
private StingSAMFileWriter OUTPUT_BAM;
private StingSAMFileWriter OUTPUT_BAM = null;
@Argument(fullName="preserve_qscores_less_than", shortName="pQ",
doc="Bases with quality scores less than this threshold won't be recalibrated, default=5. In general it's unsafe to change qualities scores below < 5, since base callers use these values to indicate random or bad bases", required=false)
private int PRESERVE_QSCORES_LESS_THAN = 5;
@ -256,7 +258,7 @@ public class TableRecalibrationWalker extends ReadWalker<SAMRecord, SAMFileWrite
// Take the header of the input SAM file and tweak it by adding in a new programRecord with the version number and list of covariates that were used
final SAMFileHeader header = getToolkit().getSAMFileHeader().clone();
if( !NO_PG_TAG ) {
final SAMProgramRecord programRecord = new SAMProgramRecord( "GATK TableRecalibration" );
final SAMProgramRecord programRecord = new SAMProgramRecord(PROGRAM_RECORD_NAME);
final ResourceBundle headerInfo = TextFormattingUtils.loadResourceBundle("StingText");
programRecord.setProgramVersion( headerInfo.getString("org.broadinstitute.sting.gatk.version") );
String commandLineString = "Covariates=[";
@ -280,7 +282,15 @@ public class TableRecalibrationWalker extends ReadWalker<SAMRecord, SAMFileWrite
commandLineString += "maxQ=" + MAX_QUALITY_SCORE + ", ";
commandLineString += "smoothing=" + SMOOTHING;
programRecord.setCommandLine( commandLineString );
header.addProgramRecord( programRecord );
List<SAMProgramRecord> oldRecords = header.getProgramRecords();
List<SAMProgramRecord> newRecords = new ArrayList<SAMProgramRecord>(oldRecords.size()+1);
for ( SAMProgramRecord record : oldRecords ) {
if ( !record.getId().startsWith(PROGRAM_RECORD_NAME) )
newRecords.add(record);
}
newRecords.add(programRecord);
header.setProgramRecords(newRecords);
// Write out the new header
OUTPUT_BAM.writeHeader( header );