/** * Create a GenotypesContext containing the genotypes in iteration order contained * in toCopy * * @param toCopy the collection of genotypes * @return an mutable GenotypeContext containing genotypes */ public static final GenotypesContext copy(final Collection<Genotype> toCopy) { return toCopy == null ? NO_GENOTYPES : create(new ArrayList<Genotype>(toCopy)); }
/** * Create a GenotypesContext containing the genotypes in iteration order contained * in toCopy * * @param toCopy the collection of genotypes * @return an mutable GenotypeContext containing genotypes */ public static final GenotypesContext copy(final Collection<Genotype> toCopy) { return toCopy == null ? NO_GENOTYPES : create(new ArrayList<Genotype>(toCopy)); }
/** * Create a fully resolved GenotypeContext containing genotypes * * @param genotypes our genotypes in arbitrary * @return an mutable GenotypeContext containing genotypes */ public static final GenotypesContext create(final Genotype... genotypes) { return create(new ArrayList<Genotype>(Arrays.asList(genotypes))); }
/** * Create a fully resolved GenotypeContext containing genotypes * * @param genotypes our genotypes in arbitrary * @return an mutable GenotypeContext containing genotypes */ public static final GenotypesContext create(final Genotype... genotypes) { return create(new ArrayList<Genotype>(Arrays.asList(genotypes))); }
private GetGLsTest(String name, int numAltAlleles, int ploidy, Genotype... arg) { super(GetGLsTest.class, name); GLs = GenotypesContext.create(arg); this.name = name; this.numAltAlleles = numAltAlleles; this.ploidy = ploidy; }
/** * Create a freshly allocated GenotypeContext containing the genotypes in toCopy * * @param toCopy the GenotypesContext to copy * @return an mutable GenotypeContext containing genotypes */ public static final GenotypesContext copy(final GenotypesContext toCopy) { return create(new ArrayList<Genotype>(toCopy.getGenotypes())); }
/** * Create a GenotypesContext containing the genotypes in iteration order contained * in toCopy * * @param toCopy the collection of genotypes * @return an mutable GenotypeContext containing genotypes */ @Ensures({"result != null"}) public static final GenotypesContext copy(final Collection<Genotype> toCopy) { return toCopy == null ? NO_GENOTYPES : create(new ArrayList<Genotype>(toCopy)); }
/** * Create a freshly allocated GenotypeContext containing the genotypes in toCopy * * @param toCopy the GenotypesContext to copy * @return an mutable GenotypeContext containing genotypes */ public static final GenotypesContext copy(final GenotypesContext toCopy) { return create(new ArrayList<Genotype>(toCopy.getGenotypes())); }
/** * Create a fully resolved GenotypeContext containing genotypes * * @param genotypes our genotypes in arbitrary * @return an mutable GenotypeContext containing genotypes */ @Requires({"genotypes != null"}) @Ensures({"result != null"}) public static final GenotypesContext create(final Genotype... genotypes) { return create(new ArrayList<Genotype>(Arrays.asList(genotypes))); }
/** * Create a freshly allocated GenotypeContext containing the genotypes in toCopy * * @param toCopy the GenotypesContext to copy * @return an mutable GenotypeContext containing genotypes */ @Requires({"toCopy != null"}) @Ensures({"result != null"}) public static final GenotypesContext copy(final GenotypesContext toCopy) { return create(new ArrayList<Genotype>(toCopy.getGenotypes())); }
public static GenotypesContext stripPLsAndAD(final GenotypesContext genotypes) { final GenotypesContext newGs = GenotypesContext.create(genotypes.size()); for ( final Genotype g : genotypes ) { newGs.add(removePLsAndAD(g)); } return newGs; }
public static VariantContext purgeUnallowedGenotypeAttributes(VariantContext vc, Set<String> allowedAttributes) { if ( allowedAttributes == null ) return vc; final GenotypesContext newGenotypes = GenotypesContext.create(vc.getNSamples()); for ( final Genotype genotype : vc.getGenotypes() ) { final Map<String, Object> attrs = new HashMap<>(); for ( final Map.Entry<String, Object> attr : genotype.getExtendedAttributes().entrySet() ) { if ( allowedAttributes.contains(attr.getKey()) ) attrs.put(attr.getKey(), attr.getValue()); } newGenotypes.add(new GenotypeBuilder(genotype).attributes(attrs).make()); } return new VariantContextBuilder(vc).genotypes(newGenotypes).make(); }
private static GenotypesContext createGenotypesContext(final int numGenotypes, final List<Allele> alleles) { Utils.resetRandomGenerator(); final Random random = Utils.getRandomGenerator(); final GenotypesContext gc = GenotypesContext.create(); for ( int i = 0; i < numGenotypes; i++ ) { // choose alleles at random final List<Allele> myAlleles = new ArrayList<Allele>(); myAlleles.add(alleles.get(random.nextInt(2))); myAlleles.add(alleles.get(random.nextInt(2))); final Genotype g = new GenotypeBuilder(String.format("%d", i)).alleles(myAlleles).make(); gc.add(g); } return gc; }
@Test public void testMonomorphicVariant() { Genotype g1 = GenotypeBuilder.create("AA", Arrays.asList(Aref, Aref)); Genotype g2 = GenotypeBuilder.create("BB", Arrays.asList(Aref, Allele.NO_CALL)); Genotype g3 = GenotypeBuilder.create("CC", Arrays.asList(Allele.NO_CALL,Allele.NO_CALL)); GenotypesContext gc = GenotypesContext.create(g1, g2, g3); VariantContext vc = new VariantContextBuilder("genotypes", snpLoc, snpLocStart, snpLocStop, Collections.singletonList(Aref)).genotypes(gc).make(); Assert.assertEquals(vc.getType(), VariantContext.Type.NO_VARIATION); Assert.assertNull(vc.getAltAlleleWithHighestAlleleCount()); Assert.assertEquals(vc.getCalledChrCount(Aref), 3); }
@Test(dataProvider = "SampleNamesTest") public void runSampleNamesTest(SampleNamesTest cfg) { GenotypesContext gc = GenotypesContext.create(cfg.sampleNames.size()); for ( final String name : cfg.sampleNames ) { gc.add(GenotypeBuilder.create(name, Arrays.asList(Aref, T))); } VariantContext vc = new VariantContextBuilder("genotypes", snpLoc, snpLocStart, snpLocStop, Arrays.asList(Aref, T)).genotypes(gc).make(); // same sample names => success Assert.assertTrue(vc.getSampleNames().equals(new HashSet<>(cfg.sampleNames)), "vc.getSampleNames() = " + vc.getSampleNames()); Assert.assertEquals(vc.getSampleNamesOrderedByName(), cfg.sampleNamesInOrder, "vc.getSampleNamesOrderedByName() = " + vc.getSampleNamesOrderedByName()); assertGenotypesAreInOrder(vc.getGenotypesOrderedByName(), cfg.sampleNamesInOrder); assertGenotypesAreInOrder(vc.getGenotypesOrderedBy(cfg.sampleNames), cfg.sampleNames); }
@Requires("originalGenotypes != null && alleleMapper != null") protected static GenotypesContext updateGenotypesWithMappedAlleles(final GenotypesContext originalGenotypes, final AlleleMapper alleleMapper) { final GenotypesContext updatedGenotypes = GenotypesContext.create(originalGenotypes.size()); for ( final Genotype genotype : originalGenotypes ) { final List<Allele> updatedAlleles = alleleMapper.remap(genotype.getAlleles()); updatedGenotypes.add(new GenotypeBuilder(genotype).alleles(updatedAlleles).make()); } return updatedGenotypes; }
private VariantContext createVCGeneral(final VCFHeader header, final String chrom, final int position) { final List<Allele> alleles = new ArrayList<Allele>(); final Map<String, Object> attributes = new HashMap<String,Object>(); final GenotypesContext genotypes = GenotypesContext.create(header.getGenotypeSamples().size()); alleles.add(Allele.create("A",true)); alleles.add(Allele.create("ACC",false)); attributes.put("DP","50"); for (final String name : header.getGenotypeSamples()) { final Genotype gt = new GenotypeBuilder(name,alleles.subList(1,2)).GQ(0).attribute("BB", "1").phased(true).make(); genotypes.add(gt); } return new VariantContextBuilder("RANDOM", chrom, position, position, alleles) .genotypes(genotypes).attributes(attributes).make(); }
public static VariantContextBuilder pruneVariantContext(final VariantContextBuilder builder, Collection<String> keysToPreserve ) { final VariantContext vc = builder.make(); if ( keysToPreserve == null ) keysToPreserve = Collections.emptyList(); // VC info final Map<String, Object> attributes = subsetAttributes(vc.getCommonInfo(), keysToPreserve); // Genotypes final GenotypesContext genotypes = GenotypesContext.create(vc.getNSamples()); for ( final Genotype g : vc.getGenotypes() ) { final GenotypeBuilder gb = new GenotypeBuilder(g); // remove AD, DP, PL, and all extended attributes, keeping just GT and GQ gb.noAD().noDP().noPL().noAttributes(); genotypes.add(gb.make()); } return builder.genotypes(genotypes).attributes(attributes); }
public void run(final VariantContext vc) { List<VariantContext> toMerge = new ArrayList<>(); for ( int i = 0; i < dupsToMerge; i++ ) { GenotypesContext gc = GenotypesContext.create(vc.getNSamples()); for ( final Genotype g : vc.getGenotypes() ) { gc.add(new GenotypeBuilder(g).name(g.getSampleName()+"_"+i).make()); } toMerge.add(new VariantContextBuilder(vc).genotypes(gc).make()); } GATKVariantContextUtils.simpleMerge(toMerge, null, GATKVariantContextUtils.FilteredRecordMergeType.KEEP_IF_ANY_UNFILTERED, GATKVariantContextUtils.GenotypeMergeType.UNSORTED, true, false, "set", false, true); } };
/** * For a particular event described in inputVC, form PL vector for each sample by looking into allele read map and filling likelihood matrix for each allele * @param readLikelihoods Allele map describing mapping from reads to alleles and corresponding likelihoods * @return GenotypesContext object wrapping genotype objects with PLs */ @Requires({"readLikelihoods!= null", "mergedVC != null"}) @Ensures("result != null") private GenotypesContext calculateGLsForThisEvent(final ReadLikelihoods<Allele> readLikelihoods, final List<Allele> noCallAlleles) { final GenotypingLikelihoods<Allele> likelihoods = genotypingModel.calculateLikelihoods(readLikelihoods, new GenotypingData<>(ploidyModel, readLikelihoods)); final int sampleCount = samples.sampleCount(); final GenotypesContext result = GenotypesContext.create(sampleCount); for (int s = 0; s < sampleCount; s++) result.add(new GenotypeBuilder(samples.sampleAt(s)).alleles(noCallAlleles).PL(likelihoods.sampleLikelihoods(s).getAsPLs()).make()); return result; }