Added subContextOfSamples to VariantContext
-- This is a more convenient accesssor than subContextOfGenotypes, represents nearly all of the use cases of the former function, and potentially can be implemented more efficiently.
This commit is contained in:
parent
e216e85465
commit
ef9f8b5d46
|
|
@ -277,7 +277,7 @@ public class VariantEvalUtils {
|
|||
* @return a new VariantContext with just the requested samples
|
||||
*/
|
||||
public VariantContext getSubsetOfVariantContext(VariantContext vc, Collection<String> sampleNames) {
|
||||
VariantContext vcsub = vc.subContextFromGenotypes(vc.getGenotypes(sampleNames).values(), vc.getAlleles());
|
||||
VariantContext vcsub = vc.subContextFromSamples(sampleNames, vc.getAlleles());
|
||||
|
||||
HashMap<String, Object> newAts = new HashMap<String, Object>(vcsub.getAttributes());
|
||||
|
||||
|
|
|
|||
|
|
@ -659,13 +659,7 @@ public class SelectVariants extends RodWalker<Integer, Integer> {
|
|||
if ( samples == null || samples.isEmpty() )
|
||||
return vc;
|
||||
|
||||
ArrayList<Genotype> genotypes = new ArrayList<Genotype>();
|
||||
for ( Map.Entry<String, Genotype> genotypePair : vc.getGenotypes().entrySet() ) {
|
||||
if ( samples.contains(genotypePair.getKey()) )
|
||||
genotypes.add(genotypePair.getValue());
|
||||
}
|
||||
|
||||
VariantContext sub = vc.subContextFromGenotypes(genotypes, vc.getAlleles());
|
||||
VariantContext sub = vc.subContextFromSamples(samples);
|
||||
|
||||
// if we have fewer alternate alleles in the selected VC than in the original VC, we need to strip out the GL/PLs (because they are no longer accurate)
|
||||
if ( vc.getAlleles().size() != sub.getAlleles().size() )
|
||||
|
|
|
|||
|
|
@ -446,9 +446,25 @@ public class VariantContext implements Feature { // to enable tribble intergrati
|
|||
* @return vc subcontext
|
||||
*/
|
||||
public VariantContext subContextFromGenotypes(Collection<Genotype> genotypes, Collection<Allele> alleles) {
|
||||
return new VariantContext(getSource(), contig, start, stop, alleles, genotypes != null ? genotypeCollectionToMap(new TreeMap<String, Genotype>(), genotypes) : null, getNegLog10PError(), filtersWereApplied() ? getFilters() : null, getAttributes(), getReferenceBaseForIndel());
|
||||
return new VariantContext(getSource(), contig, start, stop, alleles,
|
||||
genotypes != null ? genotypeCollectionToMap(new TreeMap<String, Genotype>(), genotypes) : null,
|
||||
getNegLog10PError(),
|
||||
filtersWereApplied() ? getFilters() : null,
|
||||
getAttributes(),
|
||||
getReferenceBaseForIndel());
|
||||
}
|
||||
|
||||
public VariantContext subContextFromSamples(Collection<String> sampleNames, Collection<Allele> alleles) {
|
||||
return subContextFromGenotypes(getGenotypes(sampleNames).values(), alleles);
|
||||
}
|
||||
|
||||
public VariantContext subContextFromSamples(Collection<String> sampleNames) {
|
||||
return subContextFromGenotypes(getGenotypes(sampleNames).values());
|
||||
}
|
||||
|
||||
public VariantContext subContextFromSample(String sampleName) {
|
||||
return subContextFromGenotypes(getGenotype(sampleName));
|
||||
}
|
||||
|
||||
/**
|
||||
* helper routine for subcontext
|
||||
|
|
|
|||
Loading…
Reference in New Issue