Minor interface change for VCFGenotypeRecord.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2537 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
431e9c2c8b
commit
b643a513bb
|
|
@ -137,16 +137,18 @@ public class VariantsToVCF extends RefWalker<Integer, Integer> {
|
||||||
str.put("GQ", lod);
|
str.put("GQ", lod);
|
||||||
if (depth > 0) str.put("DP", String.valueOf(depth));
|
if (depth > 0) str.put("DP", String.valueOf(depth));
|
||||||
|
|
||||||
gt.add(new VCFGenotypeRecord(name, alleles, VCFGenotypeRecord.PHASE.UNPHASED, str));
|
VCFGenotypeRecord rec = new VCFGenotypeRecord(name, alleles, VCFGenotypeRecord.PHASE.UNPHASED);
|
||||||
|
for ( Map.Entry<String, String> entry : str.entrySet() )
|
||||||
|
rec.setField(entry.getKey(), entry.getValue());
|
||||||
|
gt.add(rec);
|
||||||
|
|
||||||
numSNPs++;
|
numSNPs++;
|
||||||
snpQual += av.getNegLog10PError();
|
snpQual += av.getNegLog10PError();
|
||||||
} else if (BaseUtils.simpleBaseToBaseIndex(ref.getBase()) != -1) {
|
} else if (BaseUtils.simpleBaseToBaseIndex(ref.getBase()) != -1) {
|
||||||
Map<String, String> str = new HashMap<String, String>();
|
|
||||||
List<VCFGenotypeEncoding> alleles = new ArrayList<VCFGenotypeEncoding>();
|
List<VCFGenotypeEncoding> alleles = new ArrayList<VCFGenotypeEncoding>();
|
||||||
alleles.add(new VCFGenotypeEncoding(String.valueOf(ref.getBase())));
|
alleles.add(new VCFGenotypeEncoding(String.valueOf(ref.getBase())));
|
||||||
alleles.add(new VCFGenotypeEncoding(String.valueOf(ref.getBase())));
|
alleles.add(new VCFGenotypeEncoding(String.valueOf(ref.getBase())));
|
||||||
gt.add(new VCFGenotypeRecord(name, alleles, VCFGenotypeRecord.PHASE.UNPHASED, str));
|
gt.add(new VCFGenotypeRecord(name, alleles, VCFGenotypeRecord.PHASE.UNPHASED));
|
||||||
|
|
||||||
numRefs++;
|
numRefs++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,20 +58,12 @@ public class VCFGenotypeRecord implements Genotype, SampleBacked {
|
||||||
* @param sampleName sample name
|
* @param sampleName sample name
|
||||||
* @param genotypes list of genotypes
|
* @param genotypes list of genotypes
|
||||||
* @param phasing phasing
|
* @param phasing phasing
|
||||||
* @param otherFlags other flags
|
|
||||||
*/
|
*/
|
||||||
public VCFGenotypeRecord(String sampleName, List<VCFGenotypeEncoding> genotypes, PHASE phasing, Map<String, String> otherFlags) {
|
public VCFGenotypeRecord(String sampleName, List<VCFGenotypeEncoding> genotypes, PHASE phasing) {
|
||||||
mSampleName = sampleName;
|
mSampleName = sampleName;
|
||||||
if (genotypes != null) this.mGenotypeAlleles.addAll(genotypes);
|
if (genotypes != null)
|
||||||
|
this.mGenotypeAlleles.addAll(genotypes);
|
||||||
mPhaseType = phasing;
|
mPhaseType = phasing;
|
||||||
if (otherFlags != null) {
|
|
||||||
// we need to be backwards compatible
|
|
||||||
if ( otherFlags.containsKey(OLD_DEPTH_KEY) ) {
|
|
||||||
otherFlags.put(DEPTH_KEY, otherFlags.get(OLD_DEPTH_KEY));
|
|
||||||
otherFlags.remove(OLD_DEPTH_KEY);
|
|
||||||
}
|
|
||||||
mFields.putAll(otherFlags);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVCFRecord(VCFRecord record) {
|
public void setVCFRecord(VCFRecord record) {
|
||||||
|
|
@ -82,6 +74,23 @@ public class VCFGenotypeRecord implements Genotype, SampleBacked {
|
||||||
mSampleName = name;
|
mSampleName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a field to the genotype record.
|
||||||
|
* Throws an exception if the key is GT, as that's computed internally.
|
||||||
|
*
|
||||||
|
* @param key the field name (use static variables above for common fields)
|
||||||
|
* @param value the field value
|
||||||
|
*/
|
||||||
|
public void setField(String key, String value) {
|
||||||
|
// make sure the GT field isn't being set
|
||||||
|
if ( key.equals(GENOTYPE_KEY) )
|
||||||
|
throw new IllegalArgumentException("Setting the GT field is not allowed as that's done internally");
|
||||||
|
// we need to be backwards compatible
|
||||||
|
if ( key.equals(OLD_DEPTH_KEY) )
|
||||||
|
key = DEPTH_KEY;
|
||||||
|
mFields.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* determine the phase of the genotype
|
* determine the phase of the genotype
|
||||||
*
|
*
|
||||||
|
|
@ -217,7 +226,8 @@ public class VCFGenotypeRecord implements Genotype, SampleBacked {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String toString() {
|
@Override
|
||||||
|
public String toString() {
|
||||||
return String.format("[VCFGenotype %s %s %s %s]", getLocation(), mSampleName, this.mGenotypeAlleles, mFields);
|
return String.format("[VCFGenotype %s %s %s %s]", getLocation(), mSampleName, this.mGenotypeAlleles, mFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -192,18 +192,12 @@ public class VCFGenotypeWriterAdapter implements VCFGenotypeWriter {
|
||||||
* @return a VCFGenotypeRecord for the no call situation
|
* @return a VCFGenotypeRecord for the no call situation
|
||||||
*/
|
*/
|
||||||
private VCFGenotypeRecord createNoCallRecord(String sampleName) {
|
private VCFGenotypeRecord createNoCallRecord(String sampleName) {
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
|
||||||
|
|
||||||
|
|
||||||
List<VCFGenotypeEncoding> alleles = new ArrayList<VCFGenotypeEncoding>();
|
List<VCFGenotypeEncoding> alleles = new ArrayList<VCFGenotypeEncoding>();
|
||||||
alleles.add(new VCFGenotypeEncoding(VCFGenotypeRecord.EMPTY_ALLELE));
|
alleles.add(new VCFGenotypeEncoding(VCFGenotypeRecord.EMPTY_ALLELE));
|
||||||
alleles.add(new VCFGenotypeEncoding(VCFGenotypeRecord.EMPTY_ALLELE));
|
alleles.add(new VCFGenotypeEncoding(VCFGenotypeRecord.EMPTY_ALLELE));
|
||||||
|
|
||||||
VCFGenotypeRecord record = new VCFGenotypeRecord(sampleName,
|
return new VCFGenotypeRecord(sampleName, alleles, VCFGenotypeRecord.PHASE.UNPHASED);
|
||||||
alleles,
|
|
||||||
VCFGenotypeRecord.PHASE.UNPHASED,
|
|
||||||
map);
|
|
||||||
return record;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return true if we support multisample, false otherwise */
|
/** @return true if we support multisample, false otherwise */
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,7 @@ public class VCFReader implements Iterator<VCFRecord>, Iterable<VCFRecord> {
|
||||||
*/
|
*/
|
||||||
public static VCFGenotypeRecord getVCFGenotype(String sampleName, String[] keyStrings, String genotypeString, String altAlleles[], char referenceBase) {
|
public static VCFGenotypeRecord getVCFGenotype(String sampleName, String[] keyStrings, String genotypeString, String altAlleles[], char referenceBase) {
|
||||||
// parameters to create the VCF genotype record
|
// parameters to create the VCF genotype record
|
||||||
Map<String, String> tagToValue = new HashMap<String, String>();
|
HashMap<String, String> tagToValue = new HashMap<String, String>();
|
||||||
VCFGenotypeRecord.PHASE phase = VCFGenotypeRecord.PHASE.UNKNOWN;
|
VCFGenotypeRecord.PHASE phase = VCFGenotypeRecord.PHASE.UNKNOWN;
|
||||||
List<VCFGenotypeEncoding> bases = new ArrayList<VCFGenotypeEncoding>();
|
List<VCFGenotypeEncoding> bases = new ArrayList<VCFGenotypeEncoding>();
|
||||||
|
|
||||||
|
|
@ -294,7 +294,11 @@ public class VCFReader implements Iterator<VCFRecord>, Iterable<VCFRecord> {
|
||||||
else if ( genotypeString.length() > 0 )
|
else if ( genotypeString.length() > 0 )
|
||||||
throw new RuntimeException("VCFReader: genotype string contained additional unprocessed fields: " + genotypeString
|
throw new RuntimeException("VCFReader: genotype string contained additional unprocessed fields: " + genotypeString
|
||||||
+ ". This most likely means that the format string is shorter then the value fields.");
|
+ ". This most likely means that the format string is shorter then the value fields.");
|
||||||
return new VCFGenotypeRecord(sampleName, bases, phase, tagToValue);
|
|
||||||
|
VCFGenotypeRecord rec = new VCFGenotypeRecord(sampleName, bases, phase);
|
||||||
|
for ( Map.Entry<String, String> entry : tagToValue.entrySet() )
|
||||||
|
rec.setField(entry.getKey(), entry.getValue());
|
||||||
|
return rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -210,24 +210,21 @@ public class VCFUtils {
|
||||||
* @return a VCFGenotypeRecord
|
* @return a VCFGenotypeRecord
|
||||||
*/
|
*/
|
||||||
public static VCFGenotypeRecord createVCFGenotypeRecord(VCFParameters params, VCFGenotypeRecord gtype, VCFRecord vcfrecord) {
|
public static VCFGenotypeRecord createVCFGenotypeRecord(VCFParameters params, VCFGenotypeRecord gtype, VCFRecord vcfrecord) {
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
|
||||||
|
|
||||||
// calculate the genotype quality and the read depth
|
|
||||||
map.put(VCFGenotypeRecord.DEPTH_KEY, String.valueOf(gtype.getReadCount()));
|
|
||||||
params.addFormatItem(VCFGenotypeRecord.DEPTH_KEY);
|
|
||||||
double qual = Math.min(10.0 * gtype.getNegLog10PError(), VCFGenotypeRecord.MAX_QUAL_VALUE);
|
|
||||||
map.put(VCFGenotypeRecord.GENOTYPE_QUALITY_KEY, String.format("%.2f", qual));
|
|
||||||
params.addFormatItem(VCFGenotypeRecord.GENOTYPE_QUALITY_KEY);
|
|
||||||
|
|
||||||
List<VCFGenotypeEncoding> alleles = createAlleleArray(gtype);
|
List<VCFGenotypeEncoding> alleles = createAlleleArray(gtype);
|
||||||
for (VCFGenotypeEncoding allele : alleles) {
|
for (VCFGenotypeEncoding allele : alleles) {
|
||||||
params.addAlternateBase(allele);
|
params.addAlternateBase(allele);
|
||||||
}
|
}
|
||||||
|
|
||||||
VCFGenotypeRecord record = new VCFGenotypeRecord(gtype.getSampleName(),
|
VCFGenotypeRecord record = new VCFGenotypeRecord(gtype.getSampleName(), alleles, VCFGenotypeRecord.PHASE.UNPHASED);
|
||||||
alleles,
|
|
||||||
VCFGenotypeRecord.PHASE.UNPHASED,
|
// calculate the genotype quality and the read depth
|
||||||
map);
|
record.setField(VCFGenotypeRecord.DEPTH_KEY, String.valueOf(gtype.getReadCount()));
|
||||||
|
params.addFormatItem(VCFGenotypeRecord.DEPTH_KEY);
|
||||||
|
double qual = Math.min(10.0 * gtype.getNegLog10PError(), VCFGenotypeRecord.MAX_QUAL_VALUE);
|
||||||
|
record.setField(VCFGenotypeRecord.GENOTYPE_QUALITY_KEY, String.format("%.2f", qual));
|
||||||
|
params.addFormatItem(VCFGenotypeRecord.GENOTYPE_QUALITY_KEY);
|
||||||
|
|
||||||
record.setVCFRecord(vcfrecord);
|
record.setVCFRecord(vcfrecord);
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
@ -241,24 +238,21 @@ public class VCFUtils {
|
||||||
* @return a VCFGenotypeRecord
|
* @return a VCFGenotypeRecord
|
||||||
*/
|
*/
|
||||||
public static VCFGenotypeRecord createVCFGenotypeRecord(VCFParameters params, VCFGenotypeCall gtype) {
|
public static VCFGenotypeRecord createVCFGenotypeRecord(VCFParameters params, VCFGenotypeCall gtype) {
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
|
||||||
|
|
||||||
// calculate the RMS mapping qualities and the read depth
|
|
||||||
map.put(VCFGenotypeRecord.DEPTH_KEY, String.valueOf(gtype.getReadCount()));
|
|
||||||
params.addFormatItem(VCFGenotypeRecord.DEPTH_KEY);
|
|
||||||
double qual = Math.min(10.0 * gtype.getNegLog10PError(), VCFGenotypeRecord.MAX_QUAL_VALUE);
|
|
||||||
map.put(VCFGenotypeRecord.GENOTYPE_QUALITY_KEY, String.format("%.2f", qual));
|
|
||||||
params.addFormatItem(VCFGenotypeRecord.GENOTYPE_QUALITY_KEY);
|
|
||||||
|
|
||||||
List<VCFGenotypeEncoding> alleles = createAlleleArray(gtype);
|
List<VCFGenotypeEncoding> alleles = createAlleleArray(gtype);
|
||||||
for (VCFGenotypeEncoding allele : alleles) {
|
for (VCFGenotypeEncoding allele : alleles) {
|
||||||
params.addAlternateBase(allele);
|
params.addAlternateBase(allele);
|
||||||
}
|
}
|
||||||
|
|
||||||
VCFGenotypeRecord record = new VCFGenotypeRecord(gtype.getSampleName(),
|
VCFGenotypeRecord record = new VCFGenotypeRecord(gtype.getSampleName(), alleles, VCFGenotypeRecord.PHASE.UNPHASED);
|
||||||
alleles,
|
|
||||||
VCFGenotypeRecord.PHASE.UNPHASED,
|
// calculate the RMS mapping qualities and the read depth
|
||||||
map);
|
record.setField(VCFGenotypeRecord.DEPTH_KEY, String.valueOf(gtype.getReadCount()));
|
||||||
|
params.addFormatItem(VCFGenotypeRecord.DEPTH_KEY);
|
||||||
|
double qual = Math.min(10.0 * gtype.getNegLog10PError(), VCFGenotypeRecord.MAX_QUAL_VALUE);
|
||||||
|
record.setField(VCFGenotypeRecord.GENOTYPE_QUALITY_KEY, String.format("%.2f", qual));
|
||||||
|
params.addFormatItem(VCFGenotypeRecord.GENOTYPE_QUALITY_KEY);
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,12 +56,12 @@ public class VCFRecordTest extends BaseTest {
|
||||||
* @return a VCFGenotypeRecord
|
* @return a VCFGenotypeRecord
|
||||||
*/
|
*/
|
||||||
private static VCFGenotypeRecord createGenotype(String name, String Allele1, String Allele2) {
|
private static VCFGenotypeRecord createGenotype(String name, String Allele1, String Allele2) {
|
||||||
Map<String, String> keyValues = new HashMap<String, String>();
|
|
||||||
keyValues.put("AA", "2");
|
|
||||||
List<VCFGenotypeEncoding> Alleles = new ArrayList<VCFGenotypeEncoding>();
|
List<VCFGenotypeEncoding> Alleles = new ArrayList<VCFGenotypeEncoding>();
|
||||||
Alleles.add(new VCFGenotypeEncoding(Allele1));
|
Alleles.add(new VCFGenotypeEncoding(Allele1));
|
||||||
Alleles.add(new VCFGenotypeEncoding(Allele2));
|
Alleles.add(new VCFGenotypeEncoding(Allele2));
|
||||||
return new VCFGenotypeRecord(name, Alleles, VCFGenotypeRecord.PHASE.PHASED, keyValues);
|
VCFGenotypeRecord rec = new VCFGenotypeRecord(name, Alleles, VCFGenotypeRecord.PHASE.PHASED);
|
||||||
|
rec.setField("AA", "2");
|
||||||
|
return rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -85,13 +85,12 @@ public class VCFWriterTest extends BaseTest {
|
||||||
|
|
||||||
List<VCFGenotypeRecord> gt = new ArrayList<VCFGenotypeRecord>();
|
List<VCFGenotypeRecord> gt = new ArrayList<VCFGenotypeRecord>();
|
||||||
for (String name : header.getGenotypeSamples()) {
|
for (String name : header.getGenotypeSamples()) {
|
||||||
Map<String,String> str = new HashMap<String,String>();
|
|
||||||
str.put("bb","0");
|
|
||||||
|
|
||||||
List<VCFGenotypeEncoding> myAlleles = new ArrayList<VCFGenotypeEncoding>();
|
List<VCFGenotypeEncoding> myAlleles = new ArrayList<VCFGenotypeEncoding>();
|
||||||
myAlleles.add(new VCFGenotypeEncoding("C"));
|
myAlleles.add(new VCFGenotypeEncoding("C"));
|
||||||
myAlleles.add(new VCFGenotypeEncoding("D1"));
|
myAlleles.add(new VCFGenotypeEncoding("D1"));
|
||||||
gt.add(new VCFGenotypeRecord(name, myAlleles, VCFGenotypeRecord.PHASE.PHASED, str));
|
VCFGenotypeRecord rec = new VCFGenotypeRecord(name, myAlleles, VCFGenotypeRecord.PHASE.PHASED);
|
||||||
|
rec.setField("bb", "0");
|
||||||
|
gt.add(rec);
|
||||||
}
|
}
|
||||||
return new VCFRecord('A',"chr1",1,"RANDOM",altBases,0,".",infoFields, "GT:AA",gt);
|
return new VCFRecord('A',"chr1",1,"RANDOM",altBases,0,".",infoFields, "GT:AA",gt);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue