Quick fix for Danny Lieber: flesh out the additional functionality required
to align to a reference other than what's specified in the header. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5133 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
b5d1aab8dc
commit
5e7a5cf924
|
|
@ -195,6 +195,12 @@ public class Alignment {
|
|||
if(newSAMHeader != null)
|
||||
read.setHeader(newSAMHeader);
|
||||
|
||||
// If we're realigning a previously aligned record, strip out the placement of the alignment.
|
||||
read.setReferenceName(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME);
|
||||
read.setAlignmentStart(SAMRecord.NO_ALIGNMENT_START);
|
||||
read.setMateReferenceName(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME);
|
||||
read.setMateAlignmentStart(SAMRecord.NO_ALIGNMENT_START);
|
||||
|
||||
if(alignment != null) {
|
||||
read.setReadUmappedFlag(false);
|
||||
read.setReferenceIndex(alignment.getContigIndex());
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
package org.broadinstitute.sting.alignment;
|
||||
|
||||
import org.broadinstitute.sting.gatk.io.StingSAMFileWriter;
|
||||
import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker;
|
||||
import org.broadinstitute.sting.commandline.Argument;
|
||||
import org.broadinstitute.sting.commandline.Output;
|
||||
|
|
@ -49,28 +50,19 @@ import java.io.PrintStream;
|
|||
*/
|
||||
@WalkerName("Align")
|
||||
public class AlignmentWalker extends ReadWalker<Integer,Integer> {
|
||||
@Argument(fullName="BWTPrefix",shortName="BWT",doc="Index files generated by bwa index -d bwtsw",required=false)
|
||||
private String prefix = null;
|
||||
|
||||
@Argument(fullName = "outputBam", shortName = "ob", doc = "Write output to this BAM filename instead of STDOUT", required = false)
|
||||
private String outputBamFile = null;
|
||||
@Argument(fullName="target_reference",shortName="target_ref",doc="The reference to which reads in the source file should be aligned. Alongside this reference should sit index files " +
|
||||
"generated by bwa index -d bwtsw. If unspecified, will default " +
|
||||
"to the reference specified via the -R argument.",required=false)
|
||||
private File targetReferenceFile = null;
|
||||
|
||||
@Output
|
||||
private PrintStream out = null;
|
||||
|
||||
@Argument(fullName = "bam_compression", shortName = "compress", doc = "Compression level to use for writing BAM files", required = false)
|
||||
private Integer bamCompression = 5;
|
||||
private StingSAMFileWriter out = null;
|
||||
|
||||
/**
|
||||
* The actual aligner.
|
||||
*/
|
||||
private BWACAligner aligner = null;
|
||||
|
||||
/**
|
||||
* Target for reads to output.
|
||||
*/
|
||||
private SAMFileWriter outputBam = null;
|
||||
|
||||
/**
|
||||
* New header to use, if desired.
|
||||
*/
|
||||
|
|
@ -81,23 +73,20 @@ public class AlignmentWalker extends ReadWalker<Integer,Integer> {
|
|||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
if(prefix == null)
|
||||
prefix = getToolkit().getArguments().referenceFile.getAbsolutePath();
|
||||
BWTFiles bwtFiles = new BWTFiles(prefix);
|
||||
if(targetReferenceFile == null)
|
||||
targetReferenceFile = getToolkit().getArguments().referenceFile;
|
||||
BWTFiles bwtFiles = new BWTFiles(targetReferenceFile.getAbsolutePath());
|
||||
BWAConfiguration configuration = new BWAConfiguration();
|
||||
aligner = new BWACAligner(bwtFiles,configuration);
|
||||
|
||||
// Take the header of the SAM file, tweak it by adding in the reference dictionary and specifying that the target file is unsorted.
|
||||
header = getToolkit().getSAMFileHeader().clone();
|
||||
SAMSequenceDictionary referenceDictionary =
|
||||
ReferenceSequenceFileFactory.getReferenceSequenceFile(getToolkit().getArguments().referenceFile).getSequenceDictionary();
|
||||
ReferenceSequenceFileFactory.getReferenceSequenceFile(targetReferenceFile).getSequenceDictionary();
|
||||
header.setSequenceDictionary(referenceDictionary);
|
||||
header.setSortOrder(SAMFileHeader.SortOrder.unsorted);
|
||||
|
||||
if (outputBamFile != null) {
|
||||
SAMFileWriterFactory factory = new SAMFileWriterFactory();
|
||||
outputBam = factory.makeBAMWriter(header, false, new File(outputBamFile), bamCompression);
|
||||
}
|
||||
out.writeHeader(header);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -109,11 +98,7 @@ public class AlignmentWalker extends ReadWalker<Integer,Integer> {
|
|||
@Override
|
||||
public Integer map(ReferenceContext ref, SAMRecord read, ReadMetaDataTracker metaDataTracker) {
|
||||
SAMRecord alignedRead = aligner.align(read,header);
|
||||
if (outputBam != null) {
|
||||
outputBam.addAlignment(alignedRead);
|
||||
} else {
|
||||
out.println(alignedRead.format());
|
||||
}
|
||||
out.addAlignment(alignedRead);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -142,8 +127,6 @@ public class AlignmentWalker extends ReadWalker<Integer,Integer> {
|
|||
@Override
|
||||
public void onTraversalDone(Integer result) {
|
||||
aligner.close();
|
||||
if (outputBam != null)
|
||||
outputBam.close();
|
||||
super.onTraversalDone(result);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class AlignerIntegrationTest extends WalkerTest {
|
|||
"-R /humgen/gsa-scr1/GATK_Data/bwa/human_b36_both.fasta" +
|
||||
" -T Align" +
|
||||
" -I " + validationDataLocation + "NA12878_Pilot1_20.trimmed.unmapped.bam" +
|
||||
" -ob %s",
|
||||
" -o %s",
|
||||
1, // just one output file
|
||||
Arrays.asList(md5));
|
||||
executeTest("testBasicAlignment", spec);
|
||||
|
|
|
|||
Loading…
Reference in New Issue