ID field now stored in the VariantContext itself, not the attributes
This commit is contained in:
parent
233e581828
commit
460a51f473
|
|
@ -6,8 +6,10 @@ import org.broad.tribble.annotation.Strand;
|
|||
import org.broad.tribble.dbsnp.OldDbSNPFeature;
|
||||
import org.broad.tribble.gelitext.GeliTextFeature;
|
||||
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
|
||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||
import org.broadinstitute.sting.utils.classloader.PluginManager;
|
||||
import org.broadinstitute.sting.utils.codecs.hapmap.RawHapMapFeature;
|
||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFConstants;
|
||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFHeader;
|
||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLine;
|
||||
import org.broadinstitute.sting.utils.variantcontext.*;
|
||||
|
|
@ -187,7 +189,6 @@ public class VariantContextAdaptors {
|
|||
}
|
||||
|
||||
Map<String, Object> attributes = new HashMap<String, Object>();
|
||||
attributes.put(VariantContext.ID_KEY, dbsnp.getRsID());
|
||||
|
||||
int index = dbsnp.getStart() - ref.getWindow().getStart() - 1;
|
||||
if ( index < 0 )
|
||||
|
|
@ -195,7 +196,7 @@ public class VariantContextAdaptors {
|
|||
Byte refBaseForIndel = new Byte(ref.getBases()[index]);
|
||||
|
||||
GenotypeCollection genotypes = null;
|
||||
VariantContext vc = new VariantContext(name, dbsnp.getChr(), dbsnp.getStart() - (sawNullAllele ? 1 : 0), dbsnp.getEnd() - (refAllele.isNull() ? 1 : 0), alleles, genotypes, VariantContext.NO_NEG_LOG_10PERROR, null, attributes, refBaseForIndel);
|
||||
VariantContext vc = new VariantContext(name, dbsnp.getRsID(), dbsnp.getChr(), dbsnp.getStart() - (sawNullAllele ? 1 : 0), dbsnp.getEnd() - (refAllele.isNull() ? 1 : 0), alleles, genotypes, VariantContext.NO_NEG_LOG_10PERROR, null, attributes, refBaseForIndel);
|
||||
return vc;
|
||||
} else
|
||||
return null; // can't handle anything else
|
||||
|
|
@ -255,8 +256,8 @@ public class VariantContextAdaptors {
|
|||
// add the call to the genotype list, and then use this list to create a VariantContext
|
||||
genotypes.add(call);
|
||||
alleles.add(refAllele);
|
||||
VariantContext vc = VariantContextUtils.toVC(name, ref.getGenomeLocParser().createGenomeLoc(geli.getChr(),geli.getStart()), alleles, genotypes, geli.getLODBestToReference(), null, attributes);
|
||||
return vc;
|
||||
GenomeLoc loc = ref.getGenomeLocParser().createGenomeLoc(geli.getChr(),geli.getStart());
|
||||
return new VariantContext(name, VCFConstants.EMPTY_ID_FIELD, loc.getContig(), loc.getStart(), loc.getStop(), alleles, genotypes, geli.getLODBestToReference(), null, attributes);
|
||||
} else
|
||||
return null; // can't handle anything else
|
||||
}
|
||||
|
|
@ -347,13 +348,10 @@ public class VariantContextAdaptors {
|
|||
genotypes.add(g);
|
||||
}
|
||||
|
||||
HashMap<String, Object> attrs = new HashMap<String, Object>(1);
|
||||
attrs.put(VariantContext.ID_KEY, hapmap.getName());
|
||||
|
||||
long end = hapmap.getEnd();
|
||||
if ( deletionLength > 0 )
|
||||
end += deletionLength;
|
||||
VariantContext vc = new VariantContext(name, hapmap.getChr(), hapmap.getStart(), end, alleles, genotypes, VariantContext.NO_NEG_LOG_10PERROR, null, attrs, refBaseForIndel);
|
||||
VariantContext vc = new VariantContext(name, hapmap.getName(), hapmap.getChr(), hapmap.getStart(), end, alleles, genotypes, VariantContext.NO_NEG_LOG_10PERROR, null, null, refBaseForIndel);
|
||||
return vc;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,11 +163,10 @@ public class VariantAnnotatorEngine {
|
|||
}
|
||||
|
||||
public VariantContext annotateContext(RefMetaDataTracker tracker, ReferenceContext ref, Map<String, AlignmentContext> stratifiedContexts, VariantContext vc) {
|
||||
|
||||
Map<String, Object> infoAnnotations = new LinkedHashMap<String, Object>(vc.getAttributes());
|
||||
|
||||
// annotate db occurrences
|
||||
annotateDBs(tracker, ref, vc, infoAnnotations);
|
||||
vc = annotateDBs(tracker, ref, vc, infoAnnotations);
|
||||
|
||||
// annotate expressions where available
|
||||
annotateExpressions(tracker, ref, infoAnnotations);
|
||||
|
|
@ -186,14 +185,14 @@ public class VariantAnnotatorEngine {
|
|||
return VariantContext.modifyGenotypes(annotatedVC, annotateGenotypes(tracker, ref, stratifiedContexts, vc));
|
||||
}
|
||||
|
||||
private void annotateDBs(RefMetaDataTracker tracker, ReferenceContext ref, VariantContext vc, Map<String, Object> infoAnnotations) {
|
||||
private VariantContext annotateDBs(RefMetaDataTracker tracker, ReferenceContext ref, VariantContext vc, Map<String, Object> infoAnnotations) {
|
||||
for ( Map.Entry<RodBinding<VariantContext>, String> dbSet : dbAnnotations.entrySet() ) {
|
||||
if ( dbSet.getValue().equals(VCFConstants.DBSNP_KEY) ) {
|
||||
String rsID = VCFUtils.rsIDOfFirstRealVariant(tracker.getValues(dbSet.getKey(), ref.getLocus()), vc.getType());
|
||||
infoAnnotations.put(VCFConstants.DBSNP_KEY, rsID != null);
|
||||
// annotate dbsnp id if available and not already there
|
||||
if ( rsID != null && (!vc.hasID() || vc.getID().equals(VCFConstants.EMPTY_ID_FIELD)) )
|
||||
infoAnnotations.put(VariantContext.ID_KEY, rsID);
|
||||
if ( rsID != null && vc.emptyID() )
|
||||
vc = VariantContext.modifyID(vc, rsID);
|
||||
} else {
|
||||
boolean overlapsComp = false;
|
||||
for ( VariantContext comp : tracker.getValues(dbSet.getKey(), ref.getLocus()) ) {
|
||||
|
|
@ -205,6 +204,8 @@ public class VariantAnnotatorEngine {
|
|||
infoAnnotations.put(dbSet.getValue(), overlapsComp);
|
||||
}
|
||||
}
|
||||
|
||||
return vc;
|
||||
}
|
||||
|
||||
private void annotateExpressions(RefMetaDataTracker tracker, ReferenceContext ref, Map<String, Object> infoAnnotations) {
|
||||
|
|
|
|||
|
|
@ -333,11 +333,11 @@ public class BeagleOutputToVCFWalker extends RodWalker<Integer, Integer> {
|
|||
|
||||
VariantContext filteredVC;
|
||||
if ( beagleVarCounts > 0 || DONT_FILTER_MONOMORPHIC_SITES )
|
||||
filteredVC = new VariantContext("outputvcf", vc_input.getChr(), vc_input.getStart(), vc_input.getEnd(), vc_input.getAlleles(), genotypes, vc_input.getNegLog10PError(), vc_input.filtersWereApplied() ? vc_input.getFilters() : null, vc_input.getAttributes());
|
||||
filteredVC = new VariantContext("outputvcf", VCFConstants.EMPTY_ID_FIELD, vc_input.getChr(), vc_input.getStart(), vc_input.getEnd(), vc_input.getAlleles(), genotypes, vc_input.getNegLog10PError(), vc_input.filtersWereApplied() ? vc_input.getFilters() : null, vc_input.getAttributes());
|
||||
else {
|
||||
Set<String> removedFilters = vc_input.filtersWereApplied() ? new HashSet<String>(vc_input.getFilters()) : new HashSet<String>(1);
|
||||
removedFilters.add(String.format("BGL_RM_WAS_%s",vc_input.getAlternateAllele(0)));
|
||||
filteredVC = new VariantContext("outputvcf", vc_input.getChr(), vc_input.getStart(), vc_input.getEnd(), new HashSet<Allele>(Arrays.asList(vc_input.getReference())), genotypes, vc_input.getNegLog10PError(), removedFilters, vc_input.getAttributes());
|
||||
filteredVC = new VariantContext("outputvcf", VCFConstants.EMPTY_ID_FIELD, vc_input.getChr(), vc_input.getStart(), vc_input.getEnd(), new HashSet<Allele>(Arrays.asList(vc_input.getReference())), genotypes, vc_input.getNegLog10PError(), removedFilters, vc_input.getAttributes());
|
||||
}
|
||||
|
||||
HashMap<String, Object> attributes = new HashMap<String, Object>(filteredVC.getAttributes());
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class VCFDiffableReader implements DiffableReader {
|
|||
// add fields
|
||||
vcRoot.add("CHROM", vc.getChr());
|
||||
vcRoot.add("POS", vc.getStart());
|
||||
vcRoot.add("ID", vc.hasID() ? vc.getID() : VCFConstants.MISSING_VALUE_v4);
|
||||
vcRoot.add("ID", vc.getID());
|
||||
vcRoot.add("REF", vc.getReference());
|
||||
vcRoot.add("ALT", vc.getAlternateAlleles());
|
||||
vcRoot.add("QUAL", vc.hasNegLog10PError() ? vc.getNegLog10PError() * 10 : VCFConstants.MISSING_VALUE_v4);
|
||||
|
|
@ -98,7 +98,7 @@ public class VCFDiffableReader implements DiffableReader {
|
|||
|
||||
// add info fields
|
||||
for (Map.Entry<String, Object> attribute : vc.getAttributes().entrySet()) {
|
||||
if ( ! attribute.getKey().startsWith("_") && ! attribute.getKey().equals(VariantContext.ID_KEY))
|
||||
if ( ! attribute.getKey().startsWith("_") )
|
||||
vcRoot.add(attribute.getKey(), attribute.getValue());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ public class VariantFiltrationWalker extends RodWalker<Integer, Integer> {
|
|||
if ( genotypes == null )
|
||||
filteredVC = VariantContext.modifyFilters(vc, filters);
|
||||
else
|
||||
filteredVC = new VariantContext(vc.getSource(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), genotypes, vc.getNegLog10PError(), filters, vc.getAttributes());
|
||||
filteredVC = new VariantContext(vc.getSource(), vc.getID(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), genotypes, vc.getNegLog10PError(), filters, vc.getAttributes());
|
||||
|
||||
writer.add(filteredVC);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ public class UGCallVariants extends RodWalker<VariantCallContext, Integer> {
|
|||
VariantContext vc = VCs.get(0);
|
||||
throw new UserException("There is no ALT allele in any of the VCF records passed in at " + vc.getChr() + ":" + vc.getStart());
|
||||
}
|
||||
return new VariantContext("VCwithGLs", variantVC.getChr(), variantVC.getStart(), variantVC.getEnd(), variantVC.getAlleles(), genotypes, VariantContext.NO_NEG_LOG_10PERROR, null, null);
|
||||
return new VariantContext("VCwithGLs", VCFConstants.EMPTY_ID_FIELD, variantVC.getChr(), variantVC.getStart(), variantVC.getEnd(), variantVC.getAlleles(), genotypes, VariantContext.NO_NEG_LOG_10PERROR, null, null);
|
||||
}
|
||||
|
||||
private static GenotypeCollection getGenotypesWithGLs(GenotypeCollection genotypes) {
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ public class UnifiedGenotyperEngine {
|
|||
VariantContext vcInput = UnifiedGenotyperEngine.getVCFromAllelesRod(tracker, ref, rawContext.getLocation(), false, logger, UAC.alleles);
|
||||
if ( vcInput == null )
|
||||
return null;
|
||||
vc = new VariantContext("UG_call", vcInput.getChr(), vcInput.getStart(), vcInput.getEnd(), vcInput.getAlleles(), VariantContext.NO_NEG_LOG_10PERROR, null, null, ref.getBase());
|
||||
vc = new VariantContext("UG_call", VCFConstants.EMPTY_ID_FIELD, vcInput.getChr(), vcInput.getStart(), vcInput.getEnd(), vcInput.getAlleles(), VariantContext.NO_NEG_LOG_10PERROR, null, null, ref.getBase());
|
||||
|
||||
} else {
|
||||
// deal with bad/non-standard reference bases
|
||||
|
|
@ -238,7 +238,7 @@ public class UnifiedGenotyperEngine {
|
|||
|
||||
Set<Allele> alleles = new HashSet<Allele>();
|
||||
alleles.add(Allele.create(ref.getBase(), true));
|
||||
vc = new VariantContext("UG_call", ref.getLocus().getContig(), ref.getLocus().getStart(), ref.getLocus().getStart(), alleles);
|
||||
vc = new VariantContext("UG_call", VCFConstants.EMPTY_ID_FIELD, ref.getLocus().getContig(), ref.getLocus().getStart(), ref.getLocus().getStart(), alleles);
|
||||
}
|
||||
|
||||
if ( annotationEngine != null ) {
|
||||
|
|
@ -288,7 +288,7 @@ public class UnifiedGenotyperEngine {
|
|||
int endLoc = calculateEndPos(alleles, refAllele, loc);
|
||||
|
||||
return new VariantContext("UG_call",
|
||||
loc.getContig(),
|
||||
VCFConstants.EMPTY_ID_FIELD, loc.getContig(),
|
||||
loc.getStart(),
|
||||
endLoc,
|
||||
alleles,
|
||||
|
|
@ -420,7 +420,7 @@ public class UnifiedGenotyperEngine {
|
|||
myAlleles = new HashSet<Allele>(1);
|
||||
myAlleles.add(vc.getReference());
|
||||
}
|
||||
VariantContext vcCall = new VariantContext("UG_call", loc.getContig(), loc.getStart(), endLoc,
|
||||
VariantContext vcCall = new VariantContext("UG_call", VCFConstants.EMPTY_ID_FIELD, loc.getContig(), loc.getStart(), endLoc,
|
||||
myAlleles, genotypes, phredScaledConfidence/10.0, passesCallThreshold(phredScaledConfidence) ? null : filter, attributes, refContext.getBase());
|
||||
|
||||
if ( annotationEngine != null ) {
|
||||
|
|
@ -504,7 +504,7 @@ public class UnifiedGenotyperEngine {
|
|||
myAlleles = new HashSet<Allele>(1);
|
||||
myAlleles.add(vc.getReference());
|
||||
}
|
||||
VariantContext vcCall = new VariantContext("UG_call", loc.getContig(), loc.getStart(), endLoc,
|
||||
VariantContext vcCall = new VariantContext("UG_call", VCFConstants.EMPTY_ID_FIELD, loc.getContig(), loc.getStart(), endLoc,
|
||||
myAlleles, genotypes, phredScaledConfidence/10.0, passesCallThreshold(phredScaledConfidence) ? null : filter, attributes, vc.getReferenceBaseForIndel());
|
||||
|
||||
return new VariantCallContext(vcCall, confidentlyCalled(phredScaledConfidence, PofF));
|
||||
|
|
|
|||
|
|
@ -1074,7 +1074,7 @@ public class SomaticIndelDetectorWalker extends ReadWalker<Integer,Integer> {
|
|||
filters = new HashSet<String>();
|
||||
filters.add("NoCall");
|
||||
}
|
||||
VariantContext vc = new VariantContext("IGv2_Indel_call", refName, start, stop, alleles, genotypes,
|
||||
VariantContext vc = new VariantContext("IGv2_Indel_call", VCFConstants.EMPTY_ID_FIELD, refName, start, stop, alleles, genotypes,
|
||||
-1.0 /* log error */, filters, null, refBases[(int)start-1]);
|
||||
vcf.add(vc);
|
||||
}
|
||||
|
|
@ -1171,7 +1171,7 @@ public class SomaticIndelDetectorWalker extends ReadWalker<Integer,Integer> {
|
|||
filters.add("TCov");
|
||||
}
|
||||
|
||||
VariantContext vc = new VariantContext("IGv2_Indel_call", refName, start, stop, alleles, genotypes,
|
||||
VariantContext vc = new VariantContext("IGv2_Indel_call", VCFConstants.EMPTY_ID_FIELD, refName, start, stop, alleles, genotypes,
|
||||
-1.0 /* log error */, filters, attrs, refBases[(int)start-1]);
|
||||
vcf.add(vc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1141,7 +1141,7 @@ public class ReadBackedPhasingWalker extends RodWalker<PhasingStatsAndOutput, Ph
|
|||
}
|
||||
|
||||
public VariantContext toVariantContext() {
|
||||
return new VariantContext(name, contig, start, stop, alleles, genotypes, negLog10PError, filters, attributes);
|
||||
return new VariantContext(name, VCFConstants.EMPTY_ID_FIELD, contig, start, stop, alleles, genotypes, negLog10PError, filters, attributes);
|
||||
}
|
||||
|
||||
public GenomeLoc getLocation() {
|
||||
|
|
|
|||
|
|
@ -223,6 +223,6 @@ public class LeftAlignVariants extends RodWalker<Integer, Integer> {
|
|||
newGenotypes.add(Genotype.modifyAlleles(genotype, newAlleles));
|
||||
}
|
||||
|
||||
return new VariantContext(vc.getSource(), vc.getChr(), vc.getStart(), vc.getEnd(), alleleMap.values(), newGenotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, vc.getAttributes(), refBaseForIndel);
|
||||
return new VariantContext(vc.getSource(), vc.getID(), vc.getChr(), vc.getStart(), vc.getEnd(), alleleMap.values(), newGenotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, vc.getAttributes(), refBaseForIndel);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -315,7 +315,7 @@ public class VariantsToTable extends RodWalker<Integer, Integer> {
|
|||
getters.put("FILTER", new Getter() { public String get(VariantContext vc) {
|
||||
return vc.isNotFiltered() ? "PASS" : Utils.join(",", vc.getFilters()); }
|
||||
});
|
||||
getters.put("ID", new Getter() { public String get(VariantContext vc) { return vc.hasID() ? vc.getID() : "."; } });
|
||||
getters.put("ID", new Getter() { public String get(VariantContext vc) { return vc.getID(); } });
|
||||
getters.put("HET", new Getter() { public String get(VariantContext vc) { return Integer.toString(vc.getHetCount()); } });
|
||||
getters.put("HOM-REF", new Getter() { public String get(VariantContext vc) { return Integer.toString(vc.getHomRefCount()); } });
|
||||
getters.put("HOM-VAR", new Getter() { public String get(VariantContext vc) { return Integer.toString(vc.getHomVarCount()); } });
|
||||
|
|
|
|||
|
|
@ -121,10 +121,8 @@ public class VariantsToVCF extends RodWalker<Integer, Integer> {
|
|||
Collection<VariantContext> contexts = getVariantContexts(tracker, ref);
|
||||
|
||||
for ( VariantContext vc : contexts ) {
|
||||
Map<String, Object> attrs = new HashMap<String, Object>(vc.getAttributes());
|
||||
if ( rsID != null && !vc.hasID() ) {
|
||||
attrs.put(VariantContext.ID_KEY, rsID);
|
||||
vc = VariantContext.modifyAttributes(vc, attrs);
|
||||
if ( rsID != null && vc.emptyID() ) {
|
||||
vc = VariantContext.modifyID(vc, rsID);
|
||||
}
|
||||
|
||||
// set the appropriate sample name if necessary
|
||||
|
|
@ -203,7 +201,7 @@ public class VariantsToVCF extends RodWalker<Integer, Integer> {
|
|||
while ( dbsnpIterator.hasNext() ) {
|
||||
GATKFeature feature = dbsnpIterator.next();
|
||||
VariantContext vc = (VariantContext)feature.getUnderlyingObject();
|
||||
if ( vc.hasID() && vc.getID().equals(rsID) )
|
||||
if ( vc.getID().equals(rsID) )
|
||||
return vc;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ public abstract class AbstractVCFCodec implements FeatureCodec, NameAwareCodec,
|
|||
else if ( parts[2].equals(VCFConstants.EMPTY_ID_FIELD) )
|
||||
id = VCFConstants.EMPTY_ID_FIELD;
|
||||
else
|
||||
id = new String(parts[2]);
|
||||
id = parts[2];
|
||||
String ref = getCachedString(parts[3].toUpperCase());
|
||||
String alts = getCachedString(parts[4].toUpperCase());
|
||||
Double qual = parseQual(parts[5]);
|
||||
|
|
@ -274,7 +274,7 @@ public abstract class AbstractVCFCodec implements FeatureCodec, NameAwareCodec,
|
|||
// get our alleles, filters, and setup an attribute map
|
||||
List<Allele> alleles = parseAlleles(ref, alts, lineNo);
|
||||
Set<String> filters = parseFilters(filter);
|
||||
Map<String, Object> attributes = parseInfo(info, id);
|
||||
Map<String, Object> attributes = parseInfo(info);
|
||||
|
||||
// find out our current location, and clip the alleles down to their minimum length
|
||||
int loc = pos;
|
||||
|
|
@ -295,7 +295,7 @@ public abstract class AbstractVCFCodec implements FeatureCodec, NameAwareCodec,
|
|||
|
||||
VariantContext vc = null;
|
||||
try {
|
||||
vc = new VariantContext(name, contig, pos, loc, alleles, qual, filters, attributes, ref.getBytes()[0]);
|
||||
vc = new VariantContext(name, id, contig, pos, loc, alleles, qual, filters, attributes, ref.getBytes()[0]);
|
||||
} catch (Exception e) {
|
||||
generateException(e.getMessage());
|
||||
}
|
||||
|
|
@ -349,10 +349,9 @@ public abstract class AbstractVCFCodec implements FeatureCodec, NameAwareCodec,
|
|||
/**
|
||||
* parse out the info fields
|
||||
* @param infoField the fields
|
||||
* @param id the indentifier
|
||||
* @return a mapping of keys to objects
|
||||
*/
|
||||
private Map<String, Object> parseInfo(String infoField, String id) {
|
||||
private Map<String, Object> parseInfo(String infoField) {
|
||||
Map<String, Object> attributes = new HashMap<String, Object>();
|
||||
|
||||
if ( infoField.length() == 0 )
|
||||
|
|
@ -391,8 +390,6 @@ public abstract class AbstractVCFCodec implements FeatureCodec, NameAwareCodec,
|
|||
}
|
||||
}
|
||||
|
||||
if ( ! id.equals(VCFConstants.EMPTY_ID_FIELD) )
|
||||
attributes.put(VariantContext.ID_KEY, id);
|
||||
return attributes;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ public class StandardVCFWriter extends IndexingVCFWriter {
|
|||
mWriter.write(VCFConstants.FIELD_SEPARATOR);
|
||||
|
||||
// ID
|
||||
String ID = vc.hasID() ? vc.getID() : VCFConstants.EMPTY_ID_FIELD;
|
||||
String ID = vc.getID();
|
||||
mWriter.write(ID);
|
||||
mWriter.write(VCFConstants.FIELD_SEPARATOR);
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ public class StandardVCFWriter extends IndexingVCFWriter {
|
|||
Map<String, String> infoFields = new TreeMap<String, String>();
|
||||
for ( Map.Entry<String, Object> field : vc.getAttributes().entrySet() ) {
|
||||
String key = field.getKey();
|
||||
if ( key.equals(VariantContext.ID_KEY) || key.equals(VariantContext.UNPARSED_GENOTYPE_MAP_KEY) || key.equals(VariantContext.UNPARSED_GENOTYPE_PARSER_KEY) )
|
||||
if ( key.equals(VariantContext.UNPARSED_GENOTYPE_MAP_KEY) || key.equals(VariantContext.UNPARSED_GENOTYPE_PARSER_KEY) )
|
||||
continue;
|
||||
|
||||
String outputValue = formatVCFField(field.getValue());
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
package org.broadinstitute.sting.utils.gcf;
|
||||
|
||||
import org.broadinstitute.sting.utils.codecs.vcf.StandardVCFWriter;
|
||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFConstants;
|
||||
import org.broadinstitute.sting.utils.exceptions.UserException;
|
||||
import org.broadinstitute.sting.utils.variantcontext.Allele;
|
||||
import org.broadinstitute.sting.utils.variantcontext.Genotype;
|
||||
|
|
@ -148,7 +149,7 @@ public class GCF {
|
|||
Byte refPadByte = refPad == 0 ? null : refPad;
|
||||
GenotypeCollection genotypes = decodeGenotypes(header);
|
||||
|
||||
return new VariantContext(source, contig, start, stop, alleleMap, genotypes, negLog10PError, filters, attributes, refPadByte);
|
||||
return new VariantContext(source, VCFConstants.EMPTY_ID_FIELD, contig, start, stop, alleleMap, genotypes, negLog10PError, filters, attributes, refPadByte);
|
||||
}
|
||||
|
||||
private GenotypeCollection decodeGenotypes(final GCFHeader header) {
|
||||
|
|
@ -193,7 +194,7 @@ public class GCF {
|
|||
boolean first = true;
|
||||
for ( Map.Entry<String, Object> field : vc.getAttributes().entrySet() ) {
|
||||
String key = field.getKey();
|
||||
if ( key.equals(VariantContext.ID_KEY) || key.equals(VariantContext.UNPARSED_GENOTYPE_MAP_KEY) || key.equals(VariantContext.UNPARSED_GENOTYPE_PARSER_KEY) )
|
||||
if ( key.equals(VariantContext.UNPARSED_GENOTYPE_MAP_KEY) || key.equals(VariantContext.UNPARSED_GENOTYPE_PARSER_KEY) )
|
||||
continue;
|
||||
int stringIndex = GCFHeaderBuilder.encodeString(key);
|
||||
String outputValue = StandardVCFWriter.formatVCFField(field.getValue());
|
||||
|
|
|
|||
|
|
@ -167,16 +167,19 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
public final static double NO_NEG_LOG_10PERROR = CommonInfo.NO_NEG_LOG_10PERROR;
|
||||
public final static String UNPARSED_GENOTYPE_MAP_KEY = "_UNPARSED_GENOTYPE_MAP_";
|
||||
public final static String UNPARSED_GENOTYPE_PARSER_KEY = "_UNPARSED_GENOTYPE_PARSER_";
|
||||
public final static String ID_KEY = "ID";
|
||||
|
||||
@Deprecated // ID is no longer stored in the attributes map
|
||||
private final static String ID_KEY = "ID";
|
||||
|
||||
private final Byte REFERENCE_BASE_FOR_INDEL;
|
||||
|
||||
public final static Set<String> PASSES_FILTERS = Collections.unmodifiableSet(new LinkedHashSet<String>());
|
||||
|
||||
/** The location of this VariantContext */
|
||||
protected String contig;
|
||||
protected long start;
|
||||
protected long stop;
|
||||
final protected String contig;
|
||||
final protected long start;
|
||||
final protected long stop;
|
||||
private final String ID;
|
||||
|
||||
/** The type (cached for performance reasons) of this context */
|
||||
protected Type type = null;
|
||||
|
|
@ -199,7 +202,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
private Allele ALT = null;
|
||||
|
||||
// were filters applied?
|
||||
private boolean filtersWereAppliedToContext;
|
||||
final private boolean filtersWereAppliedToContext;
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
|
|
@ -223,10 +226,16 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
* @param attributes attributes
|
||||
* @param referenceBaseForIndel padded reference base
|
||||
*/
|
||||
public VariantContext(String source, String contig, long start, long stop, Collection<Allele> alleles, GenotypeCollection genotypes, double negLog10PError, Set<String> filters, Map<String, Object> attributes, Byte referenceBaseForIndel) {
|
||||
this(source, contig, start, stop, alleles, genotypes, negLog10PError, filters, attributes, referenceBaseForIndel, false, true);
|
||||
public VariantContext(String source, String ID, String contig, long start, long stop, Collection<Allele> alleles, GenotypeCollection genotypes, double negLog10PError, Set<String> filters, Map<String, Object> attributes, Byte referenceBaseForIndel) {
|
||||
this(source, ID, contig, start, stop, alleles, genotypes, negLog10PError, filters, attributes, referenceBaseForIndel, false, true);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public VariantContext(String source, String contig, long start, long stop, Collection<Allele> alleles, GenotypeCollection genotypes, double negLog10PError, Set<String> filters, Map<String, Object> attributes, Byte referenceBaseForIndel) {
|
||||
this(source, VCFConstants.EMPTY_ID_FIELD, contig, start, stop, alleles, genotypes, negLog10PError, filters, attributes, referenceBaseForIndel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* the complete constructor. Makes a complete VariantContext from its arguments
|
||||
*
|
||||
|
|
@ -240,8 +249,13 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
* @param filters filters: use null for unfiltered and empty set for passes filters
|
||||
* @param attributes attributes
|
||||
*/
|
||||
public VariantContext(String source, String ID, String contig, long start, long stop, Collection<Allele> alleles, GenotypeCollection genotypes, double negLog10PError, Set<String> filters, Map<String, Object> attributes) {
|
||||
this(source, ID, contig, start, stop, alleles, genotypes, negLog10PError, filters, attributes, null, false, true);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public VariantContext(String source, String contig, long start, long stop, Collection<Allele> alleles, GenotypeCollection genotypes, double negLog10PError, Set<String> filters, Map<String, Object> attributes) {
|
||||
this(source, contig, start, stop, alleles, genotypes, negLog10PError, filters, attributes, null, false, true);
|
||||
this(source, VCFConstants.EMPTY_ID_FIELD, contig, start, stop, alleles, genotypes, negLog10PError, filters, attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -261,8 +275,13 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
* @param attributes attributes
|
||||
* @param referenceBaseForIndel padded reference base
|
||||
*/
|
||||
public VariantContext(String source, String ID, String contig, long start, long stop, Collection<Allele> alleles, double negLog10PError, Set<String> filters, Map<String, Object> attributes, Byte referenceBaseForIndel) {
|
||||
this(source, ID, contig, start, stop, alleles, NO_GENOTYPES, negLog10PError, filters, attributes, referenceBaseForIndel, true, true);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public VariantContext(String source, String contig, long start, long stop, Collection<Allele> alleles, double negLog10PError, Set<String> filters, Map<String, Object> attributes, Byte referenceBaseForIndel) {
|
||||
this(source, contig, start, stop, alleles, NO_GENOTYPES, negLog10PError, filters, attributes, referenceBaseForIndel, true, true);
|
||||
this(source, VCFConstants.EMPTY_ID_FIELD, contig, start, stop, alleles, negLog10PError, filters, attributes, referenceBaseForIndel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -278,12 +297,19 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
* @param filters filters: use null for unfiltered and empty set for passes filters
|
||||
* @param attributes attributes
|
||||
*/
|
||||
public VariantContext(String source, String contig, long start, long stop, Collection<Allele> alleles, Collection<Genotype> genotypes, double negLog10PError, Set<String> filters, Map<String, Object> attributes) {
|
||||
this(source, contig, start, stop, alleles,
|
||||
public VariantContext(String source, String ID, String contig, long start, long stop, Collection<Allele> alleles, Collection<Genotype> genotypes, double negLog10PError, Set<String> filters, Map<String, Object> attributes) {
|
||||
this(source, ID, contig, start, stop, alleles,
|
||||
GenotypeCollection.copy(genotypes),
|
||||
negLog10PError, filters, attributes, null, false, true);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public VariantContext(String source, String contig, long start, long stop, Collection<Allele> alleles, Collection<Genotype> genotypes, double negLog10PError, Set<String> filters, Map<String, Object> attributes) {
|
||||
this(source, VCFConstants.EMPTY_ID_FIELD, contig, start, stop, alleles,
|
||||
GenotypeCollection.copy(genotypes),
|
||||
negLog10PError, filters, attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new variant context without genotypes and no Perror, no filters, and no attributes
|
||||
*
|
||||
|
|
@ -293,8 +319,13 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
* @param stop the stop reference base (one based)
|
||||
* @param alleles alleles
|
||||
*/
|
||||
public VariantContext(String source, String ID, String contig, long start, long stop, Collection<Allele> alleles) {
|
||||
this(source, ID, contig, start, stop, alleles, NO_GENOTYPES, CommonInfo.NO_NEG_LOG_10PERROR, null, null, null, false, true);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public VariantContext(String source, String contig, long start, long stop, Collection<Allele> alleles) {
|
||||
this(source, contig, start, stop, alleles, NO_GENOTYPES, CommonInfo.NO_NEG_LOG_10PERROR, null, null, null, false, true);
|
||||
this(source, VCFConstants.EMPTY_ID_FIELD, contig, start, stop, alleles);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -307,8 +338,13 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
* @param alleles alleles
|
||||
* @param genotypes genotypes
|
||||
*/
|
||||
public VariantContext(String source, String ID, String contig, long start, long stop, Collection<Allele> alleles, Collection<Genotype> genotypes) {
|
||||
this(source, ID, contig, start, stop, alleles, genotypes, CommonInfo.NO_NEG_LOG_10PERROR, null, null);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public VariantContext(String source, String contig, long start, long stop, Collection<Allele> alleles, Collection<Genotype> genotypes) {
|
||||
this(source, contig, start, stop, alleles, genotypes, CommonInfo.NO_NEG_LOG_10PERROR, null, null);
|
||||
this(source, VCFConstants.EMPTY_ID_FIELD, contig, start, stop, alleles, genotypes, CommonInfo.NO_NEG_LOG_10PERROR, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -317,7 +353,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
* @param other the VariantContext to copy
|
||||
*/
|
||||
public VariantContext(VariantContext other) {
|
||||
this(other.getSource(), other.getChr(), other.getStart(), other.getEnd() , other.getAlleles(), other.getGenotypes(), other.getNegLog10PError(), other.filtersWereApplied() ? other.getFilters() : null, other.getAttributes(), other.REFERENCE_BASE_FOR_INDEL, false, true);
|
||||
this(other.getSource(), other.getID(), other.getChr(), other.getStart(), other.getEnd() , other.getAlleles(), other.getGenotypes(), other.getNegLog10PError(), other.filtersWereApplied() ? other.getFilters() : null, other.getAttributes(), other.REFERENCE_BASE_FOR_INDEL, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -336,7 +372,8 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
* @param genotypesAreUnparsed true if the genotypes have not yet been parsed
|
||||
* @param performValidation if true, call validate() as the final step in construction
|
||||
*/
|
||||
private VariantContext(String source, String contig, long start, long stop,
|
||||
private VariantContext(String source, String ID,
|
||||
String contig, long start, long stop,
|
||||
Collection<Allele> alleles, GenotypeCollection genotypes,
|
||||
double negLog10PError, Set<String> filters, Map<String, Object> attributes,
|
||||
Byte referenceBaseForIndel, boolean genotypesAreUnparsed,
|
||||
|
|
@ -346,6 +383,10 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
this.start = start;
|
||||
this.stop = stop;
|
||||
|
||||
// intern for efficiency. equals calls will generate NPE if ID is inappropriately passed in as null
|
||||
this.ID = ID.equals(VCFConstants.EMPTY_ID_FIELD) ? VCFConstants.EMPTY_ID_FIELD : ID;
|
||||
if ( this.ID.equals("") ) throw new IllegalArgumentException("ID field cannot be the empty string");
|
||||
|
||||
if ( !genotypesAreUnparsed && attributes != null ) {
|
||||
if ( attributes.containsKey(UNPARSED_GENOTYPE_MAP_KEY) )
|
||||
attributes.remove(UNPARSED_GENOTYPE_MAP_KEY);
|
||||
|
|
@ -357,13 +398,17 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
filtersWereAppliedToContext = filters != null;
|
||||
REFERENCE_BASE_FOR_INDEL = referenceBaseForIndel;
|
||||
|
||||
// todo -- remove me when this check is no longer necessary
|
||||
if ( this.commonInfo.hasAttribute(ID_KEY) )
|
||||
throw new IllegalArgumentException("Trying to create a VariantContext with a ID key. Please use provided constructor argument ID");
|
||||
|
||||
if ( alleles == null ) { throw new IllegalArgumentException("Alleles cannot be null"); }
|
||||
|
||||
// we need to make this a LinkedHashSet in case the user prefers a given ordering of alleles
|
||||
this.alleles = makeAlleles(alleles);
|
||||
|
||||
if ( genotypes == null ) {
|
||||
genotypes = NO_GENOTYPES;
|
||||
this.genotypes = NO_GENOTYPES;
|
||||
} else {
|
||||
this.genotypes = genotypes.immutable();
|
||||
}
|
||||
|
|
@ -397,13 +442,13 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
// ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static VariantContext modifyGenotypes(VariantContext vc, GenotypeCollection genotypes) {
|
||||
VariantContext modifiedVC = new VariantContext(vc.getSource(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, vc.getAttributes(), vc.getReferenceBaseForIndel(), false, false);
|
||||
VariantContext modifiedVC = new VariantContext(vc.getSource(), vc.getID(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, vc.getAttributes(), vc.getReferenceBaseForIndel(), false, false);
|
||||
modifiedVC.validateGenotypes();
|
||||
return modifiedVC;
|
||||
}
|
||||
|
||||
public static VariantContext modifyLocation(VariantContext vc, String chr, int start, int end) {
|
||||
VariantContext modifiedVC = new VariantContext(vc.getSource(), chr, start, end, vc.getAlleles(), vc.genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, vc.getAttributes(), vc.getReferenceBaseForIndel(), true, false);
|
||||
VariantContext modifiedVC = new VariantContext(vc.getSource(), vc.getID(), chr, start, end, vc.getAlleles(), vc.genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, vc.getAttributes(), vc.getReferenceBaseForIndel(), true, false);
|
||||
|
||||
// Since start and end have changed, we need to call both validateAlleles() and validateReferencePadding(),
|
||||
// since those validation routines rely on the values of start and end:
|
||||
|
|
@ -414,31 +459,31 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
}
|
||||
|
||||
public static VariantContext modifyFilters(VariantContext vc, Set<String> filters) {
|
||||
return new VariantContext(vc.getSource(), vc.getChr(), vc.getStart(), vc.getEnd() , vc.getAlleles(), vc.genotypes, vc.getNegLog10PError(), filters, new HashMap<String, Object>(vc.getAttributes()), vc.getReferenceBaseForIndel(), true, false);
|
||||
return new VariantContext(vc.getSource(), vc.getID(), vc.getChr(), vc.getStart(), vc.getEnd() , vc.getAlleles(), vc.genotypes, vc.getNegLog10PError(), filters, new HashMap<String, Object>(vc.getAttributes()), vc.getReferenceBaseForIndel(), true, false);
|
||||
}
|
||||
|
||||
public static VariantContext modifyAttributes(VariantContext vc, Map<String, Object> attributes) {
|
||||
return new VariantContext(vc.getSource(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), vc.genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, attributes, vc.getReferenceBaseForIndel(), true, false);
|
||||
return new VariantContext(vc.getSource(), vc.getID(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), vc.genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, attributes, vc.getReferenceBaseForIndel(), true, false);
|
||||
}
|
||||
|
||||
public static VariantContext modifyAttribute(VariantContext vc, final String key, final Object value) {
|
||||
Map<String, Object> attributes = new HashMap<String, Object>(vc.getAttributes());
|
||||
attributes.put(key, value);
|
||||
return new VariantContext(vc.getSource(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), vc.genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, attributes, vc.getReferenceBaseForIndel(), true, false);
|
||||
return new VariantContext(vc.getSource(), vc.getID(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), vc.genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, attributes, vc.getReferenceBaseForIndel(), true, false);
|
||||
}
|
||||
|
||||
public static VariantContext modifyReferencePadding(VariantContext vc, Byte b) {
|
||||
VariantContext modifiedVC = new VariantContext(vc.getSource(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), vc.genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, vc.getAttributes(), b, true, false);
|
||||
VariantContext modifiedVC = new VariantContext(vc.getSource(), vc.getID(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), vc.genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, vc.getAttributes(), b, true, false);
|
||||
modifiedVC.validateReferencePadding();
|
||||
return modifiedVC;
|
||||
}
|
||||
|
||||
public static VariantContext modifyPErrorFiltersAndAttributes(VariantContext vc, double negLog10PError, Set<String> filters, Map<String, Object> attributes) {
|
||||
return new VariantContext(vc.getSource(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), vc.genotypes, negLog10PError, filters, attributes, vc.getReferenceBaseForIndel(), true, false);
|
||||
return new VariantContext(vc.getSource(), vc.getID(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), vc.genotypes, negLog10PError, filters, attributes, vc.getReferenceBaseForIndel(), true, false);
|
||||
}
|
||||
|
||||
public static VariantContext modifyID(final VariantContext vc, final String id) {
|
||||
return modifyAttribute(vc, ID_KEY, id);
|
||||
return new VariantContext(vc.getSource(), id, vc.getChr(), vc.getStart(), vc.getEnd() , vc.getAlleles(), vc.genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, new HashMap<String, Object>(vc.getAttributes()), vc.getReferenceBaseForIndel(), true, false);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
|
|
@ -494,7 +539,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
// }
|
||||
|
||||
public VariantContext subContextFromSamples(Set<String> sampleNames, Collection<Allele> alleles) {
|
||||
return new VariantContext(getSource(), contig, start, stop, alleles,
|
||||
return new VariantContext(getSource(), getID(), contig, start, stop, alleles,
|
||||
genotypes.subsetToSamples(sampleNames),
|
||||
getNegLog10PError(),
|
||||
filtersWereApplied() ? getFilters() : null,
|
||||
|
|
@ -504,7 +549,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
|
||||
public VariantContext subContextFromSamples(Set<String> sampleNames) {
|
||||
GenotypeCollection newGenotypes = genotypes.subsetToSamples(sampleNames);
|
||||
return new VariantContext(getSource(), contig, start, stop, allelesOfGenotypes(newGenotypes),
|
||||
return new VariantContext(getSource(), getID(), contig, start, stop, allelesOfGenotypes(newGenotypes),
|
||||
newGenotypes,
|
||||
getNegLog10PError(),
|
||||
filtersWereApplied() ? getFilters() : null,
|
||||
|
|
@ -694,11 +739,15 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
// ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
public boolean hasID() {
|
||||
return commonInfo.hasAttribute(ID_KEY);
|
||||
return getID() != VCFConstants.EMPTY_ID_FIELD;
|
||||
}
|
||||
|
||||
public boolean emptyID() {
|
||||
return ! hasID();
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return (String)commonInfo.getAttribute(ID_KEY);
|
||||
return ID;
|
||||
}
|
||||
|
||||
public boolean hasReferenceBaseForIndel() {
|
||||
|
|
@ -1154,7 +1203,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
}
|
||||
|
||||
public void validateRSIDs(Set<String> rsIDs) {
|
||||
if ( rsIDs != null && hasAttribute(VariantContext.ID_KEY) ) {
|
||||
if ( rsIDs != null && hasID() ) {
|
||||
for ( String id : getID().split(VCFConstants.ID_FIELD_SEPARATOR) ) {
|
||||
if ( id.startsWith("rs") && !rsIDs.contains(id) )
|
||||
throw new TribbleException.InternalCodecException(String.format("the rsID %s for the record at position %s:%d is not in dbSNP", id, getChr(), getStart()));
|
||||
|
|
@ -1538,7 +1587,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
|
||||
// Do not change the filter state if filters were not applied to this context
|
||||
Set<String> inputVCFilters = inputVC.filtersWereAppliedToContext ? inputVC.getFilters() : null;
|
||||
return new VariantContext(inputVC.getSource(), inputVC.getChr(), inputVC.getStart(), inputVC.getEnd(), alleles, genotypes, inputVC.getNegLog10PError(), inputVCFilters, inputVC.getAttributes(),refByte);
|
||||
return new VariantContext(inputVC.getSource(), inputVC.getID(), inputVC.getChr(), inputVC.getStart(), inputVC.getEnd(), alleles, genotypes, inputVC.getNegLog10PError(), inputVCFilters, inputVC.getAttributes(),refByte);
|
||||
}
|
||||
else
|
||||
return inputVC;
|
||||
|
|
|
|||
|
|
@ -57,55 +57,6 @@ public class VariantContextUtils {
|
|||
engine.setLenient(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new VariantContext
|
||||
*
|
||||
* @param name name
|
||||
* @param loc location
|
||||
* @param alleles alleles
|
||||
* @param genotypes genotypes set
|
||||
* @param negLog10PError qual
|
||||
* @param filters filters: use null for unfiltered and empty set for passes filters
|
||||
* @param attributes attributes
|
||||
* @return VariantContext object
|
||||
*/
|
||||
public static VariantContext toVC(String name, GenomeLoc loc, Collection<Allele> alleles, Collection<Genotype> genotypes, double negLog10PError, Set<String> filters, Map<String, Object> attributes) {
|
||||
return new VariantContext(name, loc.getContig(), loc.getStart(), loc.getStop(), alleles, GenotypeCollection.copy(genotypes), negLog10PError, filters, attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new variant context without genotypes and no Perror, no filters, and no attributes
|
||||
* @param name name
|
||||
* @param loc location
|
||||
* @param alleles alleles
|
||||
* @return VariantContext object
|
||||
*/
|
||||
public static VariantContext toVC(String name, GenomeLoc loc, Collection<Allele> alleles) {
|
||||
return new VariantContext (name, loc.getContig(), loc.getStart(), loc.getStop(), alleles, VariantContext.NO_GENOTYPES, CommonInfo.NO_NEG_LOG_10PERROR, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new variant context without genotypes and no Perror, no filters, and no attributes
|
||||
* @param name name
|
||||
* @param loc location
|
||||
* @param alleles alleles
|
||||
* @param genotypes genotypes
|
||||
* @return VariantContext object
|
||||
*/
|
||||
public static VariantContext toVC(String name, GenomeLoc loc, Collection<Allele> alleles, Collection<Genotype> genotypes) {
|
||||
return new VariantContext(name, loc.getContig(), loc.getStart(), loc.getStop(), alleles, genotypes, CommonInfo.NO_NEG_LOG_10PERROR, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*
|
||||
* @param other the VariantContext to copy
|
||||
* @return VariantContext object
|
||||
*/
|
||||
public static VariantContext toVC(VariantContext other) {
|
||||
return new VariantContext(other.getSource(), other.getChr(), other.getStart(), other.getEnd(), other.getAlleles(), other.getGenotypes(), other.getNegLog10PError(), other.getFilters(), other.getAttributes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the attributes of the attributes map given the VariantContext to reflect the proper chromosome-based VCF tags
|
||||
*
|
||||
|
|
@ -345,19 +296,15 @@ public class VariantContextUtils {
|
|||
// VC info
|
||||
final Map<String, Object> attributes = subsetAttributes(vc.commonInfo, keysToPreserve);
|
||||
|
||||
// this must be done as the ID is stored in the attributes field
|
||||
// todo -- remove me when ID becomes a first class field in VC
|
||||
if ( vc.hasID() ) attributes.put(VariantContext.ID_KEY, vc.getID());
|
||||
|
||||
// Genotypes
|
||||
final GenotypeCollection genotypes = GenotypeCollection.create(vc.getNSamples());
|
||||
for ( final Genotype g : vc.getGenotypes() ) {
|
||||
Map<String, Object> genotypeAttributes = subsetAttributes(g.commonInfo, keysToPreserve);
|
||||
genotypes.add(new Genotype(g.getSampleName(), g.getAlleles(), g.getNegLog10PError(), g.getFilters(),
|
||||
genotypeAttributes, g.isPhased()));
|
||||
genotypeAttributes, g.isPhased()));
|
||||
}
|
||||
|
||||
return new VariantContext(vc.getSource(), vc.getChr(), vc.getStart(), vc.getEnd(),
|
||||
return new VariantContext(vc.getSource(), vc.getID(), vc.getChr(), vc.getStart(), vc.getEnd(),
|
||||
vc.getAlleles(), genotypes, vc.getNegLog10PError(), vc.getFilters(), attributes);
|
||||
}
|
||||
|
||||
|
|
@ -494,7 +441,7 @@ public class VariantContextUtils {
|
|||
//
|
||||
if (vc.hasAttribute(VCFConstants.DEPTH_KEY))
|
||||
depth += vc.getAttributeAsInt(VCFConstants.DEPTH_KEY, 0);
|
||||
if ( vc.hasID() && ! vc.getID().equals(VCFConstants.EMPTY_ID_FIELD) ) rsIDs.add(vc.getID());
|
||||
if ( vc.hasID() ) rsIDs.add(vc.getID());
|
||||
if (mergeInfoWithMaxAC && vc.hasAttribute(VCFConstants.ALLELE_COUNT_KEY)) {
|
||||
String rawAlleleCounts = vc.getAttributeAsString(VCFConstants.ALLELE_COUNT_KEY, null);
|
||||
// lets see if the string contains a , separator
|
||||
|
|
@ -587,11 +534,9 @@ public class VariantContextUtils {
|
|||
if ( depth > 0 )
|
||||
attributes.put(VCFConstants.DEPTH_KEY, String.valueOf(depth));
|
||||
|
||||
if ( ! rsIDs.isEmpty() ) {
|
||||
attributes.put(VariantContext.ID_KEY, Utils.join(",", rsIDs));
|
||||
}
|
||||
final String ID = rsIDs.isEmpty() ? VCFConstants.EMPTY_ID_FIELD : Utils.join(",", rsIDs);
|
||||
|
||||
VariantContext merged = new VariantContext(name, loc.getContig(), loc.getStart(), loc.getStop(), alleles, genotypes, negLog10PError, filters, (mergeInfoWithMaxAC ? attributesWithMaxAC : attributes) );
|
||||
VariantContext merged = new VariantContext(name, ID, loc.getContig(), loc.getStart(), loc.getStop(), alleles, genotypes, negLog10PError, filters, (mergeInfoWithMaxAC ? attributesWithMaxAC : attributes) );
|
||||
// Trim the padded bases of all alleles if necessary
|
||||
merged = createVariantContextWithTrimmedAlleles(merged);
|
||||
|
||||
|
|
@ -694,7 +639,7 @@ public class VariantContextUtils {
|
|||
genotypes.add(Genotype.modifyAlleles(genotype, trimmedAlleles));
|
||||
|
||||
}
|
||||
return new VariantContext(inputVC.getSource(), inputVC.getChr(), inputVC.getStart(), inputVC.getEnd(), alleles, genotypes, inputVC.getNegLog10PError(), inputVC.filtersWereApplied() ? inputVC.getFilters() : null, attributes, new Byte(inputVC.getReference().getBases()[0]));
|
||||
return new VariantContext(inputVC.getSource(), inputVC.getID(), inputVC.getChr(), inputVC.getStart(), inputVC.getEnd(), alleles, genotypes, inputVC.getNegLog10PError(), inputVC.filtersWereApplied() ? inputVC.getFilters() : null, attributes, new Byte(inputVC.getReference().getBases()[0]));
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -934,7 +879,7 @@ public class VariantContextUtils {
|
|||
newGenotypes.add(Genotype.modifyAlleles(genotype, newAlleles));
|
||||
}
|
||||
|
||||
return new VariantContext(vc.getSource(), vc.getChr(), vc.getStart(), vc.getEnd(), alleleMap.values(), newGenotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, vc.getAttributes());
|
||||
return new VariantContext(vc.getSource(), vc.getID(), vc.getChr(), vc.getStart(), vc.getEnd(), alleleMap.values(), newGenotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, vc.getAttributes());
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1058,7 +1003,14 @@ public class VariantContextUtils {
|
|||
Set<String> mergedFilters = new HashSet<String>(); // Since vc1 and vc2 were unfiltered, the merged record remains unfiltered
|
||||
Map<String, Object> mergedAttribs = VariantContextUtils.mergeVariantContextAttributes(vc1, vc2);
|
||||
|
||||
VariantContext mergedVc = new VariantContext(mergedName, vc1.getChr(), vc1.getStart(), vc2.getEnd(), mergeData.getAllMergedAlleles(), mergedGenotypes, mergedNegLog10PError, mergedFilters, mergedAttribs);
|
||||
// ids
|
||||
List<String> mergedIDs = new ArrayList<String>();
|
||||
if ( vc1.hasID() ) mergedIDs.add(vc1.getID());
|
||||
if ( vc2.hasID() ) mergedIDs.add(vc2.getID());
|
||||
String mergedID = Utils.join(VCFConstants.ID_FIELD_SEPARATOR, mergedIDs);
|
||||
|
||||
// TODO -- FIX ID
|
||||
VariantContext mergedVc = new VariantContext(mergedName, mergedID, vc1.getChr(), vc1.getStart(), vc2.getEnd(), mergeData.getAllMergedAlleles(), mergedGenotypes, mergedNegLog10PError, mergedFilters, mergedAttribs);
|
||||
|
||||
mergedAttribs = new HashMap<String, Object>(mergedVc.getAttributes());
|
||||
VariantContextUtils.calculateChromosomeCounts(mergedVc, mergedAttribs, true);
|
||||
|
|
@ -1154,20 +1106,6 @@ public class VariantContextUtils {
|
|||
mergedAttribs.put(orAttrib, attribVal);
|
||||
}
|
||||
|
||||
// Merge ID fields:
|
||||
String iDVal = null;
|
||||
for (VariantContext vc : vcList) {
|
||||
String val = vc.getAttributeAsString(VariantContext.ID_KEY, null);
|
||||
if (val != null && !val.equals(VCFConstants.EMPTY_ID_FIELD)) {
|
||||
if (iDVal == null)
|
||||
iDVal = val;
|
||||
else
|
||||
iDVal += VCFConstants.ID_FIELD_SEPARATOR + val;
|
||||
}
|
||||
}
|
||||
if (iDVal != null)
|
||||
mergedAttribs.put(VariantContext.ID_KEY, iDVal);
|
||||
|
||||
return mergedAttribs;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature;
|
|||
import org.broadinstitute.sting.gatk.refdata.utils.RODRecordList;
|
||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||
import org.broadinstitute.sting.utils.GenomeLocParser;
|
||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFConstants;
|
||||
import org.broadinstitute.sting.utils.sam.ArtificialSAMUtils;
|
||||
import org.broadinstitute.sting.utils.variantcontext.Allele;
|
||||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||
|
|
@ -65,9 +66,9 @@ public class RefMetaDataTrackerUnitTest {
|
|||
C = Allele.create("C");
|
||||
G = Allele.create("G");
|
||||
T = Allele.create("T");
|
||||
AC_SNP = new VariantContext("x", "chr1", START_POS, START_POS, Arrays.asList(A, C));
|
||||
AG_SNP = new VariantContext("x", "chr1", START_POS, START_POS, Arrays.asList(A, G));
|
||||
AT_SNP = new VariantContext("x", "chr1", START_POS, START_POS, Arrays.asList(A, T));
|
||||
AC_SNP = new VariantContext("x", VCFConstants.EMPTY_ID_FIELD, "chr1", START_POS, START_POS, Arrays.asList(A, C));
|
||||
AG_SNP = new VariantContext("x", VCFConstants.EMPTY_ID_FIELD, "chr1", START_POS, START_POS, Arrays.asList(A, G));
|
||||
AT_SNP = new VariantContext("x", VCFConstants.EMPTY_ID_FIELD, "chr1", START_POS, START_POS, Arrays.asList(A, T));
|
||||
span10_10 = makeSpan(10, 10);
|
||||
span1_20 = makeSpan(1, 20);
|
||||
span10_20 = makeSpan(10, 20);
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ public class VCFWriterUnitTest extends BaseTest {
|
|||
genotypes.add(gt);
|
||||
|
||||
}
|
||||
return new VariantContext("RANDOM",loc.getContig(), loc.getStart(), loc.getStop(), alleles, genotypes, 0, filters, attributes, (byte)'A');
|
||||
return new VariantContext("RANDOM", VCFConstants.EMPTY_ID_FIELD, loc.getContig(), loc.getStart(), loc.getStop(), alleles, genotypes, 0, filters, attributes, (byte)'A');
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package org.broadinstitute.sting.utils.variantcontext;
|
|||
|
||||
|
||||
import org.broadinstitute.sting.BaseTest;
|
||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFConstants;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
|
@ -67,68 +68,68 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
|
||||
// test REF
|
||||
List<Allele> alleles = Arrays.asList(Tref);
|
||||
VariantContext vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles);
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles);
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.NO_VARIATION);
|
||||
|
||||
// test SNPs
|
||||
alleles = Arrays.asList(Tref, A);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles);
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles);
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.SNP);
|
||||
|
||||
alleles = Arrays.asList(Tref, A, C);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles);
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles);
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.SNP);
|
||||
|
||||
// test MNPs
|
||||
alleles = Arrays.asList(ACref, TA);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop+1, alleles);
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+1, alleles);
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.MNP);
|
||||
|
||||
alleles = Arrays.asList(ATCref, CAT, Allele.create("GGG"));
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop+2, alleles);
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+2, alleles);
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.MNP);
|
||||
|
||||
// test INDELs
|
||||
alleles = Arrays.asList(Aref, ATC);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.INDEL);
|
||||
|
||||
alleles = Arrays.asList(ATCref, A);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop+2, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+2, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.INDEL);
|
||||
|
||||
alleles = Arrays.asList(Tref, TA, TC);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.INDEL);
|
||||
|
||||
alleles = Arrays.asList(ATCref, A, AC);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop+2, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+2, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.INDEL);
|
||||
|
||||
alleles = Arrays.asList(ATCref, A, Allele.create("ATCTC"));
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop+2, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+2, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.INDEL);
|
||||
|
||||
// test MIXED
|
||||
alleles = Arrays.asList(TAref, T, TC);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop+1, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+1, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.MIXED);
|
||||
|
||||
alleles = Arrays.asList(TAref, T, AC);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop+1, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+1, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.MIXED);
|
||||
|
||||
alleles = Arrays.asList(ACref, ATC, AT);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop+1, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+1, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.MIXED);
|
||||
|
||||
alleles = Arrays.asList(Aref, T, symbolic);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.MIXED);
|
||||
|
||||
// test SYMBOLIC
|
||||
alleles = Arrays.asList(Tref, symbolic);
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
Assert.assertEquals(vc.getType(), VariantContext.Type.SYMBOLIC);
|
||||
}
|
||||
|
||||
|
|
@ -136,8 +137,8 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
public void testMultipleSNPAlleleOrdering() {
|
||||
final List<Allele> allelesNaturalOrder = Arrays.asList(Aref, C, T);
|
||||
final List<Allele> allelesUnnaturalOrder = Arrays.asList(Aref, T, C);
|
||||
VariantContext naturalVC = new VariantContext("natural", snpLoc, snpLocStart, snpLocStop, allelesNaturalOrder);
|
||||
VariantContext unnaturalVC = new VariantContext("unnatural", snpLoc, snpLocStart, snpLocStop, allelesUnnaturalOrder);
|
||||
VariantContext naturalVC = new VariantContext("natural", VCFConstants.EMPTY_ID_FIELD, snpLoc, snpLocStart, snpLocStop, allelesNaturalOrder);
|
||||
VariantContext unnaturalVC = new VariantContext("unnatural", VCFConstants.EMPTY_ID_FIELD, snpLoc, snpLocStart, snpLocStop, allelesUnnaturalOrder);
|
||||
Assert.assertEquals(new ArrayList<Allele>(naturalVC.getAlleles()), allelesNaturalOrder);
|
||||
Assert.assertEquals(new ArrayList<Allele>(unnaturalVC.getAlleles()), allelesUnnaturalOrder);
|
||||
}
|
||||
|
|
@ -146,7 +147,7 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
public void testCreatingSNPVariantContext() {
|
||||
|
||||
List<Allele> alleles = Arrays.asList(Aref, T);
|
||||
VariantContext vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles);
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles);
|
||||
|
||||
Assert.assertEquals(vc.getChr(), snpLoc);
|
||||
Assert.assertEquals(vc.getStart(), snpLocStart);
|
||||
|
|
@ -173,7 +174,7 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
@Test
|
||||
public void testCreatingRefVariantContext() {
|
||||
List<Allele> alleles = Arrays.asList(Aref);
|
||||
VariantContext vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles);
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles);
|
||||
|
||||
Assert.assertEquals(vc.getChr(), snpLoc);
|
||||
Assert.assertEquals(vc.getStart(), snpLocStart);
|
||||
|
|
@ -199,7 +200,7 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
@Test
|
||||
public void testCreatingDeletionVariantContext() {
|
||||
List<Allele> alleles = Arrays.asList(ATCref, del);
|
||||
VariantContext vc = new VariantContext("test", delLoc, delLocStart, delLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, delLoc, delLocStart, delLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
|
||||
Assert.assertEquals(vc.getChr(), delLoc);
|
||||
Assert.assertEquals(vc.getStart(), delLocStart);
|
||||
|
|
@ -226,7 +227,7 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
@Test
|
||||
public void testCreatingInsertionVariantContext() {
|
||||
List<Allele> alleles = Arrays.asList(delRef, ATC);
|
||||
VariantContext vc = new VariantContext("test", insLoc, insLocStart, insLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
|
||||
Assert.assertEquals(vc.getChr(), insLoc);
|
||||
Assert.assertEquals(vc.getStart(), insLocStart);
|
||||
|
|
@ -253,7 +254,7 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
public void testCreatingPartiallyCalledGenotype() {
|
||||
List<Allele> alleles = Arrays.asList(Aref, C);
|
||||
Genotype g = new Genotype("foo", Arrays.asList(C, Allele.NO_CALL), 10);
|
||||
VariantContext vc = new VariantContext("test", snpLoc, snpLocStart, snpLocStop, alleles, Arrays.asList(g));
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc, snpLocStart, snpLocStop, alleles, Arrays.asList(g));
|
||||
|
||||
Assert.assertTrue(vc.isSNP());
|
||||
Assert.assertEquals(vc.getNAlleles(), 2);
|
||||
|
|
@ -274,38 +275,38 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
|
||||
@Test (expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadConstructorArgs1() {
|
||||
new VariantContext("test", insLoc, insLocStart, insLocStop, Arrays.asList(delRef, ATCref));
|
||||
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Arrays.asList(delRef, ATCref));
|
||||
}
|
||||
|
||||
@Test (expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadConstructorArgs2() {
|
||||
new VariantContext("test", insLoc, insLocStart, insLocStop, Arrays.asList(delRef, del));
|
||||
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Arrays.asList(delRef, del));
|
||||
}
|
||||
|
||||
@Test (expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadConstructorArgs3() {
|
||||
new VariantContext("test", insLoc, insLocStart, insLocStop, Arrays.asList(del));
|
||||
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Arrays.asList(del));
|
||||
}
|
||||
|
||||
@Test (expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadConstructorArgs4() {
|
||||
new VariantContext("test", insLoc, insLocStart, insLocStop, Collections.<Allele>emptyList());
|
||||
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Collections.<Allele>emptyList());
|
||||
}
|
||||
|
||||
@Test (expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadConstructorArgsDuplicateAlleles1() {
|
||||
new VariantContext("test", insLoc, insLocStart, insLocStop, Arrays.asList(Aref, T, T));
|
||||
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Arrays.asList(Aref, T, T));
|
||||
}
|
||||
|
||||
@Test (expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadConstructorArgsDuplicateAlleles2() {
|
||||
new VariantContext("test", insLoc, insLocStart, insLocStop, Arrays.asList(Aref, A));
|
||||
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Arrays.asList(Aref, A));
|
||||
}
|
||||
|
||||
@Test (expectedExceptions = IllegalStateException.class)
|
||||
public void testBadLoc1() {
|
||||
List<Allele> alleles = Arrays.asList(Aref, T, del);
|
||||
new VariantContext("test", delLoc, delLocStart, delLocStop, alleles);
|
||||
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, delLoc, delLocStart, delLocStop, alleles);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -316,7 +317,7 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
Genotype g2 = new Genotype("AT", Arrays.asList(Aref, T), 10);
|
||||
Genotype g3 = new Genotype("TT", Arrays.asList(T, T), 10);
|
||||
|
||||
VariantContext vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1, g2, g3));
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1, g2, g3));
|
||||
|
||||
Assert.assertTrue(vc.hasGenotypes());
|
||||
Assert.assertFalse(vc.isMonomorphic());
|
||||
|
|
@ -355,7 +356,7 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
Genotype g5 = new Genotype("dd", Arrays.asList(del, del), 10);
|
||||
Genotype g6 = new Genotype("..", Arrays.asList(Allele.NO_CALL, Allele.NO_CALL), 10);
|
||||
|
||||
VariantContext vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1, g2, g3, g4, g5, g6));
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1, g2, g3, g4, g5, g6));
|
||||
|
||||
Assert.assertTrue(vc.hasGenotypes());
|
||||
Assert.assertFalse(vc.isMonomorphic());
|
||||
|
|
@ -380,7 +381,7 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
Genotype g1 = new Genotype("AA1", Arrays.asList(Aref, Aref), 10);
|
||||
Genotype g2 = new Genotype("AA2", Arrays.asList(Aref, Aref), 10);
|
||||
Genotype g3 = new Genotype("..", Arrays.asList(Allele.NO_CALL, Allele.NO_CALL), 10);
|
||||
VariantContext vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1, g2, g3));
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1, g2, g3));
|
||||
|
||||
Assert.assertTrue(vc.hasGenotypes());
|
||||
Assert.assertTrue(vc.isMonomorphic());
|
||||
|
|
@ -400,21 +401,21 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
Genotype g1 = new Genotype("AA", Arrays.asList(Aref, Aref), 10);
|
||||
Genotype g2 = new Genotype("AT", Arrays.asList(Aref, T), 10);
|
||||
|
||||
VariantContext vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1,g2));
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1,g2));
|
||||
|
||||
Assert.assertTrue(vc.isNotFiltered());
|
||||
Assert.assertFalse(vc.isFiltered());
|
||||
Assert.assertEquals(0, vc.getFilters().size());
|
||||
|
||||
Set<String> filters = new HashSet<String>(Arrays.asList("BAD_SNP_BAD!"));
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1,g2), VariantContext.NO_NEG_LOG_10PERROR, filters, null);
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1,g2), VariantContext.NO_NEG_LOG_10PERROR, filters, null);
|
||||
|
||||
Assert.assertFalse(vc.isNotFiltered());
|
||||
Assert.assertTrue(vc.isFiltered());
|
||||
Assert.assertEquals(1, vc.getFilters().size());
|
||||
|
||||
filters = new HashSet<String>(Arrays.asList("BAD_SNP_BAD!", "REALLY_BAD_SNP", "CHRIST_THIS_IS_TERRIBLE"));
|
||||
vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1,g2), VariantContext.NO_NEG_LOG_10PERROR, filters, null);
|
||||
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, Arrays.asList(g1,g2), VariantContext.NO_NEG_LOG_10PERROR, filters, null);
|
||||
|
||||
Assert.assertFalse(vc.isNotFiltered());
|
||||
Assert.assertTrue(vc.isFiltered());
|
||||
|
|
@ -429,9 +430,9 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
Genotype g3 = new Genotype("TT", Arrays.asList(T, T), 10);
|
||||
Genotype g4 = new Genotype("..", Arrays.asList(Allele.NO_CALL, Allele.NO_CALL), 10);
|
||||
Genotype g5 = new Genotype("--", Arrays.asList(del, del), 10);
|
||||
VariantContext vc = new VariantContext("test", snpLoc,snpLocStart, snpLocStop , alleles, Arrays.asList(g1,g2,g3,g4,g5));
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop , alleles, Arrays.asList(g1,g2,g3,g4,g5));
|
||||
|
||||
VariantContext vc12 = vc.subContextFromSamples(new HashSet<String>(Arrays.asList(g1.getSampleName(),g2.getSampleName())));
|
||||
VariantContext vc12 = vc.subContextFromSamples(new HashSet<String>(Arrays.asList(g1.getSampleName(), g2.getSampleName())));
|
||||
VariantContext vc1 = vc.subContextFromSamples(new HashSet<String>(Arrays.asList(g1.getSampleName())));
|
||||
VariantContext vc23 = vc.subContextFromSamples(new HashSet<String>(Arrays.asList(g2.getSampleName(), g3.getSampleName())));
|
||||
VariantContext vc4 = vc.subContextFromSamples(new HashSet<String>(Arrays.asList(g4.getSampleName())));
|
||||
|
|
@ -514,7 +515,7 @@ public class VariantContextUnitTest extends BaseTest {
|
|||
@Test(dataProvider = "getAlleles")
|
||||
public void testMergeAlleles(GetAllelesTest cfg) {
|
||||
final List<Allele> altAlleles = cfg.alleles.subList(1, cfg.alleles.size());
|
||||
final VariantContext vc = new VariantContext("test", snpLoc, snpLocStart, snpLocStop, cfg.alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
final VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc, snpLocStart, snpLocStop, cfg.alleles, null, CommonInfo.NO_NEG_LOG_10PERROR, null, null, (byte)'A');
|
||||
|
||||
Assert.assertEquals(vc.getAlleles(), cfg.alleles, "VC alleles not the same as input alleles");
|
||||
Assert.assertEquals(vc.getNAlleles(), cfg.alleles.size(), "VC getNAlleles not the same as input alleles size");
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ package org.broadinstitute.sting.utils.variantcontext;
|
|||
import net.sf.picard.reference.IndexedFastaSequenceFile;
|
||||
import org.broadinstitute.sting.BaseTest;
|
||||
import org.broadinstitute.sting.utils.GenomeLocParser;
|
||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFConstants;
|
||||
import org.broadinstitute.sting.utils.exceptions.UserException;
|
||||
import org.broadinstitute.sting.utils.fasta.CachingIndexedFastaSequenceFile;
|
||||
import org.testng.Assert;
|
||||
|
|
@ -98,7 +99,7 @@ public class VariantContextUtilsUnitTest extends BaseTest {
|
|||
private VariantContext makeVC(String source, List<Allele> alleles, Collection<Genotype> genotypes, Set<String> filters) {
|
||||
int start = 10;
|
||||
int stop = start; // alleles.contains(ATC) ? start + 3 : start;
|
||||
return new VariantContext(source, "1", start, stop, alleles,
|
||||
return new VariantContext(source, VCFConstants.EMPTY_ID_FIELD, "1", start, stop, alleles,
|
||||
GenotypeCollection.copy(genotypes), 1.0, filters, null, Cref.getBases()[0]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
package org.broadinstitute.sting.utils.variantcontext;
|
||||
|
||||
import net.sf.samtools.SAMFileHeader;
|
||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFConstants;
|
||||
import org.testng.Assert;
|
||||
import org.broadinstitute.sting.BaseTest;
|
||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||
|
|
@ -143,7 +144,7 @@ public class VariantJEXLContextUnitTest extends BaseTest {
|
|||
private JEXLMap getVarContext() {
|
||||
List<Allele> alleles = Arrays.asList(Aref, T);
|
||||
|
||||
VariantContext vc = new VariantContext("test", snpLoc.getContig(), snpLoc.getStart(), snpLoc.getStop(), alleles);
|
||||
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc.getContig(), snpLoc.getStart(), snpLoc.getStop(), alleles);
|
||||
return new JEXLMap(Arrays.asList(exp),vc);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue