VariantFiltrationWalker now inspects its parent package and determines the list of features that can be applied. Command-line specification of filters to run look at the simple names of these features and do a case-insensitive match to determine which features to apply. A new verbose mode allows the user to see how the likelihoods are changing with the application of each subsequent feature.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1054 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
0a0ef573f7
commit
284fd6a5fb
|
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||||
public class IVFBinomialStrand implements IndependentVariantFeature {
|
public class IVFBinomialStrand implements IndependentVariantFeature {
|
||||||
private double strandBalance = 0.5;
|
private double strandBalance = 0.5;
|
||||||
|
|
||||||
public IVFBinomialStrand(String arguments) {
|
public void initialize(String arguments) {
|
||||||
if (arguments != null && !arguments.isEmpty()) {
|
if (arguments != null && !arguments.isEmpty()) {
|
||||||
strandBalance = Double.valueOf(arguments);
|
strandBalance = Double.valueOf(arguments);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ package org.broadinstitute.sting.playground.gatk.walkers.variants;
|
||||||
import org.broadinstitute.sting.gatk.LocusContext;
|
import org.broadinstitute.sting.gatk.LocusContext;
|
||||||
|
|
||||||
public class IVFNull implements IndependentVariantFeature {
|
public class IVFNull implements IndependentVariantFeature {
|
||||||
public String getFeatureName() { return "null"; }
|
public void initialize(String arguments) {}
|
||||||
|
|
||||||
public double[] compute(char ref, LocusContext context) {
|
public double[] compute(char ref, LocusContext context) {
|
||||||
return new double[0];
|
return new double[10];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import org.broadinstitute.sting.gatk.LocusContext;
|
||||||
public interface IndependentVariantFeature {
|
public interface IndependentVariantFeature {
|
||||||
public enum Genotype { AA, AC, AG, AT, CC, CG, CT, GG, GT, TT }
|
public enum Genotype { AA, AC, AG, AT, CC, CG, CT, GG, GT, TT }
|
||||||
|
|
||||||
public String getFeatureName();
|
public void initialize(String arguments);
|
||||||
|
|
||||||
public double[] compute(char ref, LocusContext context);
|
public double[] compute(char ref, LocusContext context);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,24 +10,31 @@ import org.broadinstitute.sting.gatk.refdata.rodVariants;
|
||||||
import org.broadinstitute.sting.gatk.LocusContext;
|
import org.broadinstitute.sting.gatk.LocusContext;
|
||||||
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
||||||
import org.broadinstitute.sting.utils.StingException;
|
import org.broadinstitute.sting.utils.StingException;
|
||||||
|
import org.broadinstitute.sting.utils.PackageUtils;
|
||||||
|
import org.broadinstitute.sting.utils.JVMUtils;
|
||||||
import org.broadinstitute.sting.playground.utils.AlleleFrequencyEstimate;
|
import org.broadinstitute.sting.playground.utils.AlleleFrequencyEstimate;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Requires(value={DataSource.READS, DataSource.REFERENCE},referenceMetaData=@RMD(name="variant",type=rodVariants.class))
|
@Requires(value={DataSource.READS, DataSource.REFERENCE},referenceMetaData=@RMD(name="variant",type=rodVariants.class))
|
||||||
public class VariantFiltrationWalker extends LocusWalker<Integer, Integer> {
|
public class VariantFiltrationWalker extends LocusWalker<Integer, Integer> {
|
||||||
@Argument(fullName="features", shortName="F", doc="Feature test (optionally with arguments) to apply to genotype posteriors. Syntax: 'testname:arg1,arg2,...,argN'") public String[] FEATURES;
|
@Argument(fullName="features", shortName="F", doc="Feature test (optionally with arguments) to apply to genotype posteriors. Syntax: 'testname:arguments'") public String[] FEATURES;
|
||||||
@Argument(fullName="variants_out", shortName="VO", doc="File to which modified variants should be written") public File VARIANTS_OUT;
|
@Argument(fullName="variants_out", shortName="VO", doc="File to which modified variants should be written") public File VARIANTS_OUT;
|
||||||
|
@Argument(fullName="verbose", shortName="V", doc="Show how the variant likelihoods are changing with the application of each feature") public Boolean VERBOSE = false;
|
||||||
|
|
||||||
private PrintWriter vwriter;
|
private PrintWriter vwriter;
|
||||||
|
private ArrayList<Class> featureClasses;
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
try {
|
try {
|
||||||
vwriter = new PrintWriter(VARIANTS_OUT);
|
vwriter = new PrintWriter(VARIANTS_OUT);
|
||||||
|
|
||||||
vwriter.println(AlleleFrequencyEstimate.geliHeaderString());
|
vwriter.println(AlleleFrequencyEstimate.geliHeaderString());
|
||||||
|
|
||||||
|
featureClasses = PackageUtils.getClassesImplementingInterface(IndependentVariantFeature.class);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new StingException(String.format("Could not open file '%s' for writing", VARIANTS_OUT.getAbsolutePath()));
|
throw new StingException(String.format("Could not open file '%s' for writing", VARIANTS_OUT.getAbsolutePath()));
|
||||||
}
|
}
|
||||||
|
|
@ -45,10 +52,35 @@ public class VariantFiltrationWalker extends LocusWalker<Integer, Integer> {
|
||||||
|
|
||||||
IndependentVariantFeature ivf;
|
IndependentVariantFeature ivf;
|
||||||
|
|
||||||
if (featureName.equalsIgnoreCase("binomialstrand")) { ivf = new IVFBinomialStrand(featureArgs); }
|
if (VERBOSE) {
|
||||||
else { throw new StingException(String.format("Cannot understand feature '%s'", featureName)); }
|
out.println("Original:");
|
||||||
|
out.println(" " + variant);
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( Class featureClass : featureClasses ) {
|
||||||
|
String featureClassName = featureClass.getSimpleName();
|
||||||
|
featureClassName = featureClassName.replaceFirst("IVF", "");
|
||||||
|
|
||||||
|
if (featureName.equalsIgnoreCase(featureClassName)) {
|
||||||
|
try {
|
||||||
|
ivf = (IndependentVariantFeature) featureClass.newInstance();
|
||||||
|
ivf.initialize(featureArgs);
|
||||||
|
|
||||||
variant.adjustLikelihoods(ivf.compute(ref, context));
|
variant.adjustLikelihoods(ivf.compute(ref, context));
|
||||||
|
|
||||||
|
if (VERBOSE) {
|
||||||
|
out.println(featureClassName + ":");
|
||||||
|
out.println(" " + variant);
|
||||||
|
}
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
throw new StingException(String.format("Cannot instantiate feature class '%s': must be concrete class", featureClass.getSimpleName()));
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new StingException(String.format("Cannot instantiate feature class '%s': must have no-arg constructor", featureClass.getSimpleName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VERBOSE) { System.out.println(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
vwriter.println(variant);
|
vwriter.println(variant);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue