Skip to content

Commit

Permalink
Expand simple and twisted read pair counts.
Browse files Browse the repository at this point in the history
  • Loading branch information
hansenp committed Apr 30, 2021
1 parent 811fa2a commit 278315d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
29 changes: 18 additions & 11 deletions src/main/java/org/jax/diachromatic/count/Counter.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,17 @@ public void incrementDigestPair(DigestPair dp, ReadPair rp) {
}
dp2countsMap.put(dp, new SimpleTwistedCount());
}
if (rp.isTwisted()) {
dp2countsMap.get(dp).twisted++;
} else {
dp2countsMap.get(dp).simple++;
if (rp.getRelativeOrientationTag().equals("F1R2") || rp.getRelativeOrientationTag().equals("F2R1")) {
dp2countsMap.get(dp).simple_1++;
}
if (rp.getRelativeOrientationTag().equals("R1F2") || rp.getRelativeOrientationTag().equals("R2F1")) {
dp2countsMap.get(dp).simple_2++;
}
if (rp.getRelativeOrientationTag().equals("F1F2") || rp.getRelativeOrientationTag().equals("F2F1")) {
dp2countsMap.get(dp).twisted_1++;
}
if (rp.getRelativeOrientationTag().equals("R1R2") || rp.getRelativeOrientationTag().equals("R2R1")) {
dp2countsMap.get(dp).twisted_2++;
}
}

Expand Down Expand Up @@ -337,16 +344,16 @@ public void printInteractionCountsMapAsCountTable() throws FileNotFoundException

for (DigestPair dp : this.dp2countsMap.keySet()) {
SimpleTwistedCount cc = this.dp2countsMap.get(dp);
kInteractionCounts[cc.simple + cc.twisted]++;
kInteractionCounts[cc.simple_1 + cc.simple_2 + cc.twisted_1 + cc.twisted_2]++;
//int cnt = cc.simple + cc.twisted;
//printStream.println(dp.toString() + "\t" + cnt);
if(this.split) {
printStream.println(dp.toString() + "\t" + cc.simple + ":" + cc.twisted);
printStream.println(dp.toString() + "\t" + cc.simple_1 + ":" + cc.simple_2 + ":" + cc.twisted_1 + ":" + cc.twisted_2);
} else {
int c = cc.simple + cc.twisted;
int c = cc.simple_1 + cc.simple_2 + cc.twisted_1 + cc.twisted_2;
printStream.println(dp.toString() + "\t" + c);
}
if (cc.simple + cc.twisted == 1) {
if (cc.simple_1 + cc.simple_2 + cc.twisted_1 + cc.twisted_2 == 1) {
this.n_singleton_interactions++;
if (!dp.forward().getChromosome().equals(dp.reverse().getChromosome())) {
n_singleton_interactions_trans++;
Expand Down Expand Up @@ -392,7 +399,7 @@ public void printInteractionCountsMapInWashUSimpleTextFormat() throws FileNotFou
int reverse_digest_center = dp.reverse().getDigestStartPosition() + ((dp.reverse().getDigestEndPosition() - dp.reverse().getDigestStartPosition()) / 2);
if(LONG_RANGE_THRESHOLD<=Math.abs(reverse_digest_center - forward_digest_center)) {
SimpleTwistedCount cc = this.dp2countsMap.get(dp);
int c = cc.simple + cc.twisted;
int c = cc.simple_1 + cc.simple_2 + cc.twisted_1 + cc.twisted_2;
String coordinatesF = String.format("%s:%s-%s", dp.forward().getChromosome(),dp.forward().getDigestStartPosition(),dp.forward().getDigestEndPosition());
String coordinatesR = String.format("%s:%s-%s", dp.reverse().getChromosome(),dp.reverse().getDigestStartPosition(),dp.reverse().getDigestEndPosition());
String coordinates;
Expand Down Expand Up @@ -431,7 +438,7 @@ public void printFragmentInteractionCountsMapAsCountTable() throws FileNotFoundE
active_interacting_fragment_count++;
}
} else {
readCount = cc.simple + cc.twisted;
readCount = cc.simple_1 + cc.simple_2 + cc.twisted_1 + cc.twisted_2;
readCountsAtDigestsMap.put(dp.forward(), readCountsAtDigestsMap.get(dp.forward()) + readCount);
}
if (!readCountsAtDigestsMap.containsKey(dp.reverse())) {
Expand All @@ -441,7 +448,7 @@ public void printFragmentInteractionCountsMapAsCountTable() throws FileNotFoundE
active_interacting_fragment_count++;
}
} else {
readCount = cc.simple + cc.twisted;
readCount = cc.simple_1 + cc.simple_2 + cc.twisted_1 + cc.twisted_2;
readCountsAtDigestsMap.put(dp.reverse(), readCountsAtDigestsMap.get(dp.reverse()) + readCount);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

public class SimpleTwistedCount {

public int twisted = 0;
public int simple = 0;
public int simple_1 = 0;
public int simple_2 = 0;
public int twisted_1 = 0;
public int twisted_2 = 0;

public SimpleTwistedCount(){

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/jax/diachromatic/count/CounterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testIncrementDigestPair() {

// test whether simple and twisted read pairs are counted correctly
counter.incrementDigestPair(dp1,rp2);
assertEquals(2,counter.getSimpleTwistedCountForDigestPair(dp1).simple);
assertEquals(1,counter.getSimpleTwistedCountForDigestPair(dp1).twisted);
assertEquals(2,counter.getSimpleTwistedCountForDigestPair(dp1).simple_1 + counter.getSimpleTwistedCountForDigestPair(dp1).simple_2);
assertEquals(1,counter.getSimpleTwistedCountForDigestPair(dp1).twisted_1 + counter.getSimpleTwistedCountForDigestPair(dp1).twisted_2);
}
}

0 comments on commit 278315d

Please sign in to comment.