2009-08-05 05:01:37 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2009 The Broad Institute
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
|
* conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.broadinstitute.sting.gatk.contexts;
|
2009-02-27 05:50:29 +08:00
|
|
|
|
2009-07-01 03:17:24 +08:00
|
|
|
import net.sf.picard.reference.ReferenceSequence;
|
2009-03-11 03:34:00 +08:00
|
|
|
import net.sf.samtools.SAMRecord;
|
2009-03-13 07:30:19 +08:00
|
|
|
import org.broadinstitute.sting.utils.GenomeLoc;
|
2009-11-26 04:54:44 +08:00
|
|
|
import org.broadinstitute.sting.utils.StingException;
|
|
|
|
|
import org.broadinstitute.sting.utils.pileup.ReadBackedPileup;
|
2009-07-01 03:17:24 +08:00
|
|
|
|
|
|
|
|
import java.util.*;
|
2009-03-13 07:30:19 +08:00
|
|
|
|
2009-02-27 05:50:29 +08:00
|
|
|
/**
|
2009-03-16 22:46:19 +08:00
|
|
|
* Useful class for forwarding on locusContext data from this iterator
|
|
|
|
|
*
|
2009-02-27 05:50:29 +08:00
|
|
|
* Created by IntelliJ IDEA.
|
|
|
|
|
* User: mdepristo
|
|
|
|
|
* Date: Feb 22, 2009
|
|
|
|
|
* Time: 3:01:34 PM
|
|
|
|
|
* To change this template use File | Settings | File Templates.
|
|
|
|
|
*/
|
2009-08-05 05:01:37 +08:00
|
|
|
public class AlignmentContext {
|
2009-09-09 23:49:52 +08:00
|
|
|
protected GenomeLoc loc = null;
|
2009-11-26 04:54:44 +08:00
|
|
|
protected ReadBackedPileup pileup = null;
|
2009-09-09 23:49:52 +08:00
|
|
|
|
2009-09-13 03:11:38 +08:00
|
|
|
/**
|
|
|
|
|
* The number of bases we've skipped over in the reference since the last map invocation.
|
|
|
|
|
* Only filled in by RodTraversals right now. By default, nothing is being skipped, so skippedBases == 0.
|
|
|
|
|
*/
|
|
|
|
|
private long skippedBases = 0;
|
|
|
|
|
|
2009-09-09 23:49:52 +08:00
|
|
|
/**
|
|
|
|
|
* Default constructor for AlignmentContext object
|
|
|
|
|
* since private objects are already set to null we
|
|
|
|
|
* don't need to do anything
|
|
|
|
|
*/
|
|
|
|
|
public AlignmentContext() { /* private objects already set to null */ }
|
2009-02-27 05:50:29 +08:00
|
|
|
|
2009-03-16 22:46:19 +08:00
|
|
|
/**
|
2009-08-05 05:01:37 +08:00
|
|
|
* Create a new AlignmentContext object
|
2009-03-16 22:46:19 +08:00
|
|
|
*
|
|
|
|
|
* @param loc
|
|
|
|
|
* @param reads
|
|
|
|
|
* @param offsets
|
|
|
|
|
*/
|
2009-11-26 04:54:44 +08:00
|
|
|
@Deprecated
|
2009-08-05 05:01:37 +08:00
|
|
|
public AlignmentContext(GenomeLoc loc, List<SAMRecord> reads, List<Integer> offsets) {
|
2009-11-26 04:54:44 +08:00
|
|
|
this(loc, reads, offsets, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
public AlignmentContext(GenomeLoc loc, List<SAMRecord> reads, List<Integer> offsets, long skippedBases ) {
|
|
|
|
|
if ( loc == null ) throw new StingException("BUG: GenomeLoc in Alignment context is null");
|
|
|
|
|
if ( skippedBases < 0 ) throw new StingException("BUG: skippedBases is -1 in Alignment context");
|
2009-04-14 08:55:19 +08:00
|
|
|
|
2009-03-16 22:46:19 +08:00
|
|
|
this.loc = loc;
|
2009-11-26 04:54:44 +08:00
|
|
|
this.pileup = new ReadBackedPileup(loc, reads, offsets);
|
|
|
|
|
this.skippedBases = skippedBases;
|
2009-03-16 22:46:19 +08:00
|
|
|
}
|
2009-02-27 05:50:29 +08:00
|
|
|
|
2009-11-26 04:54:44 +08:00
|
|
|
public AlignmentContext(GenomeLoc loc, ReadBackedPileup pileup ) {
|
|
|
|
|
this(loc, pileup, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AlignmentContext(GenomeLoc loc, ReadBackedPileup pileup, long skippedBases ) {
|
|
|
|
|
if ( loc == null ) throw new StingException("BUG: GenomeLoc in Alignment context is null");
|
|
|
|
|
if ( pileup == null ) throw new StingException("BUG: ReadBackedPileup in Alignment context is null");
|
|
|
|
|
if ( skippedBases < 0 ) throw new StingException("BUG: skippedBases is -1 in Alignment context");
|
|
|
|
|
|
2009-09-13 03:11:38 +08:00
|
|
|
this.loc = loc;
|
2009-11-26 04:54:44 +08:00
|
|
|
this.pileup = pileup;
|
2009-09-13 03:11:38 +08:00
|
|
|
this.skippedBases = skippedBases;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-26 04:54:44 +08:00
|
|
|
public ReadBackedPileup getPileup() { return pileup; }
|
2009-09-13 03:11:38 +08:00
|
|
|
|
2009-03-16 22:46:19 +08:00
|
|
|
/**
|
|
|
|
|
* get all of the reads within this context
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2009-11-26 04:54:44 +08:00
|
|
|
@Deprecated
|
|
|
|
|
public List<SAMRecord> getReads() { return pileup.getReads(); }
|
2009-02-27 05:50:29 +08:00
|
|
|
|
2009-03-16 22:46:19 +08:00
|
|
|
/**
|
|
|
|
|
* Are there any reads associated with this locus?
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public boolean hasReads() {
|
2009-11-26 04:54:44 +08:00
|
|
|
return pileup.size() > 0;
|
2009-03-16 22:46:19 +08:00
|
|
|
}
|
2009-02-27 05:50:29 +08:00
|
|
|
|
2009-03-16 22:46:19 +08:00
|
|
|
/**
|
|
|
|
|
* How many reads cover this locus?
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2009-11-26 04:54:44 +08:00
|
|
|
public int size() {
|
|
|
|
|
return pileup.size();
|
2009-03-16 22:46:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get a list of the equivalent positions within in the reads at Pos
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2009-11-26 04:54:44 +08:00
|
|
|
@Deprecated
|
2009-03-16 22:46:19 +08:00
|
|
|
public List<Integer> getOffsets() {
|
2009-11-26 04:54:44 +08:00
|
|
|
return pileup.getOffsets();
|
2009-03-16 22:46:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getContig() { return getLocation().getContig(); }
|
|
|
|
|
public long getPosition() { return getLocation().getStart(); }
|
|
|
|
|
public GenomeLoc getLocation() { return loc; }
|
2009-09-09 09:28:05 +08:00
|
|
|
|
2009-04-02 04:27:06 +08:00
|
|
|
public void downsampleToCoverage(int coverage) {
|
2009-11-26 04:54:44 +08:00
|
|
|
pileup = pileup.getDownsampledPileup(coverage);
|
2009-09-09 23:36:12 +08:00
|
|
|
}
|
2009-09-13 03:11:38 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the number of bases we've skipped over in the reference since the last map invocation.
|
|
|
|
|
* Only filled in by RodTraversals right now. A value of 0 indicates that no bases were skipped.
|
|
|
|
|
*
|
|
|
|
|
* @return the number of skipped bases
|
|
|
|
|
*/
|
|
|
|
|
public long getSkippedBases() {
|
|
|
|
|
return skippedBases;
|
|
|
|
|
}
|
2009-02-27 05:50:29 +08:00
|
|
|
}
|