Skip to content

Commit 3f7a8d8

Browse files
committed
Count overall occurrences when pooling
1 parent 1779f9e commit 3f7a8d8

File tree

4 files changed

+402
-4
lines changed

4 files changed

+402
-4
lines changed

src/main/groovy/com/antigenomics/vdjtools/io/SampleWriter.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public class SampleWriter {
297297
public void write(PooledSample pooledSample, String fileName) {
298298
def printWriter = getWriter(fileName)
299299

300-
printWriter.println(header + "\tincidence\tconvergence")
300+
printWriter.println(header + "\tincidence\tconvergence\toccurrences")
301301

302302
pooledSample.each { pooledClonotype ->
303303
printWriter.println(
@@ -310,7 +310,8 @@ public class SampleWriter {
310310
pooledClonotype.clonotype."$it"
311311
},
312312
pooledClonotype.incidenceCount,
313-
pooledClonotype.diversity
313+
pooledClonotype.diversity,
314+
pooledClonotype.occurrences
314315
].flatten().join("\t"))
315316
}
316317

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.antigenomics.vdjtools.model;
2+
3+
import com.antigenomics.vdjtools.sample.Clonotype;
4+
5+
public interface CountMatrix {
6+
void update(Clonotype clonotype);
7+
8+
long getCount(Clonotype clonotype);
9+
}

src/main/java/com/antigenomics/vdjtools/pool/StoringClonotypeAggregator.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*/
4444
public class StoringClonotypeAggregator extends MaxClonotypeAggregator implements ClonotypeWrapper {
4545
private Clonotype clonotype;
46-
private int convergence;
46+
private int convergence, occurrences;
4747
private PooledSample parent;
4848
private final Set<ClonotypeKey> variants = new HashSet<>();
4949
private final ClonotypeKeyGen clonotypeKeyGen = new ClonotypeKeyGen();
@@ -52,6 +52,7 @@ protected StoringClonotypeAggregator(Clonotype clonotype, int sampleId) {
5252
super(clonotype, sampleId);
5353
this.clonotype = clonotype;
5454
this.convergence = 1;
55+
this.occurrences = 1;
5556
this.variants.add(clonotypeKeyGen.generateKey(clonotype));
5657
}
5758

@@ -63,6 +64,7 @@ protected boolean tryReplace(Clonotype clonotype, int sampleId) {
6364
convergence++;
6465
variants.add(clonotypeKey);
6566
}
67+
occurrences++;
6668

6769
if (super.tryReplace(clonotype, sampleId)) {
6870
this.clonotype = clonotype;
@@ -92,7 +94,8 @@ public void setParent(PooledSample parent) {
9294
}
9395

9496
/**
95-
* Gets the total number of convergent variants for this pooled clonotype.
97+
* Gets the total number of convergent variants for this pooled clonotype, i.e.
98+
* the total number of unique nucleotide variants in all samples.
9699
*
97100
* @return number of convergent variants.
98101
*/
@@ -101,6 +104,17 @@ public int getDiversity() {
101104
return convergence;
102105
}
103106

107+
/**
108+
* Gets the total number of clonotype occurrences - counting the total number of
109+
* nucleotide variants in all samples. Differs from diversity/convergence as the
110+
* same nucleotide variant found in two samples will be counted twice.
111+
*
112+
* @return number of occurrences
113+
*/
114+
public int getOccurrences() {
115+
return occurrences;
116+
}
117+
104118
/**
105119
* {@inheritDoc}
106120
*/

0 commit comments

Comments
 (0)