Skip to content

Commit

Permalink
add tests for partial CpG site/bottom sequence in sequence processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ke Hu committed Jul 26, 2015
1 parent ae407b5 commit 16a055b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 53 deletions.
33 changes: 11 additions & 22 deletions BSPAT/src/edu/cwru/cbc/BSPAT/DataType/Sequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ public String getOriginalSeq() {
return originalSeq;
}

public void setOriginalSeq(String originalSeq) {
this.originalSeq = originalSeq;
}

public String getRegion() {
return region;
}
Expand All @@ -100,10 +96,6 @@ public int getStartPos() {
return startPos;
}

public void setStartPos(int startPos) {
this.startPos = startPos;
}

public void addCpG(CpGSite cpg) {
CpGSites.add(cpg);
}
Expand Down Expand Up @@ -140,10 +132,6 @@ public String getStrand() {
return strand;
}

public void setStrand(String strand) {
this.strand = strand;
}

public boolean isInSeq(int pos) {
return pos >= this.startPos && pos <= this.getEndPos();
}
Expand All @@ -161,12 +149,17 @@ public void processSequence(String referenceSeq) {
}
}
char originalC, bisulfiteC;
if (strand.equals("TOP")) {
originalC = 'C';
bisulfiteC = 'T';
} else {
originalC = 'G';
bisulfiteC = 'A';
switch (strand) {
case "TOP":
originalC = 'C';
bisulfiteC = 'T';
break;
case "BOTTOM":
originalC = 'G';
bisulfiteC = 'A';
break;
default:
throw new RuntimeException("invalid sequence strand!");
}
double countOfUnConvertedC = 0;
double unequalNucleotide = 0;
Expand Down Expand Up @@ -197,10 +190,6 @@ public void processSequence(String referenceSeq) {
this.setSequenceIdentity(
1 - unequalNucleotide / (this.getOriginalSeq().length() - this.getCpGSites().size()));
this.setMethylationString(generateMethylString());
if (originalSeq.equals(
"CAATCTCTTTTGATTATTTAAACATCCCTATAAAATAAACGTCACGTAACACAAACCACTATCCCCATTTTAAAAATAAAAAAATCGAAATTCAAAAATAAAAAAAAATTTCCCCAAAATCACTA")) {
System.out.println();
}
}

private StringBuilder bisulfiteRefSeq() {
Expand Down
91 changes: 60 additions & 31 deletions BSPAT/test/edu/cwru/cbc/BSPAT/DataType/SequenceTest.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,77 @@
package edu.cwru.cbc.BSPAT.DataType;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.testng.AssertJUnit.assertEquals;

/**
* Created by lancelothk on 7/23/15.
*/
public class SequenceTest {

@org.junit.Test
public void testProcessSequence() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
String ref = "AAACATCTCTAATGAGGGAGGAGGCCCGAGGATGGCTGGGTTTGATTTATGACTGGAGGAGAAGGTCCACTTCCCACTGCGAAGCAGGCGACCTGCTC";
List<Sequence> seqList = new ArrayList<>();
seqList.add(new Sequence("1", "test", "+", 0,
"AAATATTTTTAATGAGGGAGGAGGTTTGAGGATGGTTGGGTTTGATTTATGATTGGAGGAGAAGGCTTATTTTTTATTGCGAAGTAGGCGATTTGTTC"));
seqList.add(new Sequence("2", "test", "+", 0,
"AAATATTTTTAATGAGGGAGGAGGTTTGAGGATGGTTGGGTTTGATTTATGATTGGAGGAGAAGGTCTATTTTTTATTGTGAAGTAGGTAATTTGTTT"));
seqList.add(new Sequence("3", "test", "+", 0,
"AAATATTTTTAATGAGGGAGGAGGTTTGAGGATGGTTGGGTTTGATTTATGATTGGAGGAGAAGGTTTATTTTTTATTGCGAAGTAGGGTATTTGTTC"));

for (Sequence sequence : seqList) {
sequence.addCpG(new CpGSite(26, false));
sequence.addCpG(new CpGSite(79, true));
sequence.addCpG(new CpGSite(88, true));
sequence.processSequence(ref);
}


assertEquals("sequence identity not equal for seq 1!", 0.989, seqList.get(0).getSequenceIdentity(), 0.001);
assertEquals("sequence identity not equal for seq 2!", 0.989, seqList.get(1).getSequenceIdentity(), 0.001);
assertEquals("sequence identity not equal for seq 3!", 0.979, seqList.get(2).getSequenceIdentity(), 0.001);

assertEquals("bisulfite conversion rate not equal for seq 1!", 0.947, seqList.get(0).getBisulConversionRate(),
Sequence seq1 = new Sequence("1", "TOP", "test", 0,
"AAATATTTTTAATGAGGGAGGAGGTTTGAGGATGGTTGGGTTTGATTTATGATTGGAGGAGAAGGCTTATTTTTTATTGAGAAGTAGGCGATTTGTTC");
Sequence seq2 = new Sequence("2", "TOP", "test", 0,
"AAATATTTTTAATGAGGGAGGAGGTTTGAGGATGGTTGGGTTTGATTTATGATTGGAGGAGAAGGTCTATTTTTTATTGTGAAGTAGGTAATTTGTTT");
Sequence seq3 = new Sequence("3", "BOTTOM", "test", 0,
"AAACATCTCTAATAAAAAAAAAAACCCGAAAATAACTAAATTTAATTTATAACTAAAAAAACAAATCCACTTCCCACTACGAAACAAACGACCTGCTC");

seq1.addCpG(new CpGSite(26, false));
seq1.addCpG(new CpGSite(79, true));
seq1.addCpG(new CpGSite(88, false));
seq1.processSequence(ref);

seq2.addCpG(new CpGSite(26, false));
seq2.addCpG(new CpGSite(79, true));
seq2.addCpG(new CpGSite(88, true));
seq2.processSequence(ref);

seq3.addCpG(new CpGSite(27, true));
seq3.addCpG(new CpGSite(80, false));
seq3.addCpG(new CpGSite(89, true));
seq3.processSequence(ref);


assertEquals("sequence identity not equal for seq 1!", 0.978, seq1.getSequenceIdentity(), 0.001);
assertEquals("sequence identity not equal for seq 2!", 0.989, seq2.getSequenceIdentity(), 0.001);
assertEquals("sequence identity not equal for seq 3!", 0.989, seq3.getSequenceIdentity(), 0.001);

assertEquals("bisulfite conversion rate not equal for seq 1!", 0.947, seq1.getBisulConversionRate(),
0.001);
assertEquals("bisulfite conversion rate not equal for seq 2!", 0.947, seqList.get(1).getBisulConversionRate(),
assertEquals("bisulfite conversion rate not equal for seq 2!", 0.947, seq2.getBisulConversionRate(),
0.001);
assertEquals("bisulfite conversion rate not equal for seq 3!", 0.947, seqList.get(2).getBisulConversionRate(),
assertEquals("bisulfite conversion rate not equal for seq 3!", 0.965, seq3.getBisulConversionRate(),
0.001);

assertEquals("bisulfite conversion rate not equal for seq 3!",
assertEquals(
"--------------------------**---------------------------------------------------@@-------**--------",
seq1.getMethylationString());
assertEquals(
"--------------------------**---------------------------------------------------@@-------@@--------",
seqList.get(0).getMethylationString());
seq2.getMethylationString());
assertEquals(
"--------------------------@@---------------------------------------------------**-------@@--------",
seq3.getMethylationString());


String beginningPartialCpGRef = "CGAAG";
Sequence seqBPTop = new Sequence("1", "TOP", "test", 1, "GAAG");
Sequence seqBPBottom = new Sequence("1", "BOTTOM", "test", 1, "GAAG");
seqBPTop.addCpG(new CpGSite(0, true));
seqBPBottom.addCpG(new CpGSite(1, false));
seqBPTop.processSequence(beginningPartialCpGRef);
seqBPBottom.processSequence(beginningPartialCpGRef);
assertEquals("@---", seqBPTop.getMethylationString());
assertEquals("*---", seqBPBottom.getMethylationString());

String endPartialCpGRef = "GGAACG";
Sequence seqEPTop = new Sequence("1", "TOP", "test", 0, "GGAAC");
Sequence seqEPBottom = new Sequence("1", "BOTTOM", "test", 0, "AAAAC");
seqEPTop.addCpG(new CpGSite(4, true));
seqEPBottom.addCpG(new CpGSite(5, false));
seqEPTop.processSequence(endPartialCpGRef);
seqEPBottom.processSequence(endPartialCpGRef);
assertEquals("----@", seqEPTop.getMethylationString());
assertEquals("----*", seqEPBottom.getMethylationString());
}
}

0 comments on commit 16a055b

Please sign in to comment.