/** * Same as #getExtendedAttribute with a null default * * @param key * @return */ public Object getExtendedAttribute(final String key) { return getExtendedAttribute(key, null); }
/** * Same as #getExtendedAttribute with a null default * * @param key * @return */ public Object getExtendedAttribute(final String key) { return getExtendedAttribute(key, null); }
/** * Same as #getExtendedAttribute with a null default * * @param key * @return */ public Object getExtendedAttribute(final String key) { return getExtendedAttribute(key, null); }
@Override public double getAlternativeAlleleFraction(Genotype gt) { String refObsStr = (String) gt.getExtendedAttribute("RO"); String altObsStr = (String) gt.getExtendedAttribute("AO"); int refObs = Integer.parseInt(refObsStr); int altObs = Integer.parseInt(altObsStr); return ((double) altObs) / (refObs + altObs); }
@Deprecated public int getAttributeAsInt(String key, int defaultValue) { 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 }
@Deprecated public String getAttributeAsString(String key, String defaultValue) { 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 }
@Deprecated public int getAttributeAsInt(String key, int defaultValue) { 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 }
@Deprecated public double getAttributeAsDouble(String key, double defaultValue) { 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 }
@Deprecated public double getAttributeAsDouble(String key, double defaultValue) { 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 }
@Deprecated public String getAttributeAsString(String key, String defaultValue) { 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 }
@Deprecated public double getAttributeAsDouble(String key, double defaultValue) { 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 }
@Deprecated public String getAttributeAsString(String key, String defaultValue) { 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 }
@Deprecated public int getAttributeAsInt(String key, int defaultValue) { 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 }
@Override public double getAlleleFraction(Genotype gt, int alleleNo) { String strValue = (String) gt.getExtendedAttribute("DPR"); String[] arr = strValue.split(","); double countAllele = Integer.parseInt(arr[alleleNo]); return countAllele / (double) getCoverage(gt); }
@Override public double getAlleleFraction(Genotype gt, int alleleNo) { int coverage = getCoverage(gt); int numVar = Integer.parseInt(((String) gt.getExtendedAttribute("NV")).split(",")[0]); return ((double) numVar) / coverage; }
@Override public double getAlternativeAlleleFraction(Genotype gt) { String strValue = (String) gt.getExtendedAttribute("DPR"); String[] arr = strValue.split(","); return (getCoverage(gt) - Integer.parseInt(arr[0])) / (double) getCoverage(gt); }
@Override public void start(final BCF2Encoder encoder, final VariantContext vc) throws IOException { // 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.getExtendedAttribute(getField(), null)) ) { if ( i != null ) values.add((Integer)i); // we know they are all integers } } encodingType = BCF2Utils.determineIntegerType(values); super.start(encoder, vc); } }
@Requires({"encodingType != null", "nValuesPerGenotype >= 0"}) public void addGenotype(final BCF2Encoder encoder, final VariantContext vc, final Genotype g) throws IOException { final Object fieldValue = g.getExtendedAttribute(getField(), null); getFieldEncoder().encodeValue(encoder, fieldValue, encodingType, nValuesPerGenotype); }
static private String anchorFromVc(final VariantContext vc) { final Genotype genotype = vc.getGenotype(0); if (genotype == null || !genotype.hasExtendedAttribute(VCFConstants.PHASE_SET_KEY)) { return SYNTHETIC_PHASESET_PREFIX + "_" + vc.getContig() + "_" + vc.getStart(); } else { return PHASESET_PREFIX + "_" + vc.getContig() + "_" + genotype.getExtendedAttribute(VCFConstants.PHASE_SET_KEY); } }
static private String anchorFromVc(final VariantContext vc) { final Genotype genotype = vc.getGenotype(0); if (genotype == null || !genotype.hasExtendedAttribute(VCFConstants.PHASE_SET_KEY)) { return SYNTHETIC_PHASESET_PREFIX + "_" + vc.getContig() + "_" + vc.getStart(); } else { return PHASESET_PREFIX + "_" + vc.getContig() + "_" + genotype.getExtendedAttribute(VCFConstants.PHASE_SET_KEY); } }