I committed this too soon... reverting...

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1106 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
kiran 2009-06-25 20:49:12 +00:00
parent ad3a3aa350
commit ee2af3b423
1 changed files with 31 additions and 32 deletions

View File

@ -1,8 +1,7 @@
package org.broadinstitute.sting.secondarybase; package org.broadinstitute.sting.secondarybase;
import org.broadinstitute.sting.utils.QualityUtils;
import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.Utils;
import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.QualityUtils;
/** /**
* FourProb represents four base hypotheses, their probabilities, and the ranking among one another. * FourProb represents four base hypotheses, their probabilities, and the ranking among one another.
@ -10,8 +9,8 @@ import org.broadinstitute.sting.utils.BaseUtils;
* @author Kiran Garimella * @author Kiran Garimella
*/ */
public class FourProb { public class FourProb {
private int[] baseIndices;
private double[] baseProbs; private double[] baseProbs;
private int[] baseIndices;
/** /**
* Constructor for FourProb. * Constructor for FourProb.
@ -26,33 +25,18 @@ public class FourProb {
} }
} }
int[] baseIndices = {0, 1, 2, 3};
Integer[] perm = Utils.SortPermutation(baseProbs);
double[] ascendingBaseProbs = Utils.PermuteArray(baseProbs, perm);
int[] ascendingBaseIndices = Utils.PermuteArray(baseIndices, perm);
this.baseProbs = new double[4]; this.baseProbs = new double[4];
this.baseIndices = new int[4]; this.baseIndices = new int[4];
// store this information in sorted form
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (baseProbs[i] > this.baseProbs[0]) { this.baseProbs[i] = ascendingBaseProbs[3 - i];
this.baseProbs[1] = this.baseProbs[0]; this.baseIndices[i] = ascendingBaseIndices[3 - i];
this.baseIndices[1] = this.baseIndices[0];
this.baseProbs[0] = baseProbs[i];
this.baseIndices[0] = i;
} else if (baseProbs[i] > this.baseProbs[1]) {
this.baseProbs[2] = this.baseProbs[1];
this.baseIndices[2] = this.baseIndices[1];
this.baseProbs[1] = baseProbs[i];
this.baseIndices[1] = i;
} else if (baseProbs[i] > this.baseProbs[2]) {
this.baseProbs[3] = this.baseProbs[2];
this.baseIndices[3] = this.baseIndices[2];
this.baseProbs[2] = baseProbs[i];
this.baseIndices[2] = i;
} else {
this.baseProbs[3] = baseProbs[i];
this.baseIndices[3] = i;
}
} }
} }
@ -70,8 +54,7 @@ public class FourProb {
* @param rank (0 = best, 3 = worst) the rank of the base whose index should be returned * @param rank (0 = best, 3 = worst) the rank of the base whose index should be returned
* @return the base label (A, C, G, T). * @return the base label (A, C, G, T).
*/ */
//public char baseAtRank(int rank) { return baseIndexToBase(indexAtRank(rank)); } public char baseAtRank(int rank) { return baseIndexToBase(indexAtRank(rank)); }
public char baseAtRank(int rank) { return BaseUtils.baseIndexToSimpleBase(indexAtRank(rank)); }
/** /**
* Returns the probability of the base at the specified rank. * Returns the probability of the base at the specified rank.
@ -89,6 +72,22 @@ public class FourProb {
*/ */
public byte qualAtRank(int rank) { return QualityUtils.probToQual(probAtRank(rank)); } public byte qualAtRank(int rank) { return QualityUtils.probToQual(probAtRank(rank)); }
/**
* A utility method to convert a base index into a base label.
*
* @param baseIndex the index of the base (0, 1, 2, 3).
* @return A, C, G, T, or '.' if the base index can't be understood.
*/
private char baseIndexToBase(int baseIndex) {
switch (baseIndex) {
case 0: return 'A';
case 1: return 'C';
case 2: return 'G';
case 3: return 'T';
default: return '.';
}
}
/** /**
* Prettily formats the FourProb info. * Prettily formats the FourProb info.
* *
@ -96,10 +95,10 @@ public class FourProb {
*/ */
public String toString() { public String toString() {
return ( return (
"[" + baseAtRank(0) + ":" + probAtRank(0) + " " "[" + baseAtRank(0) + ":" + qualAtRank(0) + " "
+ baseAtRank(1) + ":" + probAtRank(1) + " " + baseAtRank(1) + ":" + qualAtRank(1) + " "
+ baseAtRank(2) + ":" + probAtRank(2) + " " + baseAtRank(2) + ":" + qualAtRank(2) + " "
+ baseAtRank(3) + ":" + probAtRank(3) + "]" + baseAtRank(3) + ":" + qualAtRank(3) + "]"
); );
} }
} }