Merge pull request #45 from broadinstitute/mc_fix_indelrealigner_GSA-774
Fix to the Indel Realigner bug described in GSA-774
This commit is contained in:
commit
0055a6f1cd
|
|
@ -153,6 +153,7 @@ public class ConstrainedMateFixingManager {
|
|||
* are assumes to not be allowed to move in the incoming read stream.
|
||||
*/
|
||||
final int maxInsertSizeForMovingReadPairs;
|
||||
final int initialCapacity = 5000;
|
||||
|
||||
final GenomeLocParser genomeLocParser;
|
||||
private GenomeLoc lastLocFlushed = null;
|
||||
|
|
@ -161,12 +162,12 @@ public class ConstrainedMateFixingManager {
|
|||
|
||||
/** read.name -> records */
|
||||
HashMap<String, SAMRecordHashObject> forMateMatching = new HashMap<String, SAMRecordHashObject>();
|
||||
TreeSet<SAMRecord> waitingReads = new TreeSet<SAMRecord>(comparer);
|
||||
PriorityQueue<SAMRecord> waitingReads = new PriorityQueue<SAMRecord>(initialCapacity, comparer);
|
||||
|
||||
private SAMRecord remove(TreeSet<SAMRecord> treeSet) {
|
||||
final SAMRecord first = treeSet.first();
|
||||
if ( !treeSet.remove(first) )
|
||||
throw new UserException("Error caching SAM record " + first.getReadName() + ", which is usually caused by malformed SAM/BAM files in which multiple identical copies of a read are present.");
|
||||
private SAMRecord remove(PriorityQueue<SAMRecord> queue) {
|
||||
SAMRecord first = queue.poll();
|
||||
if (first == null)
|
||||
throw new UserException("Error caching SAM record -- priority queue is empty, and yet there was an attempt to poll it -- which is usually caused by malformed SAM/BAM files in which multiple identical copies of a read are present.");
|
||||
return first;
|
||||
}
|
||||
|
||||
|
|
@ -243,8 +244,8 @@ public class ConstrainedMateFixingManager {
|
|||
|
||||
// if the new read is on a different contig or we have too many reads, then we need to flush the queue and clear the map
|
||||
boolean tooManyReads = getNReadsInQueue() >= MAX_RECORDS_IN_MEMORY;
|
||||
if ( (canFlush && tooManyReads) || (getNReadsInQueue() > 0 && !waitingReads.first().getReferenceIndex().equals(newRead.getReferenceIndex())) ) {
|
||||
if ( DEBUG ) logger.warn("Flushing queue on " + (tooManyReads ? "too many reads" : ("move to new contig: " + newRead.getReferenceName() + " from " + waitingReads.first().getReferenceName())) + " at " + newRead.getAlignmentStart());
|
||||
if ( (canFlush && tooManyReads) || (getNReadsInQueue() > 0 && !waitingReads.peek().getReferenceIndex().equals(newRead.getReferenceIndex())) ) {
|
||||
if ( DEBUG ) logger.warn("Flushing queue on " + (tooManyReads ? "too many reads" : ("move to new contig: " + newRead.getReferenceName() + " from " + waitingReads.peek().getReferenceName())) + " at " + newRead.getAlignmentStart());
|
||||
|
||||
while ( getNReadsInQueue() > 1 ) {
|
||||
// emit to disk
|
||||
|
|
@ -307,7 +308,7 @@ public class ConstrainedMateFixingManager {
|
|||
|
||||
if ( ++counter % EMIT_FREQUENCY == 0 ) {
|
||||
while ( ! waitingReads.isEmpty() ) { // there's something in the queue
|
||||
SAMRecord read = waitingReads.first();
|
||||
SAMRecord read = waitingReads.peek();
|
||||
|
||||
if ( noReadCanMoveBefore(read.getAlignmentStart(), newRead) &&
|
||||
(!pairedReadIsMovable(read) // we won't try to move such a read
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@
|
|||
|
||||
package org.broadinstitute.sting.gatk.walkers.indels;
|
||||
|
||||
import com.google.java.contract.Requires;
|
||||
import net.sf.samtools.*;
|
||||
import net.sf.samtools.util.RuntimeIOException;
|
||||
import net.sf.samtools.util.SequenceUtil;
|
||||
|
|
@ -61,7 +60,10 @@ import org.broadinstitute.sting.gatk.iterators.ReadTransformer;
|
|||
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
||||
import org.broadinstitute.sting.gatk.walkers.BAQMode;
|
||||
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
|
||||
import org.broadinstitute.sting.utils.*;
|
||||
import org.broadinstitute.sting.utils.BaseUtils;
|
||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||
import org.broadinstitute.sting.utils.SWPairwiseAlignment;
|
||||
import org.broadinstitute.sting.utils.Utils;
|
||||
import org.broadinstitute.sting.utils.baq.BAQ;
|
||||
import org.broadinstitute.sting.utils.collections.Pair;
|
||||
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
|
||||
|
|
@ -76,7 +78,6 @@ import org.broadinstitute.sting.utils.sam.NWaySAMFileWriter;
|
|||
import org.broadinstitute.sting.utils.sam.ReadUtils;
|
||||
import org.broadinstitute.sting.utils.text.TextFormattingUtils;
|
||||
import org.broadinstitute.sting.utils.text.XReadLines;
|
||||
import org.broadinstitute.sting.utils.BaseUtils;
|
||||
import org.broadinstitute.variant.variantcontext.VariantContext;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -309,7 +310,7 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
private boolean sawReadInCurrentInterval = false;
|
||||
|
||||
// the reads and known indels that fall into the current interval
|
||||
private final ReadBin readsToClean = new ReadBin();
|
||||
private ReadBin readsToClean;
|
||||
private final ArrayList<GATKSAMRecord> readsNotToClean = new ArrayList<GATKSAMRecord>();
|
||||
private final ArrayList<VariantContext> knownIndelsToTry = new ArrayList<VariantContext>();
|
||||
private final HashSet<Object> indelRodsSeen = new HashSet<Object>();
|
||||
|
|
@ -372,6 +373,7 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
}
|
||||
|
||||
public void initialize() {
|
||||
readsToClean = new ReadBin(getToolkit().getGenomeLocParser(), REFERENCE_PADDING);
|
||||
|
||||
if ( N_WAY_OUT == null && writer == null ) {
|
||||
throw new UserException.CommandLineException("Either -o or -nWayOut must be specified");
|
||||
|
|
@ -469,12 +471,14 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
try {
|
||||
final String version = headerInfo.getString("org.broadinstitute.sting.gatk.version");
|
||||
programRecord.setProgramVersion(version);
|
||||
} catch (MissingResourceException e) {}
|
||||
} catch (MissingResourceException e) {
|
||||
// this is left empty on purpose (perhaps Andrey knows why?)
|
||||
}
|
||||
programRecord.setCommandLine(getToolkit().createApproximateCommandLineArgumentString(getToolkit(), this));
|
||||
return programRecord;
|
||||
}
|
||||
|
||||
private void emit(final SAMRecord read) {
|
||||
private void emit(final GATKSAMRecord read) {
|
||||
|
||||
// check to see whether the read was modified by looking at the temporary tag
|
||||
boolean wasModified = readsActuallyCleaned.contains(read);
|
||||
|
|
@ -530,7 +534,7 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
readsToClean.add(read);
|
||||
|
||||
// add the rods to the list of known variants
|
||||
populateKnownIndels(metaDataTracker, ref);
|
||||
populateKnownIndels(metaDataTracker);
|
||||
}
|
||||
|
||||
if ( readsToClean.size() + readsNotToClean.size() >= MAX_READS ) {
|
||||
|
|
@ -539,6 +543,7 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
}
|
||||
}
|
||||
else { // the read is past the current interval
|
||||
logger.debug(currentInterval.toString() + "\t" + read.getAlignmentStart() );
|
||||
cleanAndCallMap(ref, read, metaDataTracker, readLoc);
|
||||
}
|
||||
|
||||
|
|
@ -642,7 +647,7 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
}
|
||||
}
|
||||
|
||||
private void populateKnownIndels(RefMetaDataTracker metaDataTracker, ReferenceContext ref) {
|
||||
private void populateKnownIndels(RefMetaDataTracker metaDataTracker) {
|
||||
for ( final VariantContext vc : metaDataTracker.getValues(known) ) {
|
||||
if ( indelRodsSeen.contains(vc) )
|
||||
continue;
|
||||
|
|
@ -705,10 +710,8 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
// if ( debugOn ) System.out.println("------\nChecking consenses...\n--------\n");
|
||||
|
||||
Consensus bestConsensus = null;
|
||||
Iterator<Consensus> iter = altConsenses.iterator();
|
||||
|
||||
while ( iter.hasNext() ) {
|
||||
Consensus consensus = iter.next();
|
||||
for (Consensus consensus : altConsenses) {
|
||||
//logger.debug("Trying new consensus: " + consensus.cigar + " " + new String(consensus.str));
|
||||
|
||||
// if ( DEBUG ) {
|
||||
|
|
@ -723,34 +726,34 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
|
||||
// if ( debugOn ) System.out.println("Consensus: "+consensus.str);
|
||||
|
||||
for ( int j = 0; j < altReads.size(); j++ ) {
|
||||
for (int j = 0; j < altReads.size(); j++) {
|
||||
AlignedRead toTest = altReads.get(j);
|
||||
Pair<Integer, Integer> altAlignment = findBestOffset(consensus.str, toTest, leftmostIndex);
|
||||
|
||||
// the mismatch score is the min of its alignment vs. the reference and vs. the alternate
|
||||
int myScore = altAlignment.second;
|
||||
|
||||
if ( myScore > toTest.getAlignerMismatchScore() || myScore >= toTest.getMismatchScoreToReference() )
|
||||
if (myScore > toTest.getAlignerMismatchScore() || myScore >= toTest.getMismatchScoreToReference())
|
||||
myScore = toTest.getMismatchScoreToReference();
|
||||
// keep track of reads that align better to the alternate consensus.
|
||||
// By pushing alignments with equal scores to the alternate, it means we'll over-call (het -> hom non ref) but are less likely to under-call (het -> ref, het non ref -> het)
|
||||
// keep track of reads that align better to the alternate consensus.
|
||||
// By pushing alignments with equal scores to the alternate, it means we'll over-call (het -> hom non ref) but are less likely to under-call (het -> ref, het non ref -> het)
|
||||
else
|
||||
consensus.readIndexes.add(new Pair<Integer, Integer>(j, altAlignment.first));
|
||||
|
||||
//logger.debug(consensus.cigar + " vs. " + toTest.getRead().getReadName() + "-" + toTest.getRead().getReadString() + " => " + myScore + " vs. " + toTest.getMismatchScoreToReference());
|
||||
if ( !toTest.getRead().getDuplicateReadFlag() )
|
||||
if (!toTest.getRead().getDuplicateReadFlag())
|
||||
consensus.mismatchSum += myScore;
|
||||
|
||||
// optimization: once the mismatch sum is higher than the best consensus, quit since this one can't win
|
||||
// THIS MUST BE DISABLED IF WE DECIDE TO ALLOW MORE THAN ONE ALTERNATE CONSENSUS!
|
||||
if ( bestConsensus != null && consensus.mismatchSum > bestConsensus.mismatchSum )
|
||||
if (bestConsensus != null && consensus.mismatchSum > bestConsensus.mismatchSum)
|
||||
break;
|
||||
}
|
||||
|
||||
//logger.debug("Mismatch sum of new consensus: " + consensus.mismatchSum);
|
||||
if ( bestConsensus == null || bestConsensus.mismatchSum > consensus.mismatchSum) {
|
||||
if (bestConsensus == null || bestConsensus.mismatchSum > consensus.mismatchSum) {
|
||||
// we do not need this alt consensus, release memory right away!!
|
||||
if ( bestConsensus != null )
|
||||
if (bestConsensus != null)
|
||||
bestConsensus.readIndexes.clear();
|
||||
bestConsensus = consensus;
|
||||
//logger.debug("New consensus " + bestConsensus.cigar + " is now best consensus");
|
||||
|
|
@ -796,9 +799,9 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
StringBuilder str = new StringBuilder();
|
||||
str.append(reads.get(0).getReferenceName());
|
||||
int position = bestConsensus.positionOnReference + bestConsensus.cigar.getCigarElement(0).getLength();
|
||||
str.append("\t" + (leftmostIndex + position - 1));
|
||||
str.append("\t").append(leftmostIndex + position - 1);
|
||||
CigarElement ce = bestConsensus.cigar.getCigarElement(1);
|
||||
str.append("\t" + ce.getLength() + "\t" + ce.getOperator() + "\t");
|
||||
str.append("\t").append(ce.getLength()).append("\t").append(ce.getOperator()).append("\t");
|
||||
int length = ce.getLength();
|
||||
if ( ce.getOperator() == CigarOperator.D ) {
|
||||
for ( int i = 0; i < length; i++)
|
||||
|
|
@ -807,7 +810,7 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
for ( int i = 0; i < length; i++)
|
||||
str.append((char)bestConsensus.str[position+i]);
|
||||
}
|
||||
str.append("\t" + (((double)(totalRawMismatchSum - bestConsensus.mismatchSum))/10.0) + "\n");
|
||||
str.append("\t").append((((double) (totalRawMismatchSum - bestConsensus.mismatchSum)) / 10.0)).append("\n");
|
||||
try {
|
||||
indelOutput.write(str.toString());
|
||||
indelOutput.flush();
|
||||
|
|
@ -913,7 +916,6 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
final byte[] reference) {
|
||||
|
||||
long totalRawMismatchSum = 0L;
|
||||
|
||||
for ( final GATKSAMRecord read : reads ) {
|
||||
|
||||
// we can not deal with screwy records
|
||||
|
|
@ -1278,23 +1280,22 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
for ( int i=0; i < reference.length; i++ )
|
||||
originalMismatchBases[i] = totalOriginalBases[i] = cleanedMismatchBases[i] = totalCleanedBases[i] = 0;
|
||||
|
||||
for (int i=0; i < reads.size(); i++) {
|
||||
final AlignedRead read = reads.get(i);
|
||||
if ( read.getRead().getAlignmentBlocks().size() > 1 )
|
||||
continue;
|
||||
for (final AlignedRead read : reads) {
|
||||
if (read.getRead().getAlignmentBlocks().size() > 1)
|
||||
continue;
|
||||
|
||||
int refIdx = read.getOriginalAlignmentStart() - leftmostIndex;
|
||||
final byte[] readStr = read.getReadBases();
|
||||
final byte[] quals = read.getBaseQualities();
|
||||
|
||||
for (int j=0; j < readStr.length; j++, refIdx++ ) {
|
||||
if ( refIdx < 0 || refIdx >= reference.length ) {
|
||||
for (int j = 0; j < readStr.length; j++, refIdx++) {
|
||||
if (refIdx < 0 || refIdx >= reference.length) {
|
||||
//System.out.println( "Read: "+read.getRead().getReadName() + "; length = " + readStr.length() );
|
||||
//System.out.println( "Ref left: "+ leftmostIndex +"; ref length=" + reference.length() + "; read alignment start: "+read.getOriginalAlignmentStart() );
|
||||
break;
|
||||
}
|
||||
totalOriginalBases[refIdx] += quals[j];
|
||||
if ( readStr[j] != reference[refIdx] )
|
||||
if (readStr[j] != reference[refIdx])
|
||||
originalMismatchBases[refIdx] += quals[j];
|
||||
}
|
||||
|
||||
|
|
@ -1302,18 +1303,18 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
refIdx = read.getAlignmentStart() - leftmostIndex;
|
||||
int altIdx = 0;
|
||||
Cigar c = read.getCigar();
|
||||
for (int j = 0 ; j < c.numCigarElements() ; j++) {
|
||||
for (int j = 0; j < c.numCigarElements(); j++) {
|
||||
CigarElement ce = c.getCigarElement(j);
|
||||
int elementLength = ce.getLength();
|
||||
switch ( ce.getOperator() ) {
|
||||
switch (ce.getOperator()) {
|
||||
case M:
|
||||
case EQ:
|
||||
case X:
|
||||
for (int k = 0 ; k < elementLength ; k++, refIdx++, altIdx++ ) {
|
||||
if ( refIdx >= reference.length )
|
||||
for (int k = 0; k < elementLength; k++, refIdx++, altIdx++) {
|
||||
if (refIdx >= reference.length)
|
||||
break;
|
||||
totalCleanedBases[refIdx] += quals[altIdx];
|
||||
if ( readStr[altIdx] != reference[refIdx] )
|
||||
if (readStr[altIdx] != reference[refIdx])
|
||||
cleanedMismatchBases[refIdx] += quals[altIdx];
|
||||
}
|
||||
break;
|
||||
|
|
@ -1348,8 +1349,7 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
}
|
||||
if ( snpsOutput != null ) {
|
||||
if ( didMismatch ) {
|
||||
sb.append(reads.get(0).getRead().getReferenceName() + ":");
|
||||
sb.append((leftmostIndex + i));
|
||||
sb.append(reads.get(0).getRead().getReferenceName()).append(":").append(leftmostIndex + i);
|
||||
if ( stillMismatches )
|
||||
sb.append(" SAME_SNP\n");
|
||||
else
|
||||
|
|
@ -1603,52 +1603,4 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
|
|||
}
|
||||
}
|
||||
|
||||
private class ReadBin implements HasGenomeLocation {
|
||||
|
||||
private final ArrayList<GATKSAMRecord> reads = new ArrayList<GATKSAMRecord>();
|
||||
private byte[] reference = null;
|
||||
private GenomeLoc loc = null;
|
||||
|
||||
public ReadBin() { }
|
||||
|
||||
// Return false if we can't process this read bin because the reads are not correctly overlapping.
|
||||
// This can happen if e.g. there's a large known indel with no overlapping reads.
|
||||
public void add(GATKSAMRecord read) {
|
||||
|
||||
GenomeLoc locForRead = getToolkit().getGenomeLocParser().createGenomeLoc(read);
|
||||
if ( loc == null )
|
||||
loc = locForRead;
|
||||
else if ( locForRead.getStop() > loc.getStop() )
|
||||
loc = getToolkit().getGenomeLocParser().createGenomeLoc(loc.getContig(), loc.getStart(), locForRead.getStop());
|
||||
|
||||
reads.add(read);
|
||||
}
|
||||
|
||||
public List<GATKSAMRecord> getReads() { return reads; }
|
||||
|
||||
@Requires("referenceReader.isUppercasingBases()")
|
||||
public byte[] getReference(CachingIndexedFastaSequenceFile referenceReader) {
|
||||
// set up the reference if we haven't done so yet
|
||||
if ( reference == null ) {
|
||||
// first, pad the reference to handle deletions in narrow windows (e.g. those with only 1 read)
|
||||
int padLeft = Math.max(loc.getStart()-REFERENCE_PADDING, 1);
|
||||
int padRight = Math.min(loc.getStop()+REFERENCE_PADDING, referenceReader.getSequenceDictionary().getSequence(loc.getContig()).getSequenceLength());
|
||||
loc = getToolkit().getGenomeLocParser().createGenomeLoc(loc.getContig(), padLeft, padRight);
|
||||
reference = referenceReader.getSubsequenceAt(loc.getContig(), loc.getStart(), loc.getStop()).getBases();
|
||||
}
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
public GenomeLoc getLocation() { return loc; }
|
||||
|
||||
public int size() { return reads.size(); }
|
||||
|
||||
public void clear() {
|
||||
reads.clear();
|
||||
reference = null;
|
||||
loc = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* By downloading the PROGRAM you agree to the following terms of use:
|
||||
*
|
||||
* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY
|
||||
*
|
||||
* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE).
|
||||
*
|
||||
* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and
|
||||
* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions.
|
||||
* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows:
|
||||
*
|
||||
* 1. DEFINITIONS
|
||||
* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE.
|
||||
*
|
||||
* 2. LICENSE
|
||||
* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM.
|
||||
* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement.
|
||||
* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement.
|
||||
* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM.
|
||||
*
|
||||
* 3. OWNERSHIP OF INTELLECTUAL PROPERTY
|
||||
* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication.
|
||||
* Copyright 2012 Broad Institute, Inc.
|
||||
* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc.
|
||||
* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes.
|
||||
*
|
||||
* 4. INDEMNIFICATION
|
||||
* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement.
|
||||
*
|
||||
* 5. NO REPRESENTATIONS OR WARRANTIES
|
||||
* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME.
|
||||
* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
|
||||
*
|
||||
* 6. ASSIGNMENT
|
||||
* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void.
|
||||
*
|
||||
* 7. MISCELLANEOUS
|
||||
* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries.
|
||||
* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes.
|
||||
* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4.
|
||||
* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt.
|
||||
* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter.
|
||||
* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement.
|
||||
* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.gatk.walkers.indels;
|
||||
|
||||
import com.google.java.contract.Requires;
|
||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||
import org.broadinstitute.sting.utils.GenomeLocParser;
|
||||
import org.broadinstitute.sting.utils.HasGenomeLocation;
|
||||
import org.broadinstitute.sting.utils.fasta.CachingIndexedFastaSequenceFile;
|
||||
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: carneiro
|
||||
* Date: 2/16/13
|
||||
* Time: 11:15 PM
|
||||
*/
|
||||
class ReadBin implements HasGenomeLocation {
|
||||
|
||||
private final ArrayList<GATKSAMRecord> reads = new ArrayList<GATKSAMRecord>();
|
||||
private byte[] reference = null;
|
||||
private GenomeLoc loc = null;
|
||||
private final GenomeLocParser parser;
|
||||
private final int referencePadding;
|
||||
|
||||
public ReadBin(final GenomeLocParser parser, final int referencePadding) {
|
||||
this.parser = parser;
|
||||
this.referencePadding = referencePadding;
|
||||
}
|
||||
|
||||
// Return false if we can't process this read bin because the reads are not correctly overlapping.
|
||||
// This can happen if e.g. there's a large known indel with no overlapping reads.
|
||||
public void add(GATKSAMRecord read) {
|
||||
|
||||
final int readStart = read.getSoftStart();
|
||||
final int readStop = read.getSoftEnd();
|
||||
if ( loc == null )
|
||||
loc = parser.createGenomeLoc(read.getReferenceName(), readStart, readStop);
|
||||
else if ( readStop > loc.getStop() )
|
||||
loc = parser.createGenomeLoc(loc.getContig(), loc.getStart(), readStop);
|
||||
|
||||
reads.add(read);
|
||||
}
|
||||
|
||||
public List<GATKSAMRecord> getReads() {
|
||||
return reads;
|
||||
}
|
||||
|
||||
@Requires("referenceReader.isUppercasingBases()")
|
||||
public byte[] getReference(CachingIndexedFastaSequenceFile referenceReader) {
|
||||
// set up the reference if we haven't done so yet
|
||||
if ( reference == null ) {
|
||||
// first, pad the reference to handle deletions in narrow windows (e.g. those with only 1 read)
|
||||
int padLeft = Math.max(loc.getStart()- referencePadding, 1);
|
||||
int padRight = Math.min(loc.getStop()+ referencePadding, referenceReader.getSequenceDictionary().getSequence(loc.getContig()).getSequenceLength());
|
||||
loc = parser.createGenomeLoc(loc.getContig(), loc.getContigIndex(), padLeft, padRight);
|
||||
reference = referenceReader.getSubsequenceAt(loc.getContig(), loc.getStart(), loc.getStop()).getBases();
|
||||
}
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
public GenomeLoc getLocation() {
|
||||
return loc;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return reads.size();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
reads.clear();
|
||||
reference = null;
|
||||
loc = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* By downloading the PROGRAM you agree to the following terms of use:
|
||||
*
|
||||
* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY
|
||||
*
|
||||
* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE).
|
||||
*
|
||||
* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and
|
||||
* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions.
|
||||
* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows:
|
||||
*
|
||||
* 1. DEFINITIONS
|
||||
* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE.
|
||||
*
|
||||
* 2. LICENSE
|
||||
* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM.
|
||||
* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement.
|
||||
* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement.
|
||||
* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM.
|
||||
*
|
||||
* 3. OWNERSHIP OF INTELLECTUAL PROPERTY
|
||||
* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication.
|
||||
* Copyright 2012 Broad Institute, Inc.
|
||||
* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc.
|
||||
* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes.
|
||||
*
|
||||
* 4. INDEMNIFICATION
|
||||
* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement.
|
||||
*
|
||||
* 5. NO REPRESENTATIONS OR WARRANTIES
|
||||
* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME.
|
||||
* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
|
||||
*
|
||||
* 6. ASSIGNMENT
|
||||
* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void.
|
||||
*
|
||||
* 7. MISCELLANEOUS
|
||||
* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries.
|
||||
* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes.
|
||||
* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4.
|
||||
* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt.
|
||||
* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter.
|
||||
* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement.
|
||||
* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.gatk.walkers.indels;
|
||||
|
||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||
import org.broadinstitute.sting.utils.GenomeLocParser;
|
||||
import org.broadinstitute.sting.utils.sam.ArtificialSAMUtils;
|
||||
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
|
||||
import org.broadinstitute.sting.utils.sam.ReadUtils;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* User: carneiro
|
||||
* Date: 2/16/13
|
||||
* Time: 11:48 PM
|
||||
*/
|
||||
public class ReadBinUnitTest {
|
||||
private GenomeLocParser parser;
|
||||
private ReadBin readBin;
|
||||
|
||||
private final int readLength = 100; // all reads will have the same size
|
||||
private final int referencePadding = 10; // standard reference padding
|
||||
|
||||
@BeforeClass
|
||||
public void init() {
|
||||
parser = new GenomeLocParser(ArtificialSAMUtils.createArtificialSamHeader().getSequenceDictionary());
|
||||
readBin = new ReadBin(parser, referencePadding);
|
||||
}
|
||||
|
||||
@DataProvider(name = "reads")
|
||||
public Object[][] reads() {
|
||||
|
||||
return new Object[][]{
|
||||
{"20S80M", 80},
|
||||
{"80M20S", 1},
|
||||
{"20S60M20S", 50},
|
||||
{"100M", 500}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the GenomeLoc variable in the ReadBin after adding arbitrary reads
|
||||
*
|
||||
* @param cigarString the read's cigar string
|
||||
* @param alignmentStart the read's alignment start
|
||||
*/
|
||||
@Test(enabled = true, dataProvider = "reads")
|
||||
public void testAddingReads(String cigarString, int alignmentStart) {
|
||||
final GATKSAMRecord read = createReadAndAddToBin(cigarString, alignmentStart);
|
||||
final GenomeLoc readLoc = parser.createGenomeLoc(read.getReferenceName(), read.getReferenceIndex(), read.getSoftStart(), read.getSoftEnd());
|
||||
Assert.assertEquals(readBin.getLocation(), readLoc);
|
||||
readBin.clear();
|
||||
}
|
||||
|
||||
public GATKSAMRecord createReadAndAddToBin(String cigarString, int alignmentStart) {
|
||||
final GATKSAMRecord read = ReadUtils.createRandomRead(readLength);
|
||||
read.setCigarString(cigarString);
|
||||
read.setAlignmentStart(alignmentStart);
|
||||
readBin.add(read);
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
package org.broadinstitute.sting.utils.classloader;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.broadinstitute.sting.gatk.WalkerManager;
|
||||
import org.broadinstitute.sting.gatk.filters.FilterManager;
|
||||
import org.broadinstitute.sting.utils.exceptions.DynamicClassResolutionException;
|
||||
|
|
@ -299,11 +301,14 @@ public class PluginManager<PluginType> {
|
|||
* @return The plugin object if created; null otherwise.
|
||||
*/
|
||||
public PluginType createByType(Class<? extends PluginType> pluginType) {
|
||||
Logger logger = Logger.getLogger(PluginManager.class);
|
||||
logger.setLevel(Level.ERROR);
|
||||
try {
|
||||
Constructor<? extends PluginType> noArgsConstructor = pluginType.getDeclaredConstructor((Class[])null);
|
||||
noArgsConstructor.setAccessible(true);
|
||||
return noArgsConstructor.newInstance();
|
||||
} catch (Exception e) {
|
||||
logger.error("Couldn't initialize the plugin. Typically this is because of wrong global class variable initializations.");
|
||||
throw new DynamicClassResolutionException(pluginType, e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,11 +54,11 @@ public final class AlignmentUtils {
|
|||
public long mismatchQualities = 0;
|
||||
}
|
||||
|
||||
public static long mismatchingQualities(SAMRecord r, byte[] refSeq, int refIndex) {
|
||||
public static long mismatchingQualities(GATKSAMRecord r, byte[] refSeq, int refIndex) {
|
||||
return getMismatchCount(r, refSeq, refIndex).mismatchQualities;
|
||||
}
|
||||
|
||||
public static MismatchCount getMismatchCount(SAMRecord r, byte[] refSeq, int refIndex) {
|
||||
public static MismatchCount getMismatchCount(GATKSAMRecord r, byte[] refSeq, int refIndex) {
|
||||
return getMismatchCount(r, refSeq, refIndex, 0, r.getReadLength());
|
||||
}
|
||||
|
||||
|
|
@ -70,38 +70,39 @@ public final class AlignmentUtils {
|
|||
*
|
||||
* @param r the sam record to check against
|
||||
* @param refSeq the byte array representing the reference sequence
|
||||
* @param refIndex the index in the reference byte array of the read's first base
|
||||
* @param refIndex the index in the reference byte array of the read's first base (the reference index is matching the alignment start, there may be tons of soft-clipped bases before/after that so it's wrong to compare with getReadLength() here.)
|
||||
* @param startOnRead the index in the read's bases from which we start counting
|
||||
* @param nReadBases the number of bases after (but including) startOnRead that we check
|
||||
* @return non-null object representing the mismatch count
|
||||
*/
|
||||
@Ensures("result != null")
|
||||
public static MismatchCount getMismatchCount(SAMRecord r, byte[] refSeq, int refIndex, int startOnRead, int nReadBases) {
|
||||
public static MismatchCount getMismatchCount(GATKSAMRecord r, byte[] refSeq, int refIndex, int startOnRead, int nReadBases) {
|
||||
if ( r == null ) throw new IllegalArgumentException("attempting to calculate the mismatch count from a read that is null");
|
||||
if ( refSeq == null ) throw new IllegalArgumentException("attempting to calculate the mismatch count with a reference sequence that is null");
|
||||
if ( refIndex < 0 ) throw new IllegalArgumentException("attempting to calculate the mismatch count with a reference index that is negative");
|
||||
if ( startOnRead < 0 ) throw new IllegalArgumentException("attempting to calculate the mismatch count with a read start that is negative");
|
||||
if ( nReadBases < 0 ) throw new IllegalArgumentException("attempting to calculate the mismatch count for a negative number of read bases");
|
||||
if ( refSeq.length - refIndex < r.getReadLength() )
|
||||
if ( refSeq.length - refIndex < (r.getAlignmentEnd() - r.getAlignmentStart()) )
|
||||
throw new IllegalArgumentException("attempting to calculate the mismatch count against a reference string that is smaller than the read");
|
||||
|
||||
MismatchCount mc = new MismatchCount();
|
||||
|
||||
int readIdx = 0;
|
||||
int endOnRead = startOnRead + nReadBases - 1; // index of the last base on read we want to count
|
||||
byte[] readSeq = r.getReadBases();
|
||||
Cigar c = r.getCigar();
|
||||
for (int i = 0; i < c.numCigarElements(); i++) {
|
||||
final int endOnRead = startOnRead + nReadBases - 1; // index of the last base on read we want to count (note we are including soft-clipped bases with this math)
|
||||
final byte[] readSeq = r.getReadBases();
|
||||
final Cigar c = r.getCigar();
|
||||
final byte[] readQuals = r.getBaseQualities();
|
||||
for (final CigarElement ce : c.getCigarElements()) {
|
||||
|
||||
if (readIdx > endOnRead) break;
|
||||
if (readIdx > endOnRead)
|
||||
break;
|
||||
|
||||
CigarElement ce = c.getCigarElement(i);
|
||||
final int elementLength = ce.getLength();
|
||||
switch (ce.getOperator()) {
|
||||
case X:
|
||||
mc.numMismatches += elementLength;
|
||||
for (int j = 0; j < elementLength; j++)
|
||||
mc.mismatchQualities += r.getBaseQualities()[readIdx+j];
|
||||
mc.mismatchQualities += readQuals[readIdx+j];
|
||||
case EQ:
|
||||
refIndex += elementLength;
|
||||
readIdx += elementLength;
|
||||
|
|
@ -109,7 +110,7 @@ public final class AlignmentUtils {
|
|||
case M:
|
||||
for (int j = 0; j < elementLength; j++, refIndex++, readIdx++) {
|
||||
if (refIndex >= refSeq.length)
|
||||
continue;
|
||||
continue; // TODO : It should never happen, we should throw exception here
|
||||
if (readIdx < startOnRead) continue;
|
||||
if (readIdx > endOnRead) break;
|
||||
byte refChr = refSeq[refIndex];
|
||||
|
|
@ -120,7 +121,7 @@ public final class AlignmentUtils {
|
|||
// continue; // do not count Ns/Xs/etc ?
|
||||
if (readChr != refChr) {
|
||||
mc.numMismatches++;
|
||||
mc.mismatchQualities += r.getBaseQualities()[readIdx];
|
||||
mc.mismatchQualities += readQuals[readIdx];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -425,14 +426,14 @@ public final class AlignmentUtils {
|
|||
* @return true if read is unmapped
|
||||
*/
|
||||
public static boolean isReadUnmapped(final SAMRecord r) {
|
||||
if ( r == null ) throw new IllegalArgumentException("Read cannot be null");
|
||||
if ( r == null )
|
||||
throw new IllegalArgumentException("Read cannot be null");
|
||||
|
||||
if (r.getReadUnmappedFlag()) return true;
|
||||
return r.getReadUnmappedFlag() ||
|
||||
!((r.getReferenceIndex() != null && r.getReferenceIndex() != SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX ||
|
||||
r.getReferenceName() != null && !r.getReferenceName().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME)) &&
|
||||
r.getAlignmentStart() != SAMRecord.NO_ALIGNMENT_START);
|
||||
|
||||
if ((r.getReferenceIndex() != null && r.getReferenceIndex() != SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX
|
||||
|| r.getReferenceName() != null && !r.getReferenceName().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME))
|
||||
&& r.getAlignmentStart() != SAMRecord.NO_ALIGNMENT_START) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ public class ArtificialSAMUtils {
|
|||
/**
|
||||
* Creates an artificial sam header based on the sequence dictionary dict
|
||||
*
|
||||
* @return
|
||||
* @return a new sam header
|
||||
*/
|
||||
public static SAMFileHeader createArtificialSamHeader(final SAMSequenceDictionary dict) {
|
||||
SAMFileHeader header = new SAMFileHeader();
|
||||
|
|
@ -127,6 +127,14 @@ public class ArtificialSAMUtils {
|
|||
return header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an artificial sam header with standard test parameters
|
||||
*
|
||||
* @return the sam header
|
||||
*/
|
||||
public static SAMFileHeader createArtificialSamHeader() {
|
||||
return createArtificialSamHeader(1, 1, 1000000);
|
||||
}
|
||||
|
||||
/**
|
||||
* setup a default read group for a SAMFileHeader
|
||||
|
|
@ -270,7 +278,7 @@ public class ArtificialSAMUtils {
|
|||
* @return the artificial read
|
||||
*/
|
||||
public static GATKSAMRecord createArtificialRead(byte[] bases, byte[] qual, String cigar) {
|
||||
SAMFileHeader header = ArtificialSAMUtils.createArtificialSamHeader(1, 1, 1000000);
|
||||
SAMFileHeader header = ArtificialSAMUtils.createArtificialSamHeader();
|
||||
return ArtificialSAMUtils.createArtificialRead(header, "default_read", 0, 10000, bases, qual, cigar);
|
||||
}
|
||||
|
||||
|
|
@ -280,7 +288,7 @@ public class ArtificialSAMUtils {
|
|||
byte [] qual = {30};
|
||||
byte [] bases = Utils.arrayFromArrayWithLength(base, length);
|
||||
byte [] quals = Utils.arrayFromArrayWithLength(qual, length);
|
||||
SAMFileHeader header = ArtificialSAMUtils.createArtificialSamHeader(1, 1, 1000000);
|
||||
SAMFileHeader header = ArtificialSAMUtils.createArtificialSamHeader();
|
||||
return ArtificialSAMUtils.createArtificialRead(header, "default_read", 0, 10000, bases, quals, cigar.toString());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -380,6 +380,14 @@ public class AlignmentUtilsUnitTest {
|
|||
}
|
||||
}
|
||||
|
||||
// Adding test to make sure soft-clipped reads go through the exceptions thrown at the beginning of the getMismatchCount method
|
||||
// todo: incorporate cigars with right-tail soft-clips in the systematic tests above.
|
||||
GATKSAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "myRead", 0, 10, 20);
|
||||
read.setReadBases(reference);
|
||||
read.setBaseQualities(quals);
|
||||
read.setCigarString("10S5M5S");
|
||||
tests.add(new Object[]{read, 10, read.getAlignmentStart(), read.getReadLength(), false});
|
||||
|
||||
return tests.toArray(new Object[][]{});
|
||||
}
|
||||
|
||||
|
|
@ -393,26 +401,28 @@ public class AlignmentUtilsUnitTest {
|
|||
private static String buildTestCigarString(final char middleOp, final int lengthOfSoftClip, final int lengthOfFirstM, final int lengthOfIndel, final int readLength) {
|
||||
final StringBuilder cigar = new StringBuilder();
|
||||
int remainingLength = readLength;
|
||||
if ( lengthOfSoftClip > 0 ) {
|
||||
cigar.append(lengthOfSoftClip + "S");
|
||||
|
||||
// add soft clips to the beginning of the read
|
||||
if (lengthOfSoftClip > 0 ) {
|
||||
cigar.append(lengthOfSoftClip).append("S");
|
||||
remainingLength -= lengthOfSoftClip;
|
||||
}
|
||||
|
||||
if ( middleOp == 'M' ) {
|
||||
cigar.append(remainingLength + "M");
|
||||
cigar.append(remainingLength).append("M");
|
||||
} else {
|
||||
if ( lengthOfFirstM > 0 ) {
|
||||
cigar.append(lengthOfFirstM + "M");
|
||||
cigar.append(lengthOfFirstM).append("M");
|
||||
remainingLength -= lengthOfFirstM;
|
||||
}
|
||||
|
||||
if ( middleOp == 'D' ) {
|
||||
cigar.append(lengthOfIndel + "D");
|
||||
cigar.append(lengthOfIndel).append("D");
|
||||
} else {
|
||||
cigar.append(lengthOfIndel + "I");
|
||||
cigar.append(lengthOfIndel).append("I");
|
||||
remainingLength -= lengthOfIndel;
|
||||
}
|
||||
cigar.append(remainingLength + "M");
|
||||
cigar.append(remainingLength).append("M");
|
||||
}
|
||||
|
||||
return cigar.toString();
|
||||
|
|
|
|||
Loading…
Reference in New Issue