2010-04-20 07:00:08 +08:00
/ *
* Copyright ( c ) 2010 The Broad Institute
* Permission is hereby granted , free of charge , to any person
* obtaining a copy of this software and associated documentation
* files ( the <EFBFBD> Software <EFBFBD> ) , 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 <EFBFBD> AS IS <EFBFBD> , 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 .
* /
2010-02-05 22:18:26 +08:00
package org.broadinstitute.sting.oneoffprojects.walkers ;
2010-01-28 01:19:37 +08:00
import org.broadinstitute.sting.gatk.contexts.AlignmentContext ;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext ;
2010-02-05 23:42:54 +08:00
import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContext ;
2010-01-28 12:10:16 +08:00
import org.broadinstitute.sting.gatk.refdata.* ;
2010-01-28 01:19:37 +08:00
import org.broadinstitute.sting.gatk.walkers.RodWalker ;
2010-02-10 03:02:25 +08:00
import org.broadinstitute.sting.utils.genotype.vcf.* ;
2010-04-20 07:00:08 +08:00
import org.broadinstitute.sting.commandline.Argument ;
2010-02-05 23:42:54 +08:00
import java.util.EnumSet ;
2010-02-10 03:02:25 +08:00
import java.io.File ;
2010-01-28 01:19:37 +08:00
/ * *
* Test routine for new VariantContext object
* /
public class TestVariantContextWalker extends RodWalker < Integer , Integer > {
2010-02-05 23:42:54 +08:00
@Argument ( fullName = "takeFirstOnly" , doc = "Only take the first second at a locus, as opposed to all" , required = false )
boolean takeFirstOnly = false ;
@Argument ( fullName = "onlyContextsOfType" , doc = "Only take variant contexts of this type" , required = false )
VariantContext . Type onlyOfThisType = null ;
@Argument ( fullName = "onlyContextsStartinAtCurrentPosition" , doc = "Only take variant contexts at actually start at the current position, excluding those at span to the current location but start earlier" , required = false )
boolean onlyContextsStartinAtCurrentPosition = false ;
2010-03-05 01:58:01 +08:00
@Argument ( fullName = "printPerLocus" , doc = "If true, we'll psetenv LD_LIBRARY_PATH .:/util/gcc-4.3.0/lib64:/util/gcc-4.3.0/lib/gcc/x86_64-unknown-linux-gnu/4.3.0:/util/gcc-4.3.0/lib/:/util/lib:/broad/tools/Linux/x86_64/pkgs/boost_1.38.0/lib:/humgen/gsa-scr1/GATK_Data/bwarint the variant contexts, in addition to counts" , required = false )
2010-02-05 23:42:54 +08:00
boolean printContexts = false ;
2010-01-28 01:19:37 +08:00
2010-02-10 03:02:25 +08:00
@Argument ( fullName = "outputVCF" , doc = "If provided, we'll convert the first input context into a VCF" , required = false )
String outputVCF = null ;
private VCFWriter writer = null ;
private boolean wroteHeader = false ;
public void initialize ( ) {
if ( outputVCF ! = null )
writer = new VCFWriter ( new File ( outputVCF ) ) ;
}
2010-01-28 01:19:37 +08:00
public Integer map ( RefMetaDataTracker tracker , ReferenceContext ref , AlignmentContext context ) {
if ( ref = = null )
return 0 ;
else {
2010-02-05 23:42:54 +08:00
EnumSet < VariantContext . Type > allowedTypes = onlyOfThisType = = null ? null : EnumSet . of ( onlyOfThisType ) ;
2010-01-28 12:10:16 +08:00
2010-02-05 23:42:54 +08:00
int n = 0 ;
2010-04-19 13:47:17 +08:00
for ( VariantContext vc : tracker . getAllVariantContexts ( ref , allowedTypes , context . getLocation ( ) , onlyContextsStartinAtCurrentPosition , takeFirstOnly ) ) {
2010-02-10 03:02:25 +08:00
if ( writer ! = null & & n = = 0 ) {
if ( ! wroteHeader ) {
writer . writeHeader ( VariantContextAdaptors . createVCFHeader ( null , vc ) ) ;
wroteHeader = true ;
}
2010-03-05 01:58:01 +08:00
writer . addRecord ( VariantContextAdaptors . toVCF ( vc , ref . getBase ( ) ) ) ;
2010-02-10 03:02:25 +08:00
}
2010-02-05 23:42:54 +08:00
n + + ;
if ( printContexts ) out . printf ( " %s%n" , vc ) ;
}
if ( n > 0 & & printContexts ) {
out . printf ( "%s => had %d variant context objects%n" , context . getLocation ( ) , n ) ;
out . printf ( "---------------------------------------------%n" ) ;
}
return n ;
2010-01-28 01:19:37 +08:00
}
}
public Integer reduceInit ( ) {
return 0 ;
}
public Integer reduce ( Integer point , Integer sum ) {
return point + sum ;
}
}