Use new key of source ROD plus alleles

This commit is contained in:
Joel Thibault 2012-04-19 17:06:37 -04:00
parent 221ce9c3d6
commit 020f884d5a
1 changed files with 27 additions and 22 deletions

View File

@ -38,6 +38,7 @@ import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.MendelianViolation;
import org.broadinstitute.sting.utils.SampleUtils;
import org.broadinstitute.sting.utils.codecs.vcf.*;
import org.broadinstitute.sting.utils.collections.Pair;
import org.broadinstitute.sting.utils.exceptions.UserException;
import org.broadinstitute.sting.utils.text.XReadLines;
import org.broadinstitute.sting.utils.variantcontext.*;
@ -565,15 +566,23 @@ public class SelectVariants extends RodWalker<Integer, Integer> implements TreeR
// can't know stop location for deletions from reference
DBCursor cursor = mongoCollection.find(query);
Map<String,DBObject> results = new HashMap<String,DBObject>();
Map<String,ArrayList<Genotype>> genotypes = new HashMap<String,ArrayList<Genotype>>();
Map<Pair<String,List<Allele>>,DBObject> results = new HashMap<Pair<String,List<Allele>>,DBObject>();
Map<Pair<String,List<Allele>>,List<Genotype>> genotypes = new HashMap<Pair<String,List<Allele>>,List<Genotype>>();
while(cursor.hasNext()) {
DBObject oneResult = cursor.next();
String type = (String)oneResult.get("type");
results.put(type, oneResult);
String sample = (String)oneResult.get("sample");
String sourceROD = (String)oneResult.get("sourceROD");
ArrayList<Allele> alleles = new ArrayList<Allele>();
BasicDBObject allelesInDb = (BasicDBObject)oneResult.get("alleles");
for (Object alleleInDb : allelesInDb.values()) {
String rawAllele = (String)alleleInDb;
boolean isRef = rawAllele.contains("*");
String allele = rawAllele.replace("*", "");
alleles.add(Allele.create(allele, isRef));
}
BasicDBObject genotypeInDb = (BasicDBObject)oneResult.get("genotype");
Double genotypeError = (Double)genotypeInDb.get("error");
@ -598,24 +607,20 @@ public class SelectVariants extends RodWalker<Integer, Integer> implements TreeR
Genotype genotype = new Genotype(sample, genotypeAlleles, genotypeError);
if (!genotypes.containsKey(type))
genotypes.put(type, new ArrayList<Genotype>());
// primary key to uniquely identify variant
Pair<String, List<Allele>> sourceRodAllelePair = new Pair<String, List<Allele>>(sourceROD, alleles);
Collection<Genotype> genotypesByType = genotypes.get(type);
genotypesByType.add(Genotype.modifyAttributes(genotype, genotypeAttributes));
if (!genotypes.containsKey(sourceRodAllelePair))
genotypes.put(sourceRodAllelePair, new ArrayList<Genotype>());
Collection<Genotype> genotypesBySourceROD = genotypes.get(sourceRodAllelePair);
genotypesBySourceROD.add(Genotype.modifyAttributes(genotype, genotypeAttributes));
results.put(sourceRodAllelePair, oneResult);
}
for (String type : results.keySet()) {
DBObject result = results.get(type);
ArrayList<Allele> alleles = new ArrayList<Allele>();
BasicDBObject allelesInDb = (BasicDBObject)result.get("alleles");
for (Object alleleInDb : allelesInDb.values()) {
String rawAllele = (String)alleleInDb;
boolean isRef = rawAllele.contains("*");
String allele = rawAllele.replace("*", "");
alleles.add(Allele.create(allele, isRef));
}
for (Pair<String, List<Allele>> sourceRodAllelePair : results.keySet()) {
DBObject result = results.get(sourceRodAllelePair);
Map<String, Object> attributes = new TreeMap<String, Object>();
BasicDBList attrsInDb = (BasicDBList)result.get("attributes");
@ -638,11 +643,11 @@ public class SelectVariants extends RodWalker<Integer, Integer> implements TreeR
String id = (String)result.get("id");
Double error = (Double)result.get("error");
VariantContextBuilder builder = new VariantContextBuilder(source, contig, start, stop, alleles);
VariantContextBuilder builder = new VariantContextBuilder(source, contig, start, stop, sourceRodAllelePair.getSecond());
builder.id(id);
builder.log10PError(error);
builder.genotypes(genotypes.get(type));
builder.genotypes(genotypes.get(sourceRodAllelePair));
builder.attributes(attributes);
builder.filters(filters);