One more quick memory improvement: reuse Alleles in a given context instead of creating new ones for each sample (duh).
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3147 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
c2a37e4b5c
commit
0cc6d0fbbb
|
|
@ -386,47 +386,54 @@ public class VariantContextAdaptors {
|
||||||
VariantContext convert(String name, Object input, Allele refAllele) {
|
VariantContext convert(String name, Object input, Allele refAllele) {
|
||||||
PlinkRod plink = (PlinkRod)input;
|
PlinkRod plink = (PlinkRod)input;
|
||||||
|
|
||||||
HashSet<Allele> alleles = new HashSet<Allele>();
|
HashSet<Allele> VCAlleles = new HashSet<Allele>();
|
||||||
alleles.add(refAllele);
|
VCAlleles.add(refAllele);
|
||||||
|
|
||||||
|
// mapping from Plink Allele to VC Allele (since the PlinkRod does not annotate any of the Alleles as reference)
|
||||||
|
HashMap<Allele, Allele> plinkAlleleToVCAllele = new HashMap<Allele, Allele>();
|
||||||
|
|
||||||
Set<Genotype> genotypes = new HashSet<Genotype>();
|
Set<Genotype> genotypes = new HashSet<Genotype>();
|
||||||
|
|
||||||
Map<String, Allele[]> genotypeSets = plink.getGenotypes();
|
Map<String, Allele[]> genotypeSets = plink.getGenotypes();
|
||||||
|
|
||||||
// We need to iterate through this list and recreate the Alleles since the
|
// We need to iterate through this list and recreate the Alleles since the
|
||||||
// PlinkRod does not promise to annotate any of the Alleles as reference
|
// PlinkRod does not annotate any of the Alleles as reference.
|
||||||
// for each sample...
|
// for each sample...
|
||||||
for ( Map.Entry<String, Allele[]> genotype : genotypeSets.entrySet() ) {
|
for ( Map.Entry<String, Allele[]> genotype : genotypeSets.entrySet() ) {
|
||||||
ArrayList<Allele> myAlleles = new ArrayList<Allele>(2);
|
ArrayList<Allele> myVCAlleles = new ArrayList<Allele>(2);
|
||||||
|
|
||||||
// for each allele...
|
// for each allele...
|
||||||
for ( Allele myAllele : genotype.getValue() ) {
|
for ( Allele myPlinkAllele : genotype.getValue() ) {
|
||||||
Allele allele;
|
Allele VCAllele;
|
||||||
if ( myAllele.isNoCall() ) {
|
if ( myPlinkAllele.isNoCall() ) {
|
||||||
allele = Allele.NO_CALL;
|
VCAllele = Allele.NO_CALL;
|
||||||
} else {
|
} else {
|
||||||
if ( !plink.isIndel() ) {
|
if ( plinkAlleleToVCAllele.containsKey(myPlinkAllele) ) {
|
||||||
allele = new Allele(myAllele.getBases(), refAllele.equals(myAllele, true));
|
VCAllele = plinkAlleleToVCAllele.get(myPlinkAllele);
|
||||||
} else if ( myAllele.isNull() ) {
|
|
||||||
allele = new Allele(Allele.NULL_ALLELE_STRING, plink.isInsertion());
|
|
||||||
} else {
|
} else {
|
||||||
allele = new Allele(myAllele.getBases(), !plink.isInsertion());
|
if ( !plink.isIndel() ) {
|
||||||
|
VCAllele = new Allele(myPlinkAllele.getBases(), refAllele.equals(myPlinkAllele, true));
|
||||||
|
} else if ( myPlinkAllele.isNull() ) {
|
||||||
|
VCAllele = new Allele(Allele.NULL_ALLELE_STRING, plink.isInsertion());
|
||||||
|
} else {
|
||||||
|
VCAllele = new Allele(myPlinkAllele.getBases(), !plink.isInsertion());
|
||||||
|
}
|
||||||
|
plinkAlleleToVCAllele.put(myPlinkAllele, VCAllele);
|
||||||
|
VCAlleles.add(VCAllele);
|
||||||
}
|
}
|
||||||
|
|
||||||
alleles.add(allele);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
myAlleles.add(allele);
|
myVCAlleles.add(VCAllele);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the genotype
|
// create the genotype
|
||||||
genotypes.add(new Genotype(genotype.getKey(), myAlleles));
|
genotypes.add(new Genotype(genotype.getKey(), myVCAlleles));
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the variant context
|
// create the variant context
|
||||||
try {
|
try {
|
||||||
GenomeLoc loc = GenomeLocParser.setStop(plink.getLocation(), plink.getLocation().getStop() + plink.getLength()-1);
|
GenomeLoc loc = GenomeLocParser.setStop(plink.getLocation(), plink.getLocation().getStop() + plink.getLength()-1);
|
||||||
VariantContext vc = new VariantContext(plink.getVariantName(), loc, alleles, genotypes);
|
VariantContext vc = new VariantContext(plink.getVariantName(), loc, VCAlleles, genotypes);
|
||||||
vc.validate();
|
vc.validate();
|
||||||
return vc;
|
return vc;
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue