Cleanup Genotypes
-- Renamed getAttribute to getExtendedAttribute, as this is really what this function does -- Added a few more genotype tests
This commit is contained in:
parent
aa2178cc68
commit
856905ee5b
|
|
@ -617,7 +617,7 @@ public class SomaticIndelDetectorWalker extends ReadWalker<Integer,Integer> {
|
|||
throw new StingException("Read "+read.getReadName()+" from "+getToolkit().getSourceFileForReaderID(getToolkit().getReaderIDForRead(read))+
|
||||
"has no Normal/Tumor tag associated with it");
|
||||
|
||||
// String rg = (String)read.getAttribute("RG");
|
||||
// String rg = (String)read.getExtendedAttribute("RG");
|
||||
// if ( rg == null )
|
||||
// throw new UserException.MalformedBam(read, "Read "+read.getReadName()+" has no read group in merged stream. RG is required for somatic calls.");
|
||||
|
||||
|
|
|
|||
|
|
@ -807,7 +807,7 @@ public class PhaseByTransmission extends RodWalker<HashMap<Byte,Integer>, HashMa
|
|||
updateTrioMetricsCounters(phasedMother,phasedFather,phasedChild,mvCount,metricsCounters);
|
||||
mvfLine = String.format("%s\t%d\t%s\t%s\t%s\t%s\t%s:%s:%s:%s\t%s:%s:%s:%s\t%s:%s:%s:%s",
|
||||
vc.getChr(),vc.getStart(),vc.getFilters(),vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY),sample.toString(),
|
||||
phasedMother.getAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedMother.getGenotypeString(),phasedMother.getDP(),Arrays.asList(phasedMother.getAD()),
|
||||
phasedMother.getExtendedAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedMother.getGenotypeString(),phasedMother.getDP(),Arrays.asList(phasedMother.getAD()),
|
||||
phasedMother.getLikelihoodsString(), phasedFather.getGenotypeString(),phasedFather.getDP(),Arrays.asList(phasedFather.getAD()),phasedFather.getLikelihoodsString(),
|
||||
phasedChild.getGenotypeString(),Arrays.asList(phasedChild.getDP()),phasedChild.getAD(),phasedChild.getLikelihoodsString());
|
||||
if(!(phasedMother.getType()==mother.getType() && phasedFather.getType()==father.getType() && phasedChild.getType()==child.getType()))
|
||||
|
|
@ -819,7 +819,7 @@ public class PhaseByTransmission extends RodWalker<HashMap<Byte,Integer>, HashMa
|
|||
metricsCounters.put(NUM_GENOTYPES_MODIFIED,metricsCounters.get(NUM_GENOTYPES_MODIFIED)+1);
|
||||
mvfLine = String.format("%s\t%d\t%s\t%s\t%s\t%s\t%s:%s:%s:%s\t.:.:.:.\t%s:%s:%s:%s",
|
||||
vc.getChr(),vc.getStart(),vc.getFilters(),vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY),sample.toString(),
|
||||
phasedMother.getAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedMother.getGenotypeString(),phasedMother.getDP(),Arrays.asList(phasedMother.getAD()),phasedMother.getLikelihoodsString(),
|
||||
phasedMother.getExtendedAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedMother.getGenotypeString(),phasedMother.getDP(),Arrays.asList(phasedMother.getAD()),phasedMother.getLikelihoodsString(),
|
||||
phasedChild.getGenotypeString(),phasedChild.getDP(),Arrays.asList(phasedChild.getAD()),phasedChild.getLikelihoodsString());
|
||||
}
|
||||
}
|
||||
|
|
@ -830,7 +830,7 @@ public class PhaseByTransmission extends RodWalker<HashMap<Byte,Integer>, HashMa
|
|||
metricsCounters.put(NUM_GENOTYPES_MODIFIED,metricsCounters.get(NUM_GENOTYPES_MODIFIED)+1);
|
||||
mvfLine = String.format("%s\t%d\t%s\t%s\t%s\t%s\t.:.:.:.\t%s:%s:%s:%s\t%s:%s:%s:%s",
|
||||
vc.getChr(),vc.getStart(),vc.getFilters(),vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY),sample.toString(),
|
||||
phasedFather.getAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedFather.getGenotypeString(),phasedFather.getDP(),Arrays.asList(phasedFather.getAD()),phasedFather.getLikelihoodsString(),
|
||||
phasedFather.getExtendedAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedFather.getGenotypeString(),phasedFather.getDP(),Arrays.asList(phasedFather.getAD()),phasedFather.getLikelihoodsString(),
|
||||
phasedChild.getGenotypeString(),phasedChild.getDP(),Arrays.asList(phasedChild.getAD()),phasedChild.getLikelihoodsString());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ public class GenotypeAndValidateWalker extends RodWalker<GenotypeAndValidateWalk
|
|||
}
|
||||
}
|
||||
else {
|
||||
// if (!vcComp.hasAttribute("GV"))
|
||||
// if (!vcComp.hasExtendedAttribute("GV"))
|
||||
// throw new UserException.BadInput("Variant has no GV annotation in the INFO field. " + vcComp.getChr() + ":" + vcComp.getStart());
|
||||
|
||||
if (call.isCalledAlt(callConf)) {
|
||||
|
|
|
|||
|
|
@ -121,9 +121,9 @@ public class ValidationReport extends VariantEvaluator implements StandardEval {
|
|||
int ac = 0;
|
||||
if ( vc.getNAlleles() > 2 ) {
|
||||
return SiteStatus.POLY;
|
||||
//// System.out.printf("multiple alleles %s = %s%n", vc.getAlleles(), vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY));
|
||||
//// System.out.printf("multiple alleles %s = %s%n", vc.getAlleles(), vc.getExtendedAttribute(VCFConstants.ALLELE_COUNT_KEY));
|
||||
// // todo -- omg this is painful. We need a better approach to dealing with multi-valued attributes
|
||||
// for ( String v : (List<String>)vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY) )
|
||||
// for ( String v : (List<String>)vc.getExtendedAttribute(VCFConstants.ALLELE_COUNT_KEY) )
|
||||
// ac += Integer.valueOf(v);
|
||||
//// System.out.printf(" ac = %d%n", ac);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,9 +225,9 @@ public class SequenceDictionaryUtils {
|
|||
return false;
|
||||
|
||||
// todo -- reenable if we want to be really strict here
|
||||
// if (me.getAttribute(SAMSequenceRecord.MD5_TAG) != null && that.getAttribute(SAMSequenceRecord.MD5_TAG) != null) {
|
||||
// final BigInteger thisMd5 = new BigInteger((String)me.getAttribute(SAMSequenceRecord.MD5_TAG), 16);
|
||||
// final BigInteger thatMd5 = new BigInteger((String)that.getAttribute(SAMSequenceRecord.MD5_TAG), 16);
|
||||
// if (me.getExtendedAttribute(SAMSequenceRecord.MD5_TAG) != null && that.getExtendedAttribute(SAMSequenceRecord.MD5_TAG) != null) {
|
||||
// final BigInteger thisMd5 = new BigInteger((String)me.getExtendedAttribute(SAMSequenceRecord.MD5_TAG), 16);
|
||||
// final BigInteger thatMd5 = new BigInteger((String)that.getExtendedAttribute(SAMSequenceRecord.MD5_TAG), 16);
|
||||
// if (!thisMd5.equals(thatMd5)) {
|
||||
// return false;
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -226,12 +226,12 @@ final class CommonInfo {
|
|||
return Boolean.valueOf((String)x); // throws an exception if this isn't a string
|
||||
}
|
||||
|
||||
// public String getAttributeAsString(String key) { return (String.valueOf(getAttribute(key))); } // **NOTE**: will turn a null Object into the String "null"
|
||||
// public int getAttributeAsInt(String key) { Object x = getAttribute(key); return x instanceof Integer ? (Integer)x : Integer.valueOf((String)x); }
|
||||
// public double getAttributeAsDouble(String key) { Object x = getAttribute(key); return x instanceof Double ? (Double)x : Double.valueOf((String)x); }
|
||||
// public boolean getAttributeAsBoolean(String key) { Object x = getAttribute(key); return x instanceof Boolean ? (Boolean)x : Boolean.valueOf((String)x); }
|
||||
// public String getAttributeAsString(String key) { return (String.valueOf(getExtendedAttribute(key))); } // **NOTE**: will turn a null Object into the String "null"
|
||||
// public int getAttributeAsInt(String key) { Object x = getExtendedAttribute(key); return x instanceof Integer ? (Integer)x : Integer.valueOf((String)x); }
|
||||
// public double getAttributeAsDouble(String key) { Object x = getExtendedAttribute(key); return x instanceof Double ? (Double)x : Double.valueOf((String)x); }
|
||||
// public boolean getAttributeAsBoolean(String key) { Object x = getExtendedAttribute(key); return x instanceof Boolean ? (Boolean)x : Boolean.valueOf((String)x); }
|
||||
// public Integer getAttributeAsIntegerNoException(String key) { try {return getAttributeAsInt(key);} catch (Exception e) {return null;} }
|
||||
// public Double getAttributeAsDoubleNoException(String key) { try {return getAttributeAsDouble(key);} catch (Exception e) {return null;} }
|
||||
// public String getAttributeAsStringNoException(String key) { if (getAttribute(key) == null) return null; return getAttributeAsString(key); }
|
||||
// public String getAttributeAsStringNoException(String key) { if (getExtendedAttribute(key) == null) return null; return getAttributeAsString(key); }
|
||||
// public Boolean getAttributeAsBooleanNoException(String key) { try {return getAttributeAsBoolean(key);} catch (Exception e) {return null;} }
|
||||
}
|
||||
|
|
@ -25,11 +25,8 @@
|
|||
package org.broadinstitute.sting.utils.variantcontext;
|
||||
|
||||
|
||||
import com.google.java.contract.Ensures;
|
||||
import com.google.java.contract.Requires;
|
||||
import org.broad.tribble.util.ParsingUtils;
|
||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFConstants;
|
||||
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -156,12 +153,12 @@ public final class FastGenotype extends Genotype {
|
|||
}
|
||||
|
||||
@Override public List<String> getFilters() {
|
||||
return (List<String>)getAttribute(VCFConstants.GENOTYPE_FILTER_KEY, Collections.emptyList());
|
||||
return (List<String>) getExtendedAttribute(VCFConstants.GENOTYPE_FILTER_KEY, Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean filtersWereApplied() {
|
||||
return hasAttribute(VCFConstants.GENOTYPE_FILTER_KEY);
|
||||
return hasExtendedAttribute(VCFConstants.GENOTYPE_FILTER_KEY);
|
||||
}
|
||||
|
||||
@Override public int[] getPL() {
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ public abstract class Genotype implements Comparable<Genotype> {
|
|||
* @return true if key has a value in the extendedAttributes
|
||||
*/
|
||||
@Requires({"key != null", "! isForbiddenKey(key)"})
|
||||
public boolean hasAttribute(final String key) {
|
||||
public boolean hasExtendedAttribute(final String key) {
|
||||
return getExtendedAttributes().containsKey(key);
|
||||
}
|
||||
|
||||
|
|
@ -432,19 +432,19 @@ public abstract class Genotype implements Comparable<Genotype> {
|
|||
* @return a value (potentially) null associated with key, or defaultValue if no association exists
|
||||
*/
|
||||
@Requires({"key != null", "! isForbiddenKey(key)"})
|
||||
@Ensures("hasAttribute(key) || result == defaultValue")
|
||||
public Object getAttribute(final String key, final Object defaultValue) {
|
||||
return hasAttribute(key) ? getExtendedAttributes().get(key) : defaultValue;
|
||||
@Ensures("hasExtendedAttribute(key) || result == defaultValue")
|
||||
public Object getExtendedAttribute(final String key, final Object defaultValue) {
|
||||
return hasExtendedAttribute(key) ? getExtendedAttributes().get(key) : defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as #getAttribute with a null default
|
||||
* Same as #getExtendedAttribute with a null default
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public Object getAttribute(final String key) {
|
||||
return getAttribute(key, null);
|
||||
public Object getExtendedAttribute(final String key) {
|
||||
return getExtendedAttribute(key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -468,7 +468,7 @@ public abstract class Genotype implements Comparable<Genotype> {
|
|||
|
||||
@Deprecated
|
||||
public String getAttributeAsString(String key, String defaultValue) {
|
||||
Object x = getAttribute(key);
|
||||
Object x = getExtendedAttribute(key);
|
||||
if ( x == null ) return defaultValue;
|
||||
if ( x instanceof String ) return (String)x;
|
||||
return String.valueOf(x); // throws an exception if this isn't a string
|
||||
|
|
@ -476,7 +476,7 @@ public abstract class Genotype implements Comparable<Genotype> {
|
|||
|
||||
@Deprecated
|
||||
public int getAttributeAsInt(String key, int defaultValue) {
|
||||
Object x = getAttribute(key);
|
||||
Object x = getExtendedAttribute(key);
|
||||
if ( x == null || x == VCFConstants.MISSING_VALUE_v4 ) return defaultValue;
|
||||
if ( x instanceof Integer ) return (Integer)x;
|
||||
return Integer.valueOf((String)x); // throws an exception if this isn't a string
|
||||
|
|
@ -484,7 +484,7 @@ public abstract class Genotype implements Comparable<Genotype> {
|
|||
|
||||
@Deprecated
|
||||
public double getAttributeAsDouble(String key, double defaultValue) {
|
||||
Object x = getAttribute(key);
|
||||
Object x = getExtendedAttribute(key);
|
||||
if ( x == null ) return defaultValue;
|
||||
if ( x instanceof Double ) return (Double)x;
|
||||
return Double.valueOf((String)x); // throws an exception if this isn't a string
|
||||
|
|
@ -510,7 +510,7 @@ public abstract class Genotype implements Comparable<Genotype> {
|
|||
} else if (key.equals(VCFConstants.DEPTH_KEY)) {
|
||||
return getDP();
|
||||
} else {
|
||||
return getAttribute(key);
|
||||
return getExtendedAttribute(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -526,7 +526,7 @@ public abstract class Genotype implements Comparable<Genotype> {
|
|||
} else if (key.equals(VCFConstants.DEPTH_KEY)) {
|
||||
return hasDP();
|
||||
} else {
|
||||
return hasAttribute(key);
|
||||
return hasExtendedAttribute(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -118,13 +118,13 @@ public class SlowGenotype extends Genotype {
|
|||
@Override public double getLog10PError() { return commonInfo.getLog10PError(); }
|
||||
|
||||
@Override
|
||||
public boolean hasAttribute(String key) { return commonInfo.hasAttribute(key); }
|
||||
public boolean hasExtendedAttribute(String key) { return commonInfo.hasAttribute(key); }
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String key) { return commonInfo.getAttribute(key); }
|
||||
public Object getExtendedAttribute(String key) { return commonInfo.getAttribute(key); }
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String key, Object defaultValue) {
|
||||
public Object getExtendedAttribute(String key, Object defaultValue) {
|
||||
return commonInfo.getAttribute(key, defaultValue);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -143,12 +143,12 @@ public abstract class BCF2FieldWriter {
|
|||
}
|
||||
|
||||
public void addGenotype(final BCF2Encoder encoder, final VariantContext vc, final Genotype g) throws IOException {
|
||||
final Object fieldValue = g.getAttribute(getField(), null);
|
||||
final Object fieldValue = g.getExtendedAttribute(getField(), null);
|
||||
getFieldEncoder().encodeValue(encoder, fieldValue, encodingType, nValuesPerGenotype);
|
||||
}
|
||||
|
||||
protected int numElements(final VariantContext vc, final Genotype g) {
|
||||
return getFieldEncoder().numElements(vc, g.getAttribute(getField()));
|
||||
return getFieldEncoder().numElements(vc, g.getExtendedAttribute(getField()));
|
||||
}
|
||||
|
||||
private final int computeMaxSizeOfGenotypeFieldFromValues(final VariantContext vc) {
|
||||
|
|
@ -179,7 +179,7 @@ public abstract class BCF2FieldWriter {
|
|||
// the only value that is dynamic are integers
|
||||
final List<Integer> values = new ArrayList<Integer>(vc.getNSamples());
|
||||
for ( final Genotype g : vc.getGenotypes() ) {
|
||||
for ( final Object i : BCF2Utils.toList(g.getAttribute(getField(), null)) ) {
|
||||
for ( final Object i : BCF2Utils.toList(g.getExtendedAttribute(getField(), null)) ) {
|
||||
values.add((Integer)i); // we know they are all integers
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ class VCFWriter extends IndexingVariantContextWriter {
|
|||
outputValue = sb.toString();
|
||||
}
|
||||
} else {
|
||||
Object val = g.hasAttribute(field) ? g.getAttribute(field) : VCFConstants.MISSING_VALUE_v4;
|
||||
Object val = g.hasExtendedAttribute(field) ? g.getExtendedAttribute(field) : VCFConstants.MISSING_VALUE_v4;
|
||||
|
||||
// some exceptions
|
||||
if ( field.equals(VCFConstants.GENOTYPE_FILTER_KEY ) ) {
|
||||
|
|
|
|||
|
|
@ -74,9 +74,9 @@ public class GenotypeUnitTest extends BaseTest {
|
|||
// public boolean hasLog10PError()
|
||||
// public double getLog10PError()
|
||||
// public double getPhredScaledQual()
|
||||
// public boolean hasAttribute(String key)
|
||||
// public Object getAttribute(String key)
|
||||
// public Object getAttribute(String key, Object defaultValue)
|
||||
// public boolean hasExtendedAttribute(String key)
|
||||
// public Object getExtendedAttribute(String key)
|
||||
// public Object getExtendedAttribute(String key, Object defaultValue)
|
||||
// public String getAttributeAsString(String key, String defaultValue)
|
||||
// public int getAttributeAsInt(String key, int defaultValue)
|
||||
// public double getAttributeAsDouble(String key, double defaultValue)
|
||||
|
|
|
|||
|
|
@ -315,7 +315,7 @@ public class VariantContextBenchmark extends SimpleBenchmark {
|
|||
// case GET_ATTRIBUTE_STRING:
|
||||
// return new FunctionToBenchmark<org.broadinstitute.sting.utils.variantcontext.v13.VariantContext>() {
|
||||
// public void run(final org.broadinstitute.sting.utils.variantcontext.v13.VariantContext vc) {
|
||||
// vc.getAttribute("AN", null);
|
||||
// vc.getExtendedAttribute("AN", null);
|
||||
// }
|
||||
// };
|
||||
//
|
||||
|
|
|
|||
|
|
@ -335,6 +335,28 @@ public class VariantContextTestProvider {
|
|||
GenotypeBuilder.create("hap", Arrays.asList(ref)));
|
||||
|
||||
addGenotypeTests(site,
|
||||
GenotypeBuilder.create("noCall", noCall),
|
||||
GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
|
||||
GenotypeBuilder.create("hap", Arrays.asList(ref)));
|
||||
|
||||
addGenotypeTests(site,
|
||||
GenotypeBuilder.create("noCall", noCall),
|
||||
GenotypeBuilder.create("noCall2", noCall),
|
||||
GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
|
||||
GenotypeBuilder.create("hap", Arrays.asList(ref)));
|
||||
|
||||
addGenotypeTests(site,
|
||||
GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
|
||||
GenotypeBuilder.create("tet", Arrays.asList(ref, alt1, alt1)));
|
||||
|
||||
addGenotypeTests(site,
|
||||
GenotypeBuilder.create("noCall", noCall),
|
||||
GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
|
||||
GenotypeBuilder.create("tet", Arrays.asList(ref, alt1, alt1)));
|
||||
|
||||
addGenotypeTests(site,
|
||||
GenotypeBuilder.create("noCall", noCall),
|
||||
GenotypeBuilder.create("noCall2", noCall),
|
||||
GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
|
||||
GenotypeBuilder.create("tet", Arrays.asList(ref, alt1, alt1)));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue