Skip to content

Commit

Permalink
updates to be compatible with Java 7
Browse files Browse the repository at this point in the history
  • Loading branch information
kcibul committed Aug 16, 2013
1 parent 85cb5a1 commit f07a1d1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,36 @@ public enum SampleType {TUMOR, NORMAL}
private NormalPowerCalculator normalDbSNPSitePowerCalculator;
private TumorPowerCalculator strandArtifactPowerCalculator;

private static class PileupComparatorByAltRefQual implements Comparator<PileupElement> {
public static class PileupComparatorByAltRefQual implements Comparator<PileupElement> {
private byte alt;

private PileupComparatorByAltRefQual(byte alt) {
public PileupComparatorByAltRefQual(byte alt) {
this.alt = alt;
}

public int compare(PileupElement o1, PileupElement o2) {
return internalCompare(o1.getBase(), o1.getQual(), o2.getBase(), o2.getQual());
}

public int internalCompare(byte base1, byte qual1, byte base2, byte qual2) {
// if the bases are the same, the higher quality score comes first
if (o1.getBase() == o2.getBase()) {
if (o1.getQual() == o2.getQual()) { return 0; }
return (o1.getQual() > o2.getQual())?-1:1;
if (base1 == base2) {
if (qual1 == qual2) { return 0; }
return (qual1 > qual2)?-1:1;

// if the bases are not the same, then the alternate is first
} else {
return (o1.getBase() == alt)?-1:1;
}
if (base1 == alt) {
return -1;
} else if (base2 == alt) {
return 1;
} else {
return base1 < base2?-1:1;
}

}
}

}


Expand Down Expand Up @@ -729,7 +742,6 @@ protected Map<SampleType, ReadBackedPileup> getPileupsBySampleType(ReadBackedPil
ArrayList<PileupElement> normalPileupElements = new ArrayList<PileupElement>();

for (PileupElement p : pileup ) {
final GATKSAMRecord read = p.getRead();
final byte base = p.getBase();

if (base == ((byte)'N') || base == ((byte)'n')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public void simulate() {

final int trials = 100; // set to 10,000 for paper

final Integer[] depths = new Integer[]{5,10,15,20,25,30,35,40,45,50};
final Double[] trueAlleleFractions = new Double[]{0.1, 0.2, 0.4};
final Integer[] depths = new Integer[]{0, 5,10,15,20,25,30,35,40,45,50};
final Double[] trueAlleleFractions = new Double[]{0.1, 0.2, 0.4, 0.5};

ReferenceContext refContext = new ReferenceContext(genomeLocParser, loc, (byte)ref);
Random r = new Random();
Expand Down Expand Up @@ -207,6 +207,41 @@ public static ReadBackedPileup createReadBackedPileup(final SAMFileHeader header
return new ReadBackedPileupImpl(loc, pileupElements);
}

@Test
public void testPileupComparator() {
byte A = (byte) 'A';
byte C = (byte) 'C';
byte T = (byte) 'T';
byte Q30 = (byte) 30;
byte Q60 = (byte) 60;

MuTect.PileupComparatorByAltRefQual c = new MuTect.PileupComparatorByAltRefQual(A);

// recall:
// A<B -> -1
// A=B -> 0
// A>B -> 1
Assert.assertEquals(c.internalCompare(A, Q30, A, Q60), 1);
Assert.assertEquals(c.internalCompare(A, Q60, A, Q30), -1);
Assert.assertEquals(c.internalCompare(A, Q60, A, Q60), 0);

Assert.assertEquals(c.internalCompare(C, Q30, C, Q60), 1);
Assert.assertEquals(c.internalCompare(C, Q60, C, Q30), -1);
Assert.assertEquals(c.internalCompare(C, Q60, C, Q60), 0);

Assert.assertEquals(c.internalCompare(A, Q30, C, Q60), -1);
Assert.assertEquals(c.internalCompare(A, Q60, C, Q30), -1);
Assert.assertEquals(c.internalCompare(A, Q60, C, Q60), -1);

Assert.assertEquals(c.internalCompare(C, Q30, A, Q60), 1);
Assert.assertEquals(c.internalCompare(C, Q60, A, Q30), 1);
Assert.assertEquals(c.internalCompare(C, Q60, A, Q60), 1);

Assert.assertEquals(c.internalCompare(C, Q60, T, Q60), -1);
Assert.assertEquals(c.internalCompare(T, Q60, C, Q60), 1);

}

public static int getBinomial(int n, double p) {
int x = 0;
for(int i = 0; i < n; i++) {
Expand Down

0 comments on commit f07a1d1

Please sign in to comment.