2009-06-26 23:43:41 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2009 The Broad Institute
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
|
* conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-07-22 00:20:10 +08:00
|
|
|
package org.broadinstitute.sting.gatk.refdata;
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.utils.GenomeLoc;
|
|
|
|
|
import org.broadinstitute.sting.utils.GenomeLocParser;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
2009-09-05 02:40:43 +08:00
|
|
|
public class RodGeliText extends BasicReferenceOrderedDatum implements AllelicVariant {
|
2009-07-17 05:03:47 +08:00
|
|
|
public enum Genotype { AA, AC, AG, AT, CC, CG, CT, GG, GT, TT }
|
|
|
|
|
public GenomeLoc loc;
|
|
|
|
|
public char refBase = 'N';
|
|
|
|
|
public int depth;
|
|
|
|
|
public int maxMappingQuality;
|
|
|
|
|
public String bestGenotype = "NN";
|
|
|
|
|
public double lodBtr;
|
|
|
|
|
public double lodBtnb;
|
|
|
|
|
public double[] genotypeLikelihoods = new double[10];
|
2009-06-18 05:32:21 +08:00
|
|
|
|
2009-09-05 02:40:43 +08:00
|
|
|
public RodGeliText(final String name) {
|
2009-07-22 00:20:10 +08:00
|
|
|
super(name);
|
|
|
|
|
}
|
2009-06-18 05:32:21 +08:00
|
|
|
|
|
|
|
|
public String delimiterRegex() { return "\\s+"; }
|
|
|
|
|
|
|
|
|
|
public boolean parseLine(Object header, String[] parts) throws IOException {
|
2009-07-23 01:54:44 +08:00
|
|
|
if ( parts.length < 18 )
|
|
|
|
|
throw new IOException("Invalid rodVariant row found -- too few elements. Expected 18+, got " + parts.length);
|
2009-06-18 05:32:21 +08:00
|
|
|
if (!parts[0].startsWith("#")) {
|
2009-06-22 22:39:41 +08:00
|
|
|
loc = GenomeLocParser.createGenomeLoc(parts[0], Long.valueOf(parts[1]));
|
2009-06-18 05:32:21 +08:00
|
|
|
refBase = parts[2].charAt(0);
|
|
|
|
|
depth = Integer.valueOf(parts[3]);
|
|
|
|
|
maxMappingQuality = Integer.valueOf(parts[4]);
|
|
|
|
|
bestGenotype = parts[5];
|
2009-07-17 05:03:47 +08:00
|
|
|
lodBtr = Double.valueOf(parts[6]);
|
|
|
|
|
lodBtnb = Double.valueOf(parts[7]);
|
2009-06-18 05:32:21 +08:00
|
|
|
|
|
|
|
|
for (int pieceIndex = 8, offset = 0; pieceIndex < 18; pieceIndex++, offset++) {
|
2009-07-17 05:03:47 +08:00
|
|
|
genotypeLikelihoods[offset] = Double.valueOf(parts[pieceIndex]);
|
2009-06-18 05:32:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String toString() {
|
2009-07-10 03:45:18 +08:00
|
|
|
return String.format("%s\t%d\t%c\t%d\t%d\t%s\t%4.4f\t%4.4f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f",
|
|
|
|
|
loc.getContig(),
|
|
|
|
|
loc.getStart(),
|
2009-06-18 05:32:21 +08:00
|
|
|
refBase,
|
|
|
|
|
depth,
|
|
|
|
|
maxMappingQuality,
|
|
|
|
|
bestGenotype,
|
|
|
|
|
lodBtr,
|
|
|
|
|
lodBtnb,
|
|
|
|
|
genotypeLikelihoods[0],
|
|
|
|
|
genotypeLikelihoods[1],
|
|
|
|
|
genotypeLikelihoods[2],
|
|
|
|
|
genotypeLikelihoods[3],
|
|
|
|
|
genotypeLikelihoods[4],
|
|
|
|
|
genotypeLikelihoods[5],
|
|
|
|
|
genotypeLikelihoods[6],
|
|
|
|
|
genotypeLikelihoods[7],
|
|
|
|
|
genotypeLikelihoods[8],
|
|
|
|
|
genotypeLikelihoods[9]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GenomeLoc getLocation() { return loc; }
|
|
|
|
|
|
2009-07-22 00:20:10 +08:00
|
|
|
public String getRefBasesFWD() {
|
|
|
|
|
return String.format("%c", getRefSnpFWD());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public char getRefSnpFWD() throws IllegalStateException {
|
|
|
|
|
return refBase;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getAltBasesFWD() {
|
|
|
|
|
return String.format("%c", getAltSnpFWD());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public char getAltSnpFWD() throws IllegalStateException {
|
2009-08-08 03:37:07 +08:00
|
|
|
char c = (bestGenotype.charAt(0) == refBase) ? bestGenotype.charAt(1) : bestGenotype.charAt(0);
|
|
|
|
|
//System.out.printf("%s : %c and %c%n", bestGenotype, refBase, c);
|
|
|
|
|
return c;
|
2009-07-22 00:20:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isReference() {
|
2009-08-20 04:32:29 +08:00
|
|
|
return refBase == bestGenotype.charAt(0) && refBase == bestGenotype.charAt(1);
|
2009-07-22 00:20:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isSNP() {
|
|
|
|
|
return !isReference();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isInsertion() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isDeletion() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isIndel() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getMAF() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getHeterozygosity() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isGenotype() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getVariationConfidence() {
|
|
|
|
|
return lodBtr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getConsensusConfidence() {
|
|
|
|
|
return lodBtnb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<String> getGenotype() throws IllegalStateException {
|
|
|
|
|
return Arrays.asList(getBestGenotype());
|
|
|
|
|
//throw new IllegalStateException("huh?");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getPloidy() throws IllegalStateException {
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isBiallelic() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-11 23:01:50 +08:00
|
|
|
|
2009-07-28 11:25:03 +08:00
|
|
|
public int length() { return 1; }
|
|
|
|
|
|
2009-06-18 05:32:21 +08:00
|
|
|
public char getReferenceBase() { return refBase; }
|
|
|
|
|
|
|
|
|
|
public int getPileupDepth() { return depth; }
|
|
|
|
|
|
|
|
|
|
public int getMaxMappingQuality() { return maxMappingQuality; }
|
|
|
|
|
|
|
|
|
|
public String getBestGenotype() { return bestGenotype; }
|
|
|
|
|
|
2009-07-17 05:03:47 +08:00
|
|
|
public double getLodBtr() { return lodBtr; }
|
2009-06-18 05:32:21 +08:00
|
|
|
|
2009-07-17 05:03:47 +08:00
|
|
|
public double getLodBtnb() { return lodBtnb; }
|
2009-06-18 05:32:21 +08:00
|
|
|
|
2009-07-17 05:03:47 +08:00
|
|
|
public double[] getGenotypeLikelihoods() { return genotypeLikelihoods; }
|
2009-06-18 15:26:37 +08:00
|
|
|
|
|
|
|
|
public void adjustLikelihoods(double[] likelihoods) {
|
|
|
|
|
for (int likelihoodIndex = 0; likelihoodIndex < likelihoods.length; likelihoodIndex++) {
|
|
|
|
|
genotypeLikelihoods[likelihoodIndex] += likelihoods[likelihoodIndex];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String bestGenotype = "NN";
|
|
|
|
|
double bestLikelihood = Double.NEGATIVE_INFINITY;
|
|
|
|
|
double nextBestLikelihood = Double.NEGATIVE_INFINITY;
|
|
|
|
|
double refLikelihood = Double.NEGATIVE_INFINITY;
|
|
|
|
|
|
|
|
|
|
for (int likelihoodIndex = 0; likelihoodIndex < likelihoods.length; likelihoodIndex++) {
|
|
|
|
|
if (genotypeLikelihoods[likelihoodIndex] > bestLikelihood) {
|
|
|
|
|
bestLikelihood = genotypeLikelihoods[likelihoodIndex];
|
|
|
|
|
|
|
|
|
|
bestGenotype = Genotype.values()[likelihoodIndex].toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int likelihoodIndex = 0; likelihoodIndex < likelihoods.length; likelihoodIndex++) {
|
|
|
|
|
if (genotypeLikelihoods[likelihoodIndex] > nextBestLikelihood && genotypeLikelihoods[likelihoodIndex] < bestLikelihood) {
|
|
|
|
|
nextBestLikelihood = genotypeLikelihoods[likelihoodIndex];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int likelihoodIndex = 0; likelihoodIndex < likelihoods.length; likelihoodIndex++) {
|
|
|
|
|
if (refBase == Genotype.values()[likelihoodIndex].toString().charAt(0) &&
|
|
|
|
|
refBase == Genotype.values()[likelihoodIndex].toString().charAt(1)) {
|
|
|
|
|
refLikelihood = genotypeLikelihoods[likelihoodIndex];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.bestGenotype = bestGenotype;
|
2009-07-17 05:03:47 +08:00
|
|
|
this.lodBtr = (bestLikelihood - refLikelihood);
|
|
|
|
|
this.lodBtnb = (bestLikelihood - nextBestLikelihood);
|
2009-06-18 15:26:37 +08:00
|
|
|
}
|
2009-07-15 02:53:27 +08:00
|
|
|
|
2009-07-22 00:20:10 +08:00
|
|
|
/*
|
2009-07-15 02:53:27 +08:00
|
|
|
public String getRefBasesFWD() {
|
|
|
|
|
char[] b = { getReferenceBase() };
|
|
|
|
|
return new String( b );
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-16 10:31:10 +08:00
|
|
|
public char getRefSnpFWD() throws IllegalStateException { return getReferenceBase(); }
|
|
|
|
|
public String getAltBasesFWD() { return getBestGenotype(); }
|
|
|
|
|
public char getAltSnpFWD() throws IllegalStateException {
|
|
|
|
|
String bases = getBestGenotype();
|
|
|
|
|
if ( bases.charAt(0) != getRefSnpFWD() )
|
|
|
|
|
return bases.charAt(0);
|
|
|
|
|
else
|
|
|
|
|
return bases.charAt(1);
|
|
|
|
|
|
|
|
|
|
}
|
2009-07-15 02:53:27 +08:00
|
|
|
public boolean isReference() { return ! isSNP(); }
|
|
|
|
|
public boolean isSNP() { return getLodBtr() > 5; }
|
|
|
|
|
public boolean isInsertion() { return false; }
|
|
|
|
|
public boolean isDeletion() { return false; }
|
|
|
|
|
public boolean isIndel() { return false; }
|
|
|
|
|
public double getMAF() { return 0; }
|
|
|
|
|
public double getHeterozygosity() { return 0; }
|
|
|
|
|
public boolean isGenotype() { return true; }
|
|
|
|
|
public double getVariationConfidence() { return getLodBtr(); }
|
|
|
|
|
public double getConsensusConfidence() { return getLodBtnb(); }
|
|
|
|
|
public List<String> getGenotype() throws IllegalStateException {
|
|
|
|
|
return Arrays.asList(getBestGenotype());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getPloidy() throws IllegalStateException { return 2; }
|
|
|
|
|
public boolean isBiallelic() { return true; }
|
2009-07-22 00:20:10 +08:00
|
|
|
*/
|
2009-06-18 05:32:21 +08:00
|
|
|
}
|