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-03-11 03:34:00 +08:00
import net.sf.samtools.SAMRecord ;
2010-09-12 23:07:38 +08:00
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException ;
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.pileup.ReadBackedPileup ;
2009-12-30 04:07:29 +08:00
import org.broadinstitute.sting.utils.pileup.ReadBackedExtendedEventPileup ;
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-12-30 04:07:29 +08:00
protected ReadBackedPileup basePileup = null ;
2010-08-28 00:12:05 +08:00
protected boolean hasPileupBeenDownsampled ;
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 ;
2010-08-28 00:12:05 +08:00
public AlignmentContext ( GenomeLoc loc , ReadBackedPileup basePileup ) {
this ( loc , basePileup , 0 , false ) ;
2009-11-26 04:54:44 +08:00
}
2010-08-28 00:12:05 +08:00
public AlignmentContext ( GenomeLoc loc , ReadBackedPileup basePileup , boolean hasPileupBeenDownsampled ) {
this ( loc , basePileup , 0 , hasPileupBeenDownsampled ) ;
2009-03-16 22:46:19 +08:00
}
2009-02-27 05:50:29 +08:00
2010-08-28 00:12:05 +08:00
public AlignmentContext ( GenomeLoc loc , ReadBackedPileup basePileup , long skippedBases ) {
this ( loc , basePileup , skippedBases , false ) ;
2009-11-26 04:54:44 +08:00
}
2010-08-28 00:12:05 +08:00
public AlignmentContext ( GenomeLoc loc , ReadBackedPileup basePileup , long skippedBases , boolean hasPileupBeenDownsampled ) {
2010-09-12 23:07:38 +08:00
if ( loc = = null ) throw new ReviewedStingException ( "BUG: GenomeLoc in Alignment context is null" ) ;
if ( basePileup = = null ) throw new ReviewedStingException ( "BUG: ReadBackedPileup in Alignment context is null" ) ;
if ( skippedBases < 0 ) throw new ReviewedStingException ( "BUG: skippedBases is -1 in Alignment context" ) ;
2009-11-26 04:54:44 +08:00
2009-09-13 03:11:38 +08:00
this . loc = loc ;
2009-12-30 04:07:29 +08:00
this . basePileup = basePileup ;
2009-09-13 03:11:38 +08:00
this . skippedBases = skippedBases ;
2010-08-28 00:12:05 +08:00
this . hasPileupBeenDownsampled = hasPileupBeenDownsampled ;
2009-09-13 03:11:38 +08:00
}
2009-12-30 04:07:29 +08:00
/ * * Returns base pileup over the current genomic location . Deprectated . Use getBasePileup ( ) to make your intentions
* clear .
* @return
* /
@Deprecated
public ReadBackedPileup getPileup ( ) { return basePileup ; }
/ * * Returns base pileup over the current genomic location . May return null if this context keeps only
* extended event ( indel ) pileup .
* @return
* /
2010-07-18 06:22:44 +08:00
public ReadBackedPileup getBasePileup ( ) {
if ( ! hasBasePileup ( ) )
2010-09-12 23:07:38 +08:00
throw new ReviewedStingException ( "No base pileup is available. Please check for a base pileup with hasBasePileup() before attempting to retrieve a pileup." ) ;
2010-07-18 06:22:44 +08:00
return basePileup ;
}
2009-12-30 04:07:29 +08:00
/ * * Returns extended event ( indel ) pileup over the current genomic location . May return null if this context keeps
* only base pileup .
* @return
* /
2010-07-17 02:57:58 +08:00
public ReadBackedExtendedEventPileup getExtendedEventPileup ( ) {
if ( ! hasExtendedEventPileup ( ) )
2010-09-12 23:07:38 +08:00
throw new ReviewedStingException ( "No extended event pileup is present." ) ;
2010-07-17 02:57:58 +08:00
return ( ReadBackedExtendedEventPileup ) basePileup ;
}
2009-12-30 04:07:29 +08:00
2010-07-17 02:57:58 +08:00
/ * *
* Returns true if this alignment context keeps base pileup over the current genomic location .
* TODO : Syntax of AlignmentContext uses hasBasePileup ( ) / hasExtendedEventPileup ( ) as an enumeration mechanism . Change this to a more sensible interface .
2009-12-30 04:07:29 +08:00
* @return
* /
2010-07-17 02:57:58 +08:00
public boolean hasBasePileup ( ) { return ! ( basePileup instanceof ReadBackedExtendedEventPileup ) ; }
2009-12-30 04:07:29 +08:00
/ * * Returns true if this alignment context keeps extended event ( indel ) pileup over the current genomic location .
*
* @return
* /
2010-07-17 02:57:58 +08:00
public boolean hasExtendedEventPileup ( ) { return basePileup instanceof ReadBackedExtendedEventPileup ; }
2009-09-13 03:11:38 +08:00
2010-08-28 00:12:05 +08:00
/ * *
* Returns true if any reads have been filtered out of the pileup due to excess DoC .
* @return True if reads have been filtered out . False otherwise .
* /
public boolean hasPileupBeenDownsampled ( ) { return hasPileupBeenDownsampled ; }
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
2009-12-30 04:07:29 +08:00
//todo: unsafe and tailored for current usage only; both pileups can be null or worse, bot can be not null in theory
2010-07-17 02:57:58 +08:00
public List < SAMRecord > getReads ( ) { return ( basePileup . 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 ( ) {
2010-07-17 02:57:58 +08:00
return basePileup ! = null & & basePileup . 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 ( ) {
2010-07-17 02:57:58 +08:00
return basePileup . 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 ( ) {
2010-07-17 02:57:58 +08:00
return basePileup . 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 ) {
2010-07-17 02:57:58 +08:00
basePileup = basePileup . getDownsampledPileup ( coverage ) ;
2010-08-28 00:12:05 +08:00
hasPileupBeenDownsampled = true ;
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
}