48 Commits
v4.0 ... v4.2

Author SHA1 Message Date
eugenefischer
a5a17d1f76 Revert previous commit 2022-10-01 18:23:31 -05:00
eugenefischer
0f3ab0fdd7 Section link test 2022-10-01 18:22:55 -05:00
eugenefischer
01596ef43a Rename sections 2022-10-01 18:16:08 -05:00
eugenefischer
cda25a2c62 Update performance section and TODO 2022-10-01 18:12:33 -05:00
eugenefischer
bde6da3076 fix typo 2022-10-01 16:12:21 -05:00
eugenefischer
2eede214c0 fix typo 2022-10-01 16:11:32 -05:00
eugenefischer
98ce708825 Remove questionable claim, reorder simulation experiments 2022-10-01 15:46:22 -05:00
eugenefischer
e7e85a4542 Comment out questionable claim 2022-10-01 15:44:29 -05:00
eugenefischer
c0dd2d31f2 Update version number 2022-10-01 15:21:33 -05:00
eugenefischer
cf103c5223 Add flag to enable p-value calculation 2022-10-01 14:36:22 -05:00
eugenefischer
26f66fe139 Remove outdated comments 2022-10-01 14:35:35 -05:00
eugenefischer
89295777ef Update output example 2022-10-01 14:30:46 -05:00
eugenefischer
99c92e6eb5 Update TODO 2022-10-01 14:21:23 -05:00
eugenefischer
b82176517c Update TOC, command line options 2022-10-01 13:59:03 -05:00
eugenefischer
0657db5653 tyoo 2022-10-01 13:44:17 -05:00
eugenefischer
9f0ac227e2 Clarify steps and reasoning behind the algorithm 2022-10-01 13:43:14 -05:00
eugenefischer
54896bc47f Correct typo, remove redundant information 2022-10-01 13:01:44 -05:00
eugenefischer
b19a4d37c2 Update readme with newer results, new menu options 2022-10-01 13:00:33 -05:00
eugenefischer
457d643477 Make calculation of p-values optional, defaulting to off 2022-09-30 03:17:58 -05:00
eugenefischer
593dd6c60f Add sample cell filename, cell sample size, and sample plate size to metadata 2022-09-30 02:58:15 -05:00
eugenefischer
b8aeeb988f Add sequence dropout rate to metadata output 2022-09-30 00:33:41 -05:00
eugenefischer
b9b13fb75e Rename dropout rate flag 2022-09-29 23:58:08 -05:00
eugenefischer
289220e0d0 Remove statements about pre-filtering types. Can add that back if I ever actually parameterize that. 2022-09-29 22:10:42 -05:00
eugenefischer
19badac92b Correct misstatement of filter condition in Algorithm section 2022-09-29 18:32:42 -05:00
eugenefischer
633334a1b8 Update Theory section, add Contents and Algorithm section. 2022-09-29 18:30:07 -05:00
eugenefischer
e308e47578 Correct error in comments 2022-09-29 18:29:43 -05:00
eugenefischer
133984276f Change access modifiers and add count of wells removed to output 2022-09-29 16:03:10 -05:00
eugenefischer
ec6713a1c0 Implement filtering for wells with anomalous read counts 2022-09-29 16:03:10 -05:00
097590cf21 Add method to remove a well from the SequenceRecord (git committed as past self due to IDE misclick) 2022-09-29 16:03:10 -05:00
eugenefischer
f1e4c4f194 Remove duplicate output statements 2022-09-29 01:05:36 -05:00
eugenefischer
b6218c3ed3 update version 2022-09-29 00:53:11 -05:00
eugenefischer
756e5572b9 update readme 2022-09-29 00:00:19 -05:00
eugenefischer
c30167d5ec Change real sequence collision so it isn't biased toward sequences in the earlier wells. 2022-09-28 23:15:55 -05:00
eugenefischer
a19525f5bb update readme 2022-09-28 23:01:59 -05:00
eugenefischer
e5803defa3 Bug fix, add comments 2022-09-28 18:09:47 -05:00
eugenefischer
34dc2a5721 Add real sequence collision rate 2022-09-28 17:54:55 -05:00
eugenefischer
fd106a0d73 Add real sequence collision rate 2022-09-28 17:46:09 -05:00
eugenefischer
22faad3414 Add real sequence collision rate 2022-09-28 17:45:09 -05:00
eugenefischer
0b36e2b742 Rewrite countSequences to allow for collision with real sequences on misreads 2022-09-28 17:44:26 -05:00
eugenefischer
9dacd8cd34 Add real sequence collision rate 2022-09-28 17:43:21 -05:00
eugenefischer
89687fa849 Add real sequence collision rate, make fields final 2022-09-28 17:43:06 -05:00
eugenefischer
fb443fe958 Revert "Add getCell and getRandomCell methods"
This reverts commit adebe1542e.
2022-09-28 14:36:20 -05:00
eugenefischer
adebe1542e Add getCell and getRandomCell methods 2022-09-28 13:49:50 -05:00
eugenefischer
882fbfffc6 Purge old code 2022-09-28 13:40:13 -05:00
eugenefischer
a88cfb8b0d Add read counts for individual wells to graphml output 2022-09-28 13:38:38 -05:00
eugenefischer
deed98e79d Bugfix 2022-09-28 12:58:14 -05:00
eugenefischer
1a35600f50 Add method to get read count from individual wells 2022-09-28 12:57:45 -05:00
eugenefischer
856063529b Read depth simulation is now compatible with plate caching 2022-09-28 12:47:00 -05:00
12 changed files with 611 additions and 311 deletions

400
readme.md
View File

@@ -1,5 +1,25 @@
# BiGpairSEQ SIMULATOR
## CONTENTS
1. ABOUT
2. THEORY
3. THE BiGpairSEQ ALGORITHM
4. USAGE
1. RUNNING THE PROGRAM
2. COMMAND LINE OPTIONS
3. INTERACTIVE INTERFACE
4. INPUT/OUTPUT
1. Cell Sample Files
2. Sample Plate Files
3. Graph/Data Files
4. Matching Results Files
5. RESULTS
1. SAMPLE PLATES WITH VARYING NUMBERS OF CELLS PER WELL
2. SIMULATING EXPERIMENTS FROM pairSEQ PAPER
6. TODO
7. CITATIONS
8. ACKNOWLEDGEMENTS
9. AUTHOR
## ABOUT
@@ -8,26 +28,77 @@ of the pairSEQ algorithm (Howie, et al. 2015) for pairing T cell receptor sequen
## THEORY
Unlike pairSEQ, which calculates p-values for every TCR alpha/beta overlap and compares
against a null distribution, BiGpairSEQ does not do any statistical calculations
directly.
T cell receptors (TCRs) are encoded by pairs of sequences, alpha sequences (TCRAs) and beta sequences (TCRBs). These sequences
are extremely diverse; to the first approximation, this pair of sequences uniquely identifies a line of T cells.
As described in the original 2015 paper, pairSEQ pairs TCRAs and TCRBs by distributing a
sample of T cells across a 96-well sample plate, then sequencing the contents of each well. It then calculates p-values for
every TCRA/TCRB sequence overlap and compares that against a null distribution, to find the most statistically probable pairings.
BiGpairSEQ uses the same fundamental idea of using occupancy overlap to pair TCR sequences, but unlike pairSEQ it
does not require performing any statistical calculations at all. Instead, BiGpairSEQ uses graph theory methods which
produce provably optimal solutions.
BiGpairSEQ creates a [weighted bipartite graph](https://en.wikipedia.org/wiki/Bipartite_graph) representing the sample plate.
The distinct TCRA and TCRB sequences form the two sets of vertices. Every TCRA/TCRB pair that share a well
are connected by an edge, with the edge weight set to the number of wells in which both sequences appear.
(Sequences present in *all* wells are filtered out prior to creating the graph, as there is no signal in their occupancy pattern.)
The problem of pairing TCRA/TCRB sequences thus reduces to the "assignment problem" of finding a maximum weight
matching on a bipartite graph--the subset of vertex-disjoint edges whose weights sum to the maximum possible value.
The distinct TCRA and TCRB sequences form the two sets of vertices. Every TCRA/TCRB pair that share a well on the sample plate
are connected by an edge in the graph, with the edge weight set to the number of wells in which both sequences appear. The vertices
themselves are labeled with the occupancy data for the individual sequences they represent, which is useful for pre-filtering
before finding a maximum weight matching. Such a graph fully encodes the distribution data from the sample plate.
This is a well-studied combinatorial optimization problem, with many known solutions.
The most efficient algorithm known to the author for maximum weight matching of a bipartite graph with strictly integral
weights is from Duan and Su (2012). For a graph with m edges, n vertices per side, and maximum integer edge weight N,
their algorithm runs in **O(m sqrt(n) log(N))** time. As the graph representation of a pairSEQ experiment is
bipartite with integer weights, this algorithm is ideal for BiGpairSEQ.
The problem of pairing TCRA/TCRB sequences thus reduces to the [assignment problem](https://en.wikipedia.org/wiki/Assignment_problem) of finding a maximum weight
matching (MWM) on a bipartite graph--the subset of vertex-disjoint edges whose weights sum to the maximum possible value.
Unfortunately, it's a fairly new algorithm, and not yet implemented by the graph theory library used in this simulator.
So this program instead uses the Fibonacci heap-based algorithm of Fredman and Tarjan (1987), which has a worst-case
runtime of **O(n (n log(n) + m))**. The algorithm is implemented as described in Melhorn and Näher (1999).
This is a well-studied combinatorial optimization problem, with many known algorithms that produce
provably-optimal solutions. The most theoretically efficient algorithm known to the author for maximum weight matching of a bipartite
graph with strictly integral weights is from Duan and Su (2012). For a graph with m edges, n vertices per side,
and maximum integer edge weight N, their algorithm runs in **O(m sqrt(n) log(N))** time. As the graph representation of
a pairSEQ experiment is bipartite with integer weights, this algorithm seems ideal for BiGpairSEQ. Unfortunately, it's a
fairly new algorithm, and not yet implemented by the graph theory library used in this simulator (JGraphT), nor has the author had
time to implement it himself.
There have been some studies which show that [auction algorithms](https://en.wikipedia.org/wiki/Auction_algorithm) for the assignment problem can have superior performance in
real-world implementations, due to their simplicity, than more complex algorithms with better theoretical asymptotic
performance. But, again, there is no such algorithms implemented by JGraphT, nor has the author yet had time to implement one.
So this program instead uses the [Fibonacci heap](https://en.wikipedia.org/wiki/Fibonacci_heap) based algorithm of Fredman and Tarjan (1987) (essentially
[the Hungarian algorithm](https://en.wikipedia.org/wiki/Hungarian_algorithm) augmented with a more efficeint priority queue) which has a worst-case
runtime of **O(n (n log(n) + m))**. The algorithm is implemented as described in Melhorn and Näher (1999). (The simulator
allows the substitution of a [pairing heap](https://en.wikipedia.org/wiki/Pairing_heap) for a Fibonacci heap, though the relative performance difference of the two
has not yet been thoroughly tested.)
One possible advantage of this less efficient algorithm is that the Hungarian algorithm and its variations work with both the balanced and the unbalanced assignment problem
(that is, cases where both sides of the bipartite graph have the same number of vertices and those in which they don't.)
Many other MWM algorithms only work for the balanced assignment problem. While pairSEQ-style experiments should theoretically
be balanced assignment problems, in practice sequence dropout can cause them to be unbalanced. The unbalanced case
*can* be reduced to the balanced case, but doing so involves doubling the graph size. Since the current implementation uses only
the Hungarian algorithm, graph doubling--which could be challenging with the computational resources available to the
author--has not yet been necessary.
The relative time/space efficiencies of BiGpairSEQ when backed by different MWM algorithms remains an open problem.
## THE BiGpairSEQ ALGORITHM
1. Sequence a sample plate of T cells as in pairSEQ.
2. Pre-filter the sequence data to reduce error and minimize the size of the necessary graph.
1. *Saturating sequence filter*: remove any sequences present in all wells on the sample plate, as there is no signal in the occupancy data of saturating sequences (and each saturating sequence will have an edge to every vertex on the opposite side of the graph, vastly increasing the total graph size).
2. *Non-existent sequence filter*: sequencing misreads can pollute the data from the sample plate with non-existent sequences. These can be identified by the discrepancy between their occupancy and their total read count. Assuming sequences are read correctly at least half the time, then a sequence's total read count (R) should be at least half the well occupancy of that sequence (O) times the read depth of the sequencing run (D). Remove any sequences for which R < (O * D) / 2.
3. *Misidentified sequence filter*: sequencing misreads can cause one real sequence to be misidentified as a different real sequence. This should be fairly infrequent, but is a problem if it skews a sequence's overall occupancy pattern by causing the sequence to seem to be in a well where it's not. This can be detected by looking for discrepancies in a sequence's per-well read count. On average, the read count for a sequence in an individual well (r) should be equal to its total read count (R) divided by its total well occupancy (O). Remove from the list of wells occupied by a sequence any wells for which r < R / (2 * O).
3. Encode the occupancy data from the sample plate as a weighted bipartite graph, where one set of vertices represent the distinct TCRAs and the other set represents distinct TCRBs. Between any TCRA and TCRB that share a well, draw an edge. Assign that edge a weight equal to the total number of wells shared by both sequences.
4. Find a maximum weight matching of the bipartite graph, using any [MWM algorithm](https://en.wikipedia.org/wiki/Assignment_problem#Algorithms) that produces a provably optimal result.
* If desired, restrict the matching to a subset of the graph. (Example: restricting matching attempts to cases where the occupancy overlap is 4 or more wells--that is, edges with weight >= 4.0.) See below for discussion of why this might be desirable.
5. The resultant matching represents the likeliest TCRA/TCRB sequence pairs based on the occupancy pattern of the sample plate.
It is important to note that a maximum weight matching is not necessarily unique. If two different sets of vertex-disjoint edges
sum to the same maximal weight, then a MWM algorithms might find either one of them.
For example, consider a well that contains four rare sequences found only in that well, two TCRAs and two TCRBs.
In the graph, both of those TCRAs would have edges to both TCRBs (and to others of course, but since those edges will have a weight of 1.0,
they are unlikely be paired in a MWM to sequences with total occupancy of more than one well). If these four sequences
represent two unique T cells, then only one of the two possible pairings between these sequences is correct. But both
the correct and incorrect pairing will add 2.0 to the total graph weight, so either one could be part of a maximum weight matching.
It is to minimize the number of possible equivalent-weight matchings that one might restrict the algorithm to examining
only a subset of the graph, as described in step 4 above.
## USAGE
@@ -48,11 +119,117 @@ For example, to run the program with 32 gigabytes of memory, use the command:
`java -Xmx32G -jar BiGpairSEQ_Sim.jar`
There are a number of command line options, to allow the program to be used in shell scripts. For a full list,
use the `-help` flag:
### COMMAND LINE OPTIONS
There are a number of command line options, to allow the program to be used in shell scripts. These can be viewed with
the `-help` flag:
`java -jar BiGpairSEQ_Sim.jar -help`
```
usage: BiGpairSEQ_Sim.jar
-cells,--make-cells Makes a cell sample file of distinct T cells
-graph,--make-graph Makes a graph/data file. Requires a cell sample
file and a sample plate file
-help Displays this help menu
-match,--match-cdr3 Matches CDR3s. Requires a graph/data file.
-plate,--make-plate Makes a sample plate file. Requires a cell sample
file.
-version Prints the program version number to stdout
usage: BiGpairSEQ_Sim.jar -cells
-d,--diversity-factor <factor> The factor by which unique CDR3s
outnumber unique CDR1s
-n,--num-cells <number> The number of distinct cells to generate
-o,--output-file <filename> Name of output file
usage: BiGpairSEQ_Sim.jar -plate
-c,--cell-file <filename> The cell sample file to use
-d,--dropout-rate <rate> The sequence dropout rate due to
amplification error. (0.0 - 1.0)
-exponential Use an exponential distribution for cell
sample
-gaussian Use a Gaussian distribution for cell sample
-lambda <value> If using -exponential flag, lambda value
for distribution
-o,--output-file <filename> Name of output file
-poisson Use a Poisson distribution for cell sample
-pop <number [number]...> The well populations for each section of
the sample plate. There will be as many
sections as there are populations given.
-random <min> <max> Randomize well populations on sample plate.
Takes two arguments: the minimum possible
population and the maximum possible
population.
-stddev <value> If using -gaussian flag, standard deviation
for distrbution
-w,--wells <number> The number of wells on the sample plate
usage: BiGpairSEQ_Sim.jar -graph
-c,--cell-file <filename> Cell sample file to use for
checking pairing accuracy
-err,--read-error-prob <prob> (Optional) The probability that
a sequence will be misread. (0.0
- 1.0)
-errcoll,--error-collision-prob <prob> (Optional) The probability that
two misreads will produce the
same spurious sequence. (0.0 -
1.0)
-graphml (Optional) Output GraphML file
-nb,--no-binary (Optional) Don't output
serialized binary file
-o,--output-file <filename> Name of output file
-p,--plate-filename <filename> Sample plate file from which to
construct graph
-rd,--read-depth <depth> (Optional) The number of times
to read each sequence.
-realcoll,--real-collision-prob <prob> (Optional) The probability that
a sequence will be misread as
another real sequence. (Only
applies to unique misreads;
after this has happened once,
future error collisions could
produce the real sequence again)
(0.0 - 1.0)
usage: BiGpairSEQ_Sim.jar -match
-g,--graph-file <filename> The graph/data file to use
-max <number> The maximum number of shared wells to
attempt to match a sequence pair
-maxdiff <number> (Optional) The maximum difference in total
occupancy between two sequences to attempt
matching.
-min <number> The minimum number of shared wells to
attempt to match a sequence pair
-minpct <percent> (Optional) The minimum percentage of a
sequence's total occupancy shared by
another sequence to attempt matching. (0 -
100)
-o,--output-file <filename> (Optional) Name of output the output file.
If not present, no file will be written.
--print-alphas (Optional) Print the number of distinct
alpha sequences to stdout.
--print-attempt (Optional) Print the pairing attempt rate
to stdout
--print-betas (Optional) Print the number of distinct
beta sequences to stdout.
--print-correct (Optional) Print the number of correct
pairs to stdout
--print-error (Optional) Print the pairing error rate to
stdout
--print-incorrect (Optional) Print the number of incorrect
pairs to stdout
--print-metadata (Optional) Print a full summary of the
matching results to stdout.
--print-time (Optional) Print the total simulation time
to stdout.
-pv,--p-value (Optional) Calculate p-values for sequence
pairs.
```
### INTERACTIVE INTERFACE
If no command line arguments are given, BiGpairSEQ_Sim will launch with an interactive, menu-driven CLI for
generating files and simulating TCR pairing. The main menu looks like this:
@@ -79,7 +256,8 @@ By default, the Options menu looks like this:
3) Turn on graph/data file caching
4) Turn off serialized binary graph output
5) Turn on GraphML graph output
6) Maximum weight matching algorithm options
6) Turn on calculation of p-values
7) Maximum weight matching algorithm options
0) Return to main menu
```
@@ -96,7 +274,7 @@ These files are often generated in sequence. When entering filenames, it is not
(.csv or .ser). When reading or writing files, the program will automatically add the correct extension to any filename
without one.
To save file I/O time, the most recent instance of each of these four
To save file I/O time when using the interactive interface, the most recent instance of each of these four
files either generated or read from disk can be cached in program memory. When caching is active, subsequent uses of the
same data file won't need to be read in again until another file of that type is used or generated,
or caching is turned off for that file type. The program checks whether it needs to update its cached data by comparing
@@ -116,7 +294,7 @@ turned on in the Options menu. By default, GraphML output is OFF.
Cell Sample files consist of any number of distinct "T cells." Every cell contains
four sequences: Alpha CDR3, Beta CDR3, Alpha CDR1, Beta CDR1. The sequences are represented by
random integers. CDR3 Alpha and Beta sequences are all unique within a given Cell Sample file. CDR1 Alpha and Beta sequences
are not necessarily unique; the relative diversity can be set when making the file.
are not necessarily unique; the relative diversity of CRD1s with respect to CDR3s can be set when making the file.
(Note: though cells still have CDR1 sequences, matching of CDR1s is currently awaiting re-implementation.)
@@ -133,7 +311,7 @@ Structure:
| Alpha CDR3 | Beta CDR3 | Alpha CDR1 | Beta CDR1 |
|---|---|---|---|
|unique number|unique number|number|number|
| ... | ... |... | ... |
---
#### Sample Plate Files
@@ -142,7 +320,8 @@ described above). The wells are filled randomly from a Cell Sample file, accordi
frequency distribution. Additionally, every individual sequence within each cell may, with some
given dropout probability, be omitted from the file; this simulates the effect of amplification errors
prior to sequencing. Plates can also be partitioned into any number of sections, each of which can have a
different concentration of T cells per well.
different concentration of T cells per well. Alternatively, the number of T cells in each well can be randomized between
given minimum and maximum population values.
Options when making a Sample Plate file:
* Cell Sample file to use
@@ -152,7 +331,6 @@ Options when making a Sample Plate file:
* Standard deviation size
* Exponential
* Lambda value
* *(Based on the slope of the graph in Figure 4C of the pairSEQ paper, the distribution of the original experiment was approximately exponential with a lambda ~0.6. (Howie, et al. 2015))*
* Total number of wells on the plate
* Well populations random or fixed
* If random, minimum and maximum population sizes
@@ -160,7 +338,7 @@ Options when making a Sample Plate file:
* Number of sections on plate
* Number of T cells per well
* per section, if more than one section
* Dropout rate
* Sequence dropout rate
Files are in CSV format. There are no header labels. Every row represents a well.
Every value represents an individual cell, containing four sequences, depicted as an array string:
@@ -199,11 +377,12 @@ then use it for multiple different BiGpairSEQ simulations.
Options for creating a Graph/Data file:
* The Cell Sample file to use
* The Sample Plate file to use. (This must have been generated from the selected Cell Sample file.)
* Whether to simulate sequence read depth. If simulated:
* The read depth (number of times each sequence is read)
* The read error rate (probability a sequence is misread)
* The error collision rate (probability two misreads produce the same spurious sequence)
* The Sample Plate file to use (This must have been generated from the selected Cell Sample file.)
* Whether to simulate sequencing read depth. If simulated:
* The read depth (The number of times each sequence is read)
* The read error rate (The probability a sequence is misread)
* The error collision rate (The probability two misreads produce the same spurious sequence)
* The real sequence collision rate (The probability that a misread will produce a different, real sequence from the sample plate. Only applies to new misreads; once an error of this type has occurred, it's likelihood of occurring again is dominated by the error collision probability.)
These files do not have a human-readable structure, and are not portable to other programs.
@@ -211,8 +390,8 @@ These files do not have a human-readable structure, and are not portable to othe
For portability of graph data to other software, turn on [GraphML](http://graphml.graphdrawing.org/index.html) output
in the Options menu in interactive mode, or use the `-graphml`command line argument. This will produce a .graphml file
for the weighted graph, with vertex attributes for sequence, type, and occupancy data. This graph contains all the data
necessary for the BiGpairSEQ matching algorithm. It does not include the data to measure pairing accuracy; for that,
for the weighted graph, with vertex attributes for sequence, type, total occupancy, total read count, and the read count for every individual occupied well.
This graph contains all the data necessary for the BiGpairSEQ matching algorithm. It does not include the data to measure pairing accuracy; for that,
compare the matching results to the original Cell Sample .csv file.
---
@@ -220,7 +399,7 @@ compare the matching results to the original Cell Sample .csv file.
#### Matching Results Files
Matching results files consist of the results of a BiGpairSEQ matching simulation. Making them requires a serialized
binary Graph/Data file (.ser). (Because .graphML files are larger than .ser files, BiGpairSEQ_Sim supports .graphML
output only. Graph/data input must use a serialized binary.)
output only. Graph input must use a serialized binary.)
Matching results files are in CSV format. Rows are sequence pairings with extra relevant data. Columns are pairing-specific details.
Metadata about the matching simulation is included as comments. Comments are preceded by `#`.
@@ -238,56 +417,65 @@ Options when running a BiGpairSEQ simulation of CDR3 alpha/beta matching:
Example output:
```
# Source Sample Plate file: 4MilCellsPlate.csv
# Source Graph and Data file: 4MilCellsPlateGraph.ser
# T cell counts in sample plate wells: 30000
# Total alphas found: 11813
# Total betas found: 11808
# High overlap threshold: 94
# Low overlap threshold: 3
# Minimum overlap percent: 0
# Maximum occupancy difference: 96
# Pairing attempt rate: 0.438
# Correct pairings: 5151
# Incorrect pairings: 18
# Pairing error rate: 0.00348
# Simulation time: 862 seconds
# cell sample filename: 8MilCells.csv
# cell sample size: 8000000
# sample plate filename: 8MilCells_Plate.csv
# sample plate well count: 96
# sequence dropout rate: 0.1
# graph filename: 8MilGraph_rd2
# MWM algorithm type: LEDA book with heap: FIBONACCI
# matching weight: 218017.0
# well populations: 4000
# sequence read depth: 100
# sequence read error rate: 0.01
# read error collision rate: 0.1
# real sequence collision rate: 0.05
# total alphas read from plate: 323711
# total betas read from plate: 323981
# alphas in graph (after pre-filtering): 11707
# betas in graph (after pre-filtering): 11705
# high overlap threshold for pairing: 95
# low overlap threshold for pairing: 3
# minimum overlap percent for pairing: 0
# maximum occupancy difference for pairing: 2147483647
# pairing attempt rate: 0.716
# correct pairing count: 8373
# incorrect pairing count: 7
# pairing error rate: 0.000835
# time to generate graph (seconds): 293
# time to pair sequences (seconds): 1,416
# total simulation time (seconds): 1,709
```
| Alpha | Alpha well count | Beta | Beta well count | Overlap count | Matched Correctly? | P-value |
|---|---|---|---|---|---|---|
|5242972|17|1571520|18|17|true|1.41E-18|
|5161027|18|2072219|18|18|true|7.31E-20|
|4145198|33|1064455|30|29|true|2.65E-21|
|7700582|18|112748|18|18|true|7.31E-20|
|10258642|73|1172093|72|70.0|true|4.19E-21|
|6186865|34|4290363|37|34.0|true|4.56E-26|
|10222686|70|11044018|72|68.0|true|9.55E-25|
|5338100|75|2422988|76|74.0|true|4.57E-22|
|12363907|33|6569852|35|33.0|true|5.70E-26|
|...|...|...|...|...|...|...|
---
**NOTE: The p-values in the output are not used for matching**—they aren't part of the BiGpairSEQ algorithm at all.
P-values are calculated *after* BiGpairSEQ matching is completed, for purposes of comparison only,
using the (2021 corrected) formula from the original pairSEQ paper. (Howie, et al. 2015)
**NOTE: The p-values in the sample output above are not used for matching**—they aren't part of the BiGpairSEQ algorithm at all.
P-values (if enabled in the interactive menu options or by using the -pv flag on the command line) are calculated *after*
BiGpairSEQ matching is completed, for purposes of comparison with pairSEQ only, using the (corrected) formula from the
original pairSEQ paper. (Howie, et al. 2015) Calculation of p-values is off by default to reduce processing time.
## PERFORMANCE (old results; need updating to reflect current, improved simulator performance)
## RESULTS
On a home computer with a Ryzen 5600X CPU, 64GB of 3200MHz DDR4 RAM (half of which was allocated to the Java Virtual Machine), and a PCIe 3.0 SSD, running Linux Mint 20.3 Edge (5.13 kernel),
the author ran a BiGpairSEQ simulation of a 96-well sample plate with 30,000 T cells/well comprising ~11,800 alphas and betas,
taken from a sample of 4,000,000 distinct cells with an exponential frequency distribution (lambda 0.6).
Several BiGpairSEQ simulations were performed on a home computer with the following specs:
With min/max occupancy threshold of 3 and 94 wells for matching, and no other pre-filtering, BiGpairSEQ identified 5,151
correct pairings and 18 incorrect pairings, for an accuracy of 99.652%.
* Ryzen 5600X CPU
* 128GB of 3200MHz DDR4 RAM
* 2TB PCIe 3.0 SSD
* Linux Mint 21 (5.15 kernel)
The total simulation time was 14'22". If intermediate results were held in memory, this would be equivalent to the total elapsed time.
Since this implementation of BiGpairSEQ writes intermediate results to disk (to improve the efficiency of *repeated* simulations
with different filtering options), the actual elapsed time was greater. File I/O time was not measured, but took
slightly less time than the simulation itself. Real elapsed time from start to finish was under 30 minutes.
As mentioned in the theory section, performance could be improved by implementing a more efficient algorithm for finding
the maximum weight matching.
## BEHAVIOR WITH RANDOMIZED WELL POPULATIONS
### SAMPLE PLATES WITH VARYING NUMBERS OF CELLS PER WELL
NOTE: these results were obtained with an earlier version of BiGpairSEQ_Sim, and should be re-run with the current version.
The observed behavior is not believed to be likely to change, however.
A series of BiGpairSEQ simulations were conducted using a cell sample file of 3.5 million unique T cells. From these cells,
10 sample plate files were created. All of these sample plates had 96 wells, used an exponential distribution with a lambda of 0.6, and
@@ -332,6 +520,70 @@ The average results for the randomized plates are closest to the constant plate
This and several other tests indicate that BiGpairSEQ treats a sample plate with a highly variable number of T cells/well
roughly as though it had a constant well population equal to the plate's average well population.
### SIMULATING EXPERIMENTS FROM THE 2015 pairSEQ PAPER
#### Experiment 1
This simulation was an attempt to replicate the conditions of experiment 1 from the 2015 pairSEQ paper: a matching was found for a
96-well sample plate with 4,000 T cells/well, taken from a sample of 8,400,000
distinct cells sampled with an exponential frequency distribution. Examination of Figure 4C from the paper seems to show the points
(-5, 4) and (-4.5, 3.3) on the line at the boundary of the shaded region, so a lambda value of 1.4 was used for the
exponential distribution.
The sequence dropout rate was 10%, as the analysis in the paper concluded that most TCR
sequences "have less than a 10% chance of going unobserved." (Howie, et al. 2015) Given this choice of 10%, the simulated
sample plate is likely to have more sequence dropout, and thus greater error, than the real experiment.
The original paper does not contain (or the author of this document failed to identify) information on sequencing depth,
read error probability, or the probabilities of different kinds of read error collisions. As the pre-filtering of BiGpairSEQ
has successfully filtered out all such errors for any reasonable error rates the author has yet tested, this simulation was
done without simulating any sequencing errors, to reduce the processing time.
This simulation was performed 5 times with min/max occupancy thresholds of 3 and 95 wells respectively for matching.
| |Run 1|Run 2|Run 3|Run 4|Run 5| Average|
|---|---|---|---|---|---|---|
|Total pairs|4398|4420|4404|4409|4414|4409|
|Correct pairs|4322|4313|4337|4336|4339|4329.4|
|Incorrect pairs|76|107|67|73|75|79.6|
|Error rate|0.0173|0.0242|0.0152|0.0166|0.0170|0.018|
|Simulation time (seconds)|697|484|466|473|463|516.6|
The experiment in the original paper called 4143 pairs with a false discovery rate of 0.01.
Given the roughness of the estimation for the cell frequency distribution of the original experiment and the likely
higher rate of sequence dropout in the simulation, these simulated results match the real experiment fairly well.
#### Experiment 3
To simulate experiment 3 from the original paper, a matching was made for a 96-well sample plate with 160,000 T cells/well,
taken from a sample of 4.5 million distinct T cells sampled with an exponential frequency distribution (lambda 1.4). The
sequence dropout rate was again 10%, and no sequencing errors were simulated. Once again, deviation from the original
experiment is expected due to the roughness of the estimated frequency distribution, and due to the high sequence dropout
rate.
Results metadata:
```
# total alphas read from plate: 6929
# total betas read from plate: 6939
# alphas in graph (after pre-filtering): 4452
# betas in graph (after pre-filtering): 4461
# high overlap threshold for pairing: 95
# low overlap threshold for pairing: 3
# minimum overlap percent for pairing: 0
# maximum occupancy difference for pairing: 100
# pairing attempt rate: 0.767
# correct pairing count: 3233
# incorrect pairing count: 182
# pairing error rate: 0.0533
# time to generate graph (seconds): 40
# time to pair sequences (seconds): 230
# total simulation time (seconds): 270
```
The simulation ony found 6929 distinct TCRAs and 6939 TCRBs on the sample plate, orders of magnitude fewer than the number of
pairs called in the pairSEQ experiment. These results show that at very high sampling depths, the differences in the
underlying frequency distribution drastically affect the results. The real distribution clearly has a much longer "tail"
than the simulated exponential distribution. Implementing a way to exert finer control over the sampling distribution from
the file of distinct cells may enable better simulated replication of this experiment.
## TODO
* ~~Try invoking GC at end of workloads to reduce paging to disk~~ DONE
@@ -361,8 +613,12 @@ roughly as though it had a constant well population equal to the plate's average
* ~~Add read depth simulation options to CLI~~ DONE
* ~~Update graphml output to reflect current Vertex class attributes~~ DONE
* Individual well data from the SequenceRecords could be included, if there's ever a reason for it
* ~~Implement simulation of sequences being misread as other real sequence~~ DONE
* Update matching metadata output options in CLI
* Add frequency distribution details to metadata output
* need to make an enum for the different distribution types and refactor the Plate class and user interfaces, also add the necessary fields to GraphWithMapData and then call if from Simulator
* Update performance data in this readme
* Add section to ReadMe describing data filtering methods.
* Re-implement CDR1 matching method
* Refactor simulator code to collect all needed data in a single scan of the plate
* Currently it scans once for the vertices and then again for the edge weights. This made simulating read depth awkward, and incompatible with caching of plate files.
@@ -377,7 +633,7 @@ roughly as though it had a constant well population equal to the plate's average
* Implement Vose's alias method for arbitrary statistical distributions of cells
* Should probably refactor to use apache commons rng for this
* Use commons JCS for caching
* Parameterize pre-filtering. Currently, sequences present in all wells are filtered out before constructing the graph, which massively reduces graph size. But, ideally, no pre-filtering would be necessary.
* Parameterize pre-filtering options
## CITATIONS
@@ -397,4 +653,4 @@ BiGpairSEQ was conceived in collaboration with Dr. Alice MacQueen, who brought t
pairSEQ paper to the author's attention and explained all the biology terms he didn't know.
## AUTHOR
BiGpairSEQ algorithm and simulation by Eugene Fischer, 2021. UI improvements and documentation, 2022.
BiGpairSEQ algorithm and simulation by Eugene Fischer, 2021. Improvements and documentation, 2022.

View File

@@ -16,7 +16,8 @@ public class BiGpairSEQ {
private static HeapType priorityQueueHeapType = HeapType.FIBONACCI;
private static boolean outputBinary = true;
private static boolean outputGraphML = false;
private static final String version = "version 3.0";
private static boolean calculatePValue = false;
private static final String version = "version 4.2";
public static void main(String[] args) {
if (args.length == 0) {
@@ -173,5 +174,9 @@ public class BiGpairSEQ {
public static boolean outputGraphML() {return outputGraphML;}
public static void setOutputGraphML(boolean b) {outputGraphML = b;}
public static boolean calculatePValue() {return calculatePValue; }
public static void setCalculatePValue(boolean b) {calculatePValue = b; }
public static String getVersion() { return version; }
}

View File

@@ -58,7 +58,9 @@ public class CellFileReader {
}
public CellSample getCellSample() {
return new CellSample(distinctCells, cdr1Freq);
CellSample sample = new CellSample(distinctCells, cdr1Freq);
sample.setFilename(filename);
return sample;
}
public String getFilename() { return filename;}

View File

@@ -7,6 +7,7 @@ public class CellSample {
private List<String[]> cells;
private Integer cdr1Freq;
private String filename;
public CellSample(Integer numDistinctCells, Integer cdr1Freq){
this.cdr1Freq = cdr1Freq;
@@ -38,6 +39,7 @@ public class CellSample {
distinctCells.add(tmp);
}
this.cells = distinctCells;
this.filename = filename;
}
public CellSample(List<String[]> cells, Integer cdr1Freq){
@@ -57,4 +59,8 @@ public class CellSample {
return cells.size();
}
public String getFilename() { return filename; }
public void setFilename(String filename) { this.filename = filename; }
}

View File

@@ -48,6 +48,7 @@ import java.util.stream.Stream;
* minpercent : (optional) the minimum percent overlap to attempt a matching.
* writefile : (optional) the filename to write results to
* output : the values to print to System.out for piping
* pv : (optional) calculate p-values
*
*/
public class CommandLineInterface {
@@ -96,7 +97,7 @@ public class CommandLineInterface {
Integer[] populations;
String outputFilename = line.getOptionValue("o");
Integer numWells = Integer.parseInt(line.getOptionValue("w"));
Double dropoutRate = Double.parseDouble(line.getOptionValue("err"));
Double dropoutRate = Double.parseDouble(line.getOptionValue("d"));
if (line.hasOption("random")) {
//Array holding values of minimum and maximum populations
Integer[] min_max = Stream.of(line.getOptionValues("random"))
@@ -150,16 +151,21 @@ public class CommandLineInterface {
Integer readDepth = 1;
Double readErrorRate = 0.0;
Double errorCollisionRate = 0.0;
Double realSequenceCollisionRate = 0.0;
if (line.hasOption("rd")) {
readDepth = Integer.parseInt(line.getOptionValue("rd"));
}
if (line.hasOption("err")) {
readErrorRate = Double.parseDouble(line.getOptionValue("err"));
}
if (line.hasOption("coll")) {
errorCollisionRate = Double.parseDouble(line.getOptionValue("coll"));
if (line.hasOption("errcoll")) {
errorCollisionRate = Double.parseDouble(line.getOptionValue("errcoll"));
}
graph = Simulator.makeCDR3Graph(cells, plate, readDepth, readErrorRate, errorCollisionRate, false);
if (line.hasOption("realcoll")) {
realSequenceCollisionRate = Double.parseDouble(line.getOptionValue("realcoll"));
}
graph = Simulator.makeCDR3Graph(cells, plate, readDepth, readErrorRate, errorCollisionRate,
realSequenceCollisionRate, false);
if (!line.hasOption("no-binary")) { //output binary file unless told not to
GraphDataObjectWriter writer = new GraphDataObjectWriter(outputFilename, graph, false);
writer.writeDataToFile();
@@ -197,9 +203,12 @@ public class CommandLineInterface {
else {
maxOccupancyDiff = Integer.MAX_VALUE;
}
if (line.hasOption("pv")) {
BiGpairSEQ.setCalculatePValue(true);
}
GraphWithMapData graph = getGraph(graphFilename);
MatchingResult result = Simulator.matchCDR3s(graph, graphFilename, minThreshold, maxThreshold,
maxOccupancyDiff, minOverlapPct, false);
maxOccupancyDiff, minOverlapPct, false, BiGpairSEQ.calculatePValue());
if(outputFilename != null){
MatchingFileWriter writer = new MatchingFileWriter(outputFilename, result);
writer.writeResultsToFile();
@@ -362,7 +371,8 @@ public class CommandLineInterface {
.hasArgs()
.argName("number [number]...")
.build();
Option dropoutRate = Option.builder("err") //add this to plate options
Option dropoutRate = Option.builder("d") //add this to plate options
.longOpt("dropout-rate")
.hasArg()
.desc("The sequence dropout rate due to amplification error. (0.0 - 1.0)")
.argName("rate")
@@ -413,12 +423,20 @@ public class CommandLineInterface {
.hasArg()
.argName("prob")
.build();
Option errorCollisionProb = Option.builder("coll")
Option errorCollisionProb = Option.builder("errcoll")
.longOpt("error-collision-prob")
.desc("(Optional) The probability that two misreads will produce the same spurious sequence. (0.0 - 1.0)")
.hasArg()
.argName("prob")
.build();
Option realSequenceCollisionProb = Option.builder("realcoll")
.longOpt("real-collision-prob")
.desc("(Optional) The probability that a sequence will be misread " +
"as another real sequence. (Only applies to unique misreads; after this has happened once, " +
"future error collisions could produce the real sequence again) (0.0 - 1.0)")
.hasArg()
.argName("prob")
.build();
graphOptions.addOption(cellFilename);
graphOptions.addOption(plateFilename);
graphOptions.addOption(outputFileOption());
@@ -427,6 +445,7 @@ public class CommandLineInterface {
graphOptions.addOption(readDepth);
graphOptions.addOption(readErrorProb);
graphOptions.addOption(errorCollisionProb);
graphOptions.addOption(realSequenceCollisionProb);
return graphOptions;
}
@@ -464,12 +483,17 @@ public class CommandLineInterface {
.argName("filename")
.desc("(Optional) Name of output the output file. If not present, no file will be written.")
.build();
Option pValue = Option.builder("pv") //can't call the method this time, because this one's optional
.longOpt("p-value")
.desc("(Optional) Calculate p-values for sequence pairs.")
.build();
matchCDR3options.addOption(graphFilename)
.addOption(minOccupancyOverlap)
.addOption(maxOccupancyOverlap)
.addOption(minOverlapPercent)
.addOption(maxOccupancyDifference)
.addOption(outputFile);
.addOption(outputFile)
.addOption(pValue);
//options for output to System.out
Option printAlphaCount = Option.builder().longOpt("print-alphas")

View File

@@ -5,7 +5,6 @@ import org.jgrapht.nio.AttributeType;
import org.jgrapht.nio.DefaultAttribute;
import org.jgrapht.nio.graphml.GraphMLExporter;
import org.jgrapht.nio.graphml.GraphMLExporter.AttributeCategory;
import org.w3c.dom.Attr;
import java.io.BufferedWriter;
import java.io.IOException;
@@ -13,6 +12,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class GraphMLFileWriter {
@@ -41,11 +41,11 @@ public class GraphMLFileWriter {
}
private Map<String, Attribute> createGraphAttributes(){
Map<String, Attribute> ga = new HashMap<>();
Map<String, Attribute> attributes = new HashMap<>();
//Sample plate filename
ga.put("sample plate filename", DefaultAttribute.createAttribute(data.getSourceFilename()));
attributes.put("sample plate filename", DefaultAttribute.createAttribute(data.getPlateFilename()));
// Number of wells
ga.put("well count", DefaultAttribute.createAttribute(data.getNumWells().toString()));
attributes.put("well count", DefaultAttribute.createAttribute(data.getNumWells().toString()));
//Well populations
Integer[] wellPopulations = data.getWellPopulations();
StringBuilder populationsStringBuilder = new StringBuilder();
@@ -55,11 +55,37 @@ public class GraphMLFileWriter {
populationsStringBuilder.append(wellPopulations[i].toString());
}
String wellPopulationsString = populationsStringBuilder.toString();
ga.put("well populations", DefaultAttribute.createAttribute(wellPopulationsString));
ga.put("read depth", DefaultAttribute.createAttribute(data.getReadDepth().toString()));
ga.put("read error rate", DefaultAttribute.createAttribute(data.getReadErrorRate().toString()));
ga.put("error collision rate", DefaultAttribute.createAttribute(data.getErrorCollisionRate().toString()));
return ga;
attributes.put("well populations", DefaultAttribute.createAttribute(wellPopulationsString));
attributes.put("read depth", DefaultAttribute.createAttribute(data.getReadDepth().toString()));
attributes.put("read error rate", DefaultAttribute.createAttribute(data.getReadErrorRate().toString()));
attributes.put("error collision rate", DefaultAttribute.createAttribute(data.getErrorCollisionRate().toString()));
attributes.put("real sequence collision rate", DefaultAttribute.createAttribute(data.getRealSequenceCollisionRate()));
return attributes;
}
private Map<String, Attribute> createVertexAttributes(Vertex v){
Map<String, Attribute> attributes = new HashMap<>();
//sequence type
attributes.put("type", DefaultAttribute.createAttribute(v.getType().name()));
//sequence
attributes.put("sequence", DefaultAttribute.createAttribute(v.getSequence()));
//number of wells the sequence appears in
attributes.put("occupancy", DefaultAttribute.createAttribute(v.getOccupancy()));
//total number of times the sequence was read
attributes.put("total read count", DefaultAttribute.createAttribute(v.getReadCount()));
StringBuilder wellsAndReadCountsBuilder = new StringBuilder();
Iterator<Map.Entry<Integer, Integer>> wellOccupancies = v.getWellOccupancies().entrySet().iterator();
while (wellOccupancies.hasNext()) {
Map.Entry<Integer, Integer> entry = wellOccupancies.next();
wellsAndReadCountsBuilder.append(entry.getKey() + ":" + entry.getValue());
if (wellOccupancies.hasNext()) {
wellsAndReadCountsBuilder.append(", ");
}
}
String wellsAndReadCounts = wellsAndReadCountsBuilder.toString();
//the wells the sequence appears in and the read counts in those wells
attributes.put("wells:read counts", DefaultAttribute.createAttribute(wellsAndReadCounts));
return attributes;
}
public void writeGraphToFile() {
@@ -72,15 +98,7 @@ public class GraphMLFileWriter {
//Set graph attributes
exporter.setGraphAttributeProvider( () -> graphAttributes);
//set type, sequence, and occupancy attributes for each vertex
//NEED TO ADD NEW FIELD FOR READ COUNT
exporter.setVertexAttributeProvider( v -> {
Map<String, Attribute> attributes = new HashMap<>();
attributes.put("type", DefaultAttribute.createAttribute(v.getType().name()));
attributes.put("sequence", DefaultAttribute.createAttribute(v.getSequence()));
attributes.put("occupancy", DefaultAttribute.createAttribute(v.getOccupancy()));
attributes.put("read count", DefaultAttribute.createAttribute(v.getReadCount()));
return attributes;
});
exporter.setVertexAttributeProvider(this::createVertexAttributes);
//register the attributes
for(String s : graphAttributes.keySet()) {
exporter.registerAttribute(s, AttributeCategory.GRAPH, AttributeType.STRING);
@@ -88,7 +106,8 @@ public class GraphMLFileWriter {
exporter.registerAttribute("type", AttributeCategory.NODE, AttributeType.STRING);
exporter.registerAttribute("sequence", AttributeCategory.NODE, AttributeType.STRING);
exporter.registerAttribute("occupancy", AttributeCategory.NODE, AttributeType.STRING);
exporter.registerAttribute("read count", AttributeCategory.NODE, AttributeType.STRING);
exporter.registerAttribute("total read count", AttributeCategory.NODE, AttributeType.STRING);
exporter.registerAttribute("wells:read counts", AttributeCategory.NODE, AttributeType.STRING);
//export the graph
exporter.exportGraph(graph, writer);
} catch(IOException ex){

View File

@@ -9,15 +9,19 @@ import java.util.Map;
//Custom vertex class means a lot of the map data can now be encoded in the graph itself
public class GraphWithMapData implements java.io.Serializable {
private String sourceFilename;
private String cellFilename;
private int cellSampleSize;
private String plateFilename;
private final SimpleWeightedGraph graph;
private Integer numWells;
private Integer[] wellPopulations;
private Integer alphaCount;
private Integer betaCount;
private int readDepth;
private double readErrorRate;
private double errorCollisionRate;
private final int numWells;
private final Integer[] wellPopulations;
private final int alphaCount;
private final int betaCount;
private final double dropoutRate;
private final int readDepth;
private final double readErrorRate;
private final double errorCollisionRate;
private final double realSequenceCollisionRate;
private final Map<String, String> distCellsMapAlphaKey;
// private final Map<Integer, Integer> plateVtoAMap;
// private final Map<Integer, Integer> plateVtoBMap;
@@ -29,7 +33,8 @@ public class GraphWithMapData implements java.io.Serializable {
public GraphWithMapData(SimpleWeightedGraph graph, Integer numWells, Integer[] wellConcentrations,
Map<String, String> distCellsMapAlphaKey, Integer alphaCount, Integer betaCount,
Integer readDepth, Double readErrorRate, Double errorCollisionRate, Duration time){
Double dropoutRate, Integer readDepth, Double readErrorRate, Double errorCollisionRate,
Double realSequenceCollisionRate, Duration time){
// Map<Integer, Integer> plateVtoAMap,
// Map<Integer,Integer> plateVtoBMap, Map<Integer, Integer> plateAtoVMap,
@@ -47,9 +52,11 @@ public class GraphWithMapData implements java.io.Serializable {
// this.plateBtoVMap = plateBtoVMap;
// this.alphaWellCounts = alphaWellCounts;
// this.betaWellCounts = betaWellCounts;
this.dropoutRate = dropoutRate;
this.readDepth = readDepth;
this.readErrorRate = readErrorRate;
this.errorCollisionRate = errorCollisionRate;
this.realSequenceCollisionRate = realSequenceCollisionRate;
this.time = time;
}
@@ -107,12 +114,20 @@ public class GraphWithMapData implements java.io.Serializable {
return time;
}
public void setSourceFilename(String filename) {
this.sourceFilename = filename;
public void setCellFilename(String filename) { this.cellFilename = filename; }
public String getCellFilename() { return this.cellFilename; }
public Integer getCellSampleSize() { return this.cellSampleSize; }
public void setCellSampleSize(int size) { this.cellSampleSize = size;}
public void setPlateFilename(String filename) {
this.plateFilename = filename;
}
public String getSourceFilename() {
return sourceFilename;
public String getPlateFilename() {
return plateFilename;
}
public Double getReadErrorRate() {
@@ -122,4 +137,8 @@ public class GraphWithMapData implements java.io.Serializable {
public Double getErrorCollisionRate() {
return errorCollisionRate;
}
public Double getRealSequenceCollisionRate() { return realSequenceCollisionRate; }
public Double getDropoutRate() { return dropoutRate; }
}

View File

@@ -114,8 +114,8 @@ public class InteractiveInterface {
System.out.println("1) Poisson");
System.out.println("2) Gaussian");
System.out.println("3) Exponential");
System.out.println("(Note: approximate distribution in original paper is exponential, lambda = 0.6)");
System.out.println("(lambda value approximated from slope of log-log graph in figure 4c)");
// System.out.println("(Note: approximate distribution in original paper is exponential, lambda = 0.6)");
// System.out.println("(lambda value approximated from slope of log-log graph in figure 4c)");
System.out.println("(Note: wider distributions are more memory intensive to match)");
System.out.print("Enter selection value: ");
input = sc.nextInt();
@@ -255,6 +255,7 @@ public class InteractiveInterface {
int readDepth = 1;
double readErrorRate = 0.0;
double errorCollisionRate = 0.0;
double realSequenceCollisionRate = 0.0;
try {
String str = "\nGenerating bipartite weighted graph encoding occupancy overlap data ";
str = str.concat("\nrequires a cell sample file and a sample plate file.");
@@ -264,7 +265,6 @@ public class InteractiveInterface {
System.out.print("\nPlease enter name of an existing sample plate file: ");
plateFile = sc.next();
System.out.println("\nEnable simulation of sequence read depth and sequence read errors? (y/n)");
System.out.println("NOTE: sample plate data cannot be cached when simulating read errors");
String ans = sc.next();
Pattern pattern = Pattern.compile("(?:yes|y)", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(ans);
@@ -272,25 +272,29 @@ public class InteractiveInterface {
simulateReadDepth = true;
}
if (simulateReadDepth) {
BiGpairSEQ.setCachePlate(false);
BiGpairSEQ.clearPlateInMemory();
System.out.print("\nPlease enter read depth (the integer number of reads per sequence): ");
System.out.print("\nPlease enter the read depth (the integer number of times a sequence is read): ");
readDepth = sc.nextInt();
if(readDepth < 1) {
throw new InputMismatchException("The read depth must be an integer >= 1");
}
System.out.print("\nPlease enter probability of a sequence read error (0.0 to 1.0): ");
System.out.println("\nPlease enter the read error probability (0.0 to 1.0)");
System.out.print("(The probability that a sequence will be misread): ");
readErrorRate = sc.nextDouble();
if(readErrorRate < 0.0 || readErrorRate > 1.0) {
throw new InputMismatchException("The read error rate must be in the range [0.0, 1.0]");
throw new InputMismatchException("The read error probability must be in the range [0.0, 1.0]");
}
System.out.println("\nPlease enter the probability of read error collision");
System.out.println("(the likelihood that two read errors produce the same spurious sequence)");
System.out.print("(0.0 to 1.0): ");
System.out.println("\nPlease enter the error collision probability (0.0 to 1.0)");
System.out.print("(The probability of a sequence being misread in a way it has been misread before): ");
errorCollisionRate = sc.nextDouble();
if(errorCollisionRate < 0.0 || errorCollisionRate > 1.0) {
throw new InputMismatchException("The error collision probability must be an in the range [0.0, 1.0]");
}
System.out.println("\nPlease enter the real sequence collision probability (0.0 to 1.0)");
System.out.print("(The probability that a (non-collision) misread produces a different, real sequence): ");
realSequenceCollisionRate = sc.nextDouble();
if(realSequenceCollisionRate < 0.0 || realSequenceCollisionRate > 1.0) {
throw new InputMismatchException("The real sequence collision probability must be an in the range [0.0, 1.0]");
}
}
System.out.println("\nThe graph and occupancy data will be written to a file.");
System.out.print("Please enter a name for the output file: ");
@@ -338,7 +342,8 @@ public class InteractiveInterface {
System.out.println("Returning to main menu.");
}
else{
GraphWithMapData data = Simulator.makeCDR3Graph(cellSample, plate, readDepth, readErrorRate, errorCollisionRate, true);
GraphWithMapData data = Simulator.makeCDR3Graph(cellSample, plate, readDepth, readErrorRate,
errorCollisionRate, realSequenceCollisionRate, true);
assert filename != null;
if(BiGpairSEQ.outputBinary()) {
GraphDataObjectWriter dataWriter = new GraphDataObjectWriter(filename, data);
@@ -417,7 +422,7 @@ public class InteractiveInterface {
}
//simulate matching
MatchingResult results = Simulator.matchCDR3s(data, graphFilename, lowThreshold, highThreshold, maxOccupancyDiff,
minOverlapPercent, true);
minOverlapPercent, true, BiGpairSEQ.calculatePValue());
//write results to file
assert filename != null;
MatchingFileWriter writer = new MatchingFileWriter(filename, results);
@@ -539,7 +544,8 @@ public class InteractiveInterface {
System.out.println("3) Turn " + getOnOff(!BiGpairSEQ.cacheGraph()) + " graph/data file caching");
System.out.println("4) Turn " + getOnOff(!BiGpairSEQ.outputBinary()) + " serialized binary graph output");
System.out.println("5) Turn " + getOnOff(!BiGpairSEQ.outputGraphML()) + " GraphML graph output (for data portability to other programs)");
System.out.println("6) Maximum weight matching algorithm options");
System.out.println("6) Turn " + getOnOff(!BiGpairSEQ.calculatePValue()) + " calculation of p-values");
System.out.println("7) Maximum weight matching algorithm options");
System.out.println("0) Return to main menu");
try {
input = sc.nextInt();
@@ -549,7 +555,8 @@ public class InteractiveInterface {
case 3 -> BiGpairSEQ.setCacheGraph(!BiGpairSEQ.cacheGraph());
case 4 -> BiGpairSEQ.setOutputBinary(!BiGpairSEQ.outputBinary());
case 5 -> BiGpairSEQ.setOutputGraphML(!BiGpairSEQ.outputGraphML());
case 6 -> algorithmOptions();
case 6 -> BiGpairSEQ.setCalculatePValue(!BiGpairSEQ.calculatePValue());
case 7 -> algorithmOptions();
case 0 -> backToMain = true;
default -> System.out.println("Invalid input");
}

View File

@@ -2,6 +2,13 @@
/*
TODO: Implement exponential distribution using inversion method - DONE
TODO: Implement collisions with real sequences by having the counting function keep a map of all sequences it's read,
with values of all misreads. Can then have a spurious/real collision rate, which will have count randomly select a sequence
it's already read at least once, and put that into the list of spurious sequences for the given real sequence. Will let me get rid
of the distinctMisreadCount map, and use this new map instead. Doing it this way, once a sequence has been misread as another
sequence once, it is more likely to be misread that way again, as future read error collisions can also be real sequence collisions
Prob A: a read error occurs. Prob B: it's a new error (otherwise it's a repeated error). Prob C: if new error, prob that it's
a real sequence collision (otherwise it's a new spurious sequence) - DONE
TODO: Implement discrete frequency distributions using Vose's Alias Method
*/
@@ -148,79 +155,83 @@ public class Plate {
return wells;
}
// //returns a map of the counts of the sequence at cell index sIndex, in all wells
// public void assayWellsSequenceS(Map<String, Integer> sequences, int... sIndices){
// this.assayWellsSequenceS(sequences, 0, size, sIndices);
// }
//
// //returns a map of the counts of the sequence at cell index sIndex, in a specific well
// public void assayWellsSequenceS(Map<String, Integer> sequences, int n, int... sIndices) {
// this.assayWellsSequenceS(sequences, n, n+1, sIndices);
// }
//
// //returns a map of the counts of the sequence at cell index sIndex, in a range of wells
// public void assayWellsSequenceS(Map<String, Integer> sequences, int start, int end, int... sIndices) {
// for(int sIndex: sIndices){
// for(int i = start; i < end; i++){
// countSequences(sequences, wells.get(i), sIndex);
// }
// }
// }
// //For the sequences at cell indices sIndices, counts number of unique sequences in the given well into the given map
// private void countSequences(Map<String, Integer> wellMap, List<String[]> well, int... sIndices) {
// for(String[] cell : well) {
// for(int sIndex: sIndices){
// //skip dropout sequences, which have value -1
// if(!"-1".equals(cell[sIndex])){
// wellMap.merge(cell[sIndex], 1, (oldValue, newValue) -> oldValue + newValue);
// }
// }
// }
// }
//For the sequences at cell indices sIndices, counts number of unique sequences in all well into the given map
//For the sequences at cell indices sIndices, counts number of unique sequences in all wells.
//Also simulates sequence read errors with given probabilities.
//Returns a map of SequenceRecords containing plate data for all sequences read.
//TODO actually implement usage of misreadSequences - DONE
public Map<String, SequenceRecord> countSequences(Integer readDepth, Double readErrorRate,
Double errorCollisionRate, int... sIndices) {
Double errorCollisionRate, Double realSequenceCollisionRate, int... sIndices) {
SequenceType[] sequenceTypes = EnumSet.allOf(SequenceType.class).toArray(new SequenceType[0]);
Map<String, Integer> distinctMisreadCounts = new HashMap<>();
//Map of all real sequences read. Keys are sequences, values are ways sequence has been misread.
Map<String, List<String>> sequencesAndMisreads = new HashMap<>();
//Map of all sequences read. Keys are sequences, values are associated SequenceRecords
Map<String, SequenceRecord> sequenceMap = new LinkedHashMap<>();
//get list of all distinct, real sequences
String[] realSequences = assayWells(sIndices).toArray(new String[0]);
for (int well = 0; well < size; well++) {
for (String[] cell : wells.get(well)) {
for (int sIndex : sIndices) {
for (String[] cell: wells.get(well)) {
for (int sIndex: sIndices) {
//the sequence being read
String currentSequence = cell[sIndex];
//skip dropout sequences, which have value -1
if (!"-1".equals(cell[sIndex])) {
if (!"-1".equals(currentSequence)) {
//keep rereading the sequence until the read depth is reached
for (int j = 0; j < readDepth; j++) {
//Misread sequence
//The sequence is misread
if (rand.nextDouble() < readErrorRate) {
StringBuilder spurious = new StringBuilder(cell[sIndex]);
//if this sequence hasn't been misread before, or the read error is unique,
//append one more "*" than has been appended before
if (rand.nextDouble() > errorCollisionRate || !distinctMisreadCounts.containsKey(cell[sIndex])) {
distinctMisreadCounts.merge(cell[sIndex], 1, (oldValue, newValue) -> oldValue + newValue);
for (int k = 0; k < distinctMisreadCounts.get(cell[sIndex]); k++) {
//The sequence hasn't been read or misread before
if (!sequencesAndMisreads.containsKey(currentSequence)) {
sequencesAndMisreads.put(currentSequence, new ArrayList<>());
}
//The specific misread hasn't happened before
if (rand.nextDouble() >= errorCollisionRate || sequencesAndMisreads.get(currentSequence).size() == 0) {
//The misread doesn't collide with a real sequence already on the plate and some sequences have already been read
if(rand.nextDouble() >= realSequenceCollisionRate || !sequenceMap.isEmpty()){
StringBuilder spurious = new StringBuilder(currentSequence);
for (int k = 0; k <= sequencesAndMisreads.get(currentSequence).size(); k++) {
spurious.append("*");
}
//New sequence record for the spurious sequence
SequenceRecord tmp = new SequenceRecord(spurious.toString(), sequenceTypes[sIndex]);
tmp.addRead(well);
sequenceMap.put(spurious.toString(), tmp);
//add spurious sequence to list of misreads for the real sequence
sequencesAndMisreads.get(currentSequence).add(spurious.toString());
}
//if this is a read error collision, randomly choose a number of "*"s that has been appended before
//The misread collides with a real sequence already read from plate
else {
int starCount = rand.nextInt(distinctMisreadCounts.get(cell[sIndex]));
for (int k = 0; k < starCount; k++) {
spurious.append("*");
}
sequenceMap.get(spurious.toString()).addRead(well);
String wrongSequence;
do{
//get a random real sequence that's been read from the plate before
int index = rand.nextInt(realSequences.length);
wrongSequence = realSequences[index];
//make sure it's not accidentally the *right* sequence
//Also that it's not a wrong sequence already in the misread list
} while(currentSequence.equals(wrongSequence) || sequencesAndMisreads.get(currentSequence).contains(wrongSequence));
//update the SequenceRecord for wrongSequence
sequenceMap.get(wrongSequence).addRead(well);
//add wrongSequence to the misreads for currentSequence
sequencesAndMisreads.get(currentSequence).add(wrongSequence);
}
}
//sequence is read correctly
}
//The sequence is read correctly
else {
if (!sequenceMap.containsKey(cell[sIndex])) {
SequenceRecord tmp = new SequenceRecord(cell[sIndex], sequenceTypes[sIndex]);
//the sequence hasn't been read before
if (!sequenceMap.containsKey(currentSequence)) {
//create new record for the sequence
SequenceRecord tmp = new SequenceRecord(currentSequence, sequenceTypes[sIndex]);
//add this read to the sequence record
tmp.addRead(well);
sequenceMap.put(cell[sIndex], tmp);
} else {
sequenceMap.get(cell[sIndex]).addRead(well);
//add the sequence and its record to the sequence map
sequenceMap.put(currentSequence, tmp);
//add the sequence to the sequences and misreads map
sequencesAndMisreads.put(currentSequence, new ArrayList<>());
}
//the sequence has been read before
else {
//get the sequence's record and add this read to it
sequenceMap.get(currentSequence).addRead(well);
}
}
}
@@ -231,97 +242,17 @@ public class Plate {
return sequenceMap;
}
// //returns a map of the counts of the sequence at cell index sIndex, in all wells
// //Simulates read depth and read errors, counts the number of reads of a unique sequence into the given map.
// public void assayWellsSequenceSWithReadDepth(Map<String, Integer> misreadCounts, Map<String, Integer> occupancyMap, Map<String, Integer> readCountMap,
// int readDepth, double readErrorProb, double errorCollisionProb, int... sIndices) {
// this.assayWellsSequenceSWithReadDepth(misreadCounts, occupancyMap, readCountMap, readDepth, readErrorProb, errorCollisionProb, 0, size, sIndices);
// }
// //returns a map of the counts of the sequence at cell index sIndex, in a specific of wells
// //Simulates read depth and read errors, counts the number of reads of a unique sequence into the given map.
// public void assayWellsSequenceSWithReadDepth(Map<String, Integer> misreadCounts, Map<String, Integer> occupancyMap, Map<String, Integer> readCountMap,
// int readDepth, double readErrorProb, double errorCollisionProb,
// int n, int... sIndices) {
// this.assayWellsSequenceSWithReadDepth(misreadCounts, occupancyMap, readCountMap, readDepth, readErrorProb, errorCollisionProb, n, n+1, sIndices);
// }
//
// //returns a map of the counts of the sequence at cell index sIndex, in a range of wells
// //Simulates read depth and read errors, counts the number of reads of a unique sequence into the given map.
// public void assayWellsSequenceSWithReadDepth(Map<String, Integer> misreadCounts, Map<String, Integer> occupancyMap, Map<String, Integer> readCountMap,
// int readDepth, double readErrorProb, double errorCollisionProb,
// int start, int end, int... sIndices) {
// for(int sIndex: sIndices){
// for(int i = start; i < end; i++){
// countSequencesWithReadDepth(misreadCounts, occupancyMap, readCountMap, readDepth, readErrorProb, errorCollisionProb, wells.get(i), sIndex);
// }
// }
// }
//
// //For the sequences at cell indices sIndices, counts number of unique sequences in the given well into the given map
// //Simulates read depth and read errors, counts the number of reads of a unique sequence into the given map.
// //NOTE: this function changes the content of the well, adding spurious cells to contain the misread sequences
// //(this is necessary because, in the simulation, the plate is read multiple times, but random misreads can only
// //be simulated once).
// //(Possibly I should refactor all of this to only require a single plate assay, to speed things up. Or at least
// //to see if it would speed things up.)
// private void countSequencesWithReadDepth(Map<String, Integer> distinctMisreadCounts, Map<String, Integer> occupancyMap, Map<String, Integer> readCountMap,
// int readDepth, double readErrorProb, double errorCollisionProb,
// List<String[]> well, int... sIndices) {
// //list of spurious cells to add to well after counting
// List<String[]> spuriousCells = new ArrayList<>();
// for(String[] cell : well) {
// //new potential spurious cell for each cell that gets read
// String[] spuriousCell = new String[SequenceType.values().length];
// //initialize spurious cell with all dropout sequences
// Arrays.fill(spuriousCell, "-1");
// //has a read error occurred?
// boolean readError = false;
// for(int sIndex: sIndices){
// //skip dropout sequences, which have value "-1"
// if(!"-1".equals(cell[sIndex])){
// Map<String, Integer> sequencesWithReadCounts = new LinkedHashMap<>();
// for(int i = 0; i < readDepth; i++) {
// if (rand.nextDouble() <= readErrorProb) {
// readError = true;
// //Read errors are represented by appending "*"s to the end of the sequence some number of times
// StringBuilder spurious = new StringBuilder(cell[sIndex]);
// //if this sequence hasn't been misread before, or the read error is unique,
// //append one more "*" than has been appended before
// if (!distinctMisreadCounts.containsKey(cell[sIndex]) || rand.nextDouble() > errorCollisionProb) {
// distinctMisreadCounts.merge(cell[sIndex], 1, (oldValue, newValue) -> oldValue + newValue);
// for (int j = 0; j < distinctMisreadCounts.get(cell[sIndex]); j++) {
// spurious.append("*");
// }
// }
// //if this is a read error collision, randomly choose a number of "*"s that has been appended before
// else {
// int starCount = rand.nextInt(distinctMisreadCounts.get(cell[sIndex]));
// for (int j = 0; j < starCount; j++) {
// spurious.append("*");
// }
// }
// sequencesWithReadCounts.merge(spurious.toString(), 1, (oldValue, newValue) -> oldValue + newValue);
// //add spurious sequence to spurious cell
// spuriousCell[sIndex] = spurious.toString();
// }
// else {
// sequencesWithReadCounts.merge(cell[sIndex], 1, (oldValue, newValue) -> oldValue + newValue);
// }
// }
// for(String seq : sequencesWithReadCounts.keySet()) {
// occupancyMap.merge(seq, 1, (oldValue, newValue) -> oldValue + newValue);
// readCountMap.merge(seq, sequencesWithReadCounts.get(seq), (oldValue, newValue) -> oldValue + newValue);
// }
// }
// }
// if (readError) { //only add a new spurious cell if there was a read error
// spuriousCells.add(spuriousCell);
// }
// }
// //add all spurious cells to the well
// well.addAll(spuriousCells);
// }
private HashSet<String> assayWells(int[] indices) {
HashSet<String> allSequences = new HashSet<>();
for (List<String[]> well: wells) {
for (String[] cell: well) {
for(int index: indices) {
allSequences.add(cell[index]);
}
}
}
return allSequences;
}
public String getSourceFileName() {
return sourceFile;

View File

@@ -39,6 +39,11 @@ public class SequenceRecord implements Serializable {
wells.put(wellNumber, readCount);
}
//Method to remove a well from the occupancy map.
//Useful for cases where one sequence is misread as another sequence that isn't actually present in the well
//This can reveal itself as an anomalously low read count in that well.
public void deleteWell(Integer wellNumber) { wells.remove(wellNumber); }
public Set<Integer> getWells() {
return wells.keySet();
}

View File

@@ -12,14 +12,6 @@ import java.text.NumberFormat;
import java.time.Instant;
import java.time.Duration;
import java.util.*;
/*
Refactor notes
What would be necessary to do everything with only one scan through the sample plate?
I would need to keep a list of sequences (real and spurious), and metadata about each sequence.
I would need the data:
* # of each well the sequence appears in
* Read count in that well
*/
//NOTE: "sequence" in method and variable names refers to a peptide sequence from a simulated T cell
@@ -27,7 +19,8 @@ public class Simulator implements GraphModificationFunctions {
public static GraphWithMapData makeCDR3Graph(CellSample cellSample, Plate samplePlate, int readDepth,
double readErrorRate, double errorCollisionRate, boolean verbose) {
double readErrorRate, double errorCollisionRate,
double realSequenceCollisionRate, boolean verbose) {
//start timing
Instant start = Instant.now();
int[] alphaIndices = {SequenceType.CDR3_ALPHA.ordinal()};
@@ -44,11 +37,11 @@ public class Simulator implements GraphModificationFunctions {
//Make linkedHashMap keyed to sequences, values are SequenceRecords reflecting plate statistics
if(verbose){System.out.println("Making sample plate sequence maps");}
Map<String, SequenceRecord> alphaSequences = samplePlate.countSequences(readDepth, readErrorRate,
errorCollisionRate, alphaIndices);
errorCollisionRate, realSequenceCollisionRate, alphaIndices);
int alphaCount = alphaSequences.size();
if(verbose){System.out.println("Alphas sequences read: " + alphaCount);}
Map<String, SequenceRecord> betaSequences = samplePlate.countSequences(readDepth, readErrorRate,
errorCollisionRate, betaIndices);
errorCollisionRate, realSequenceCollisionRate, betaIndices);
int betaCount = betaSequences.size();
if(verbose){System.out.println("Betas sequences read: " + betaCount);}
if(verbose){System.out.println("Sample plate sequence maps made");}
@@ -68,10 +61,14 @@ public class Simulator implements GraphModificationFunctions {
if(verbose){System.out.println("Remaining alpha sequence count: " + alphaSequences.size());}
if(verbose){System.out.println("Remaining beta sequence count: " + betaSequences.size());}
}
int pairableAlphaCount = alphaSequences.size();
if(verbose){System.out.println("Remaining alpha sequence count: " + pairableAlphaCount);}
int pairableBetaCount = betaSequences.size();
if(verbose){System.out.println("Remaining beta sequence count: " + pairableBetaCount);}
if (realSequenceCollisionRate > 0.0) {
if(verbose){System.out.println("Removing wells with anomalous read counts from sequence records");}
int alphaWellsRemoved = filterWellsByReadCount(alphaSequences);
int betaWellsRemoved = filterWellsByReadCount(betaSequences);
if(verbose){System.out.println("Wells with anomalous read counts removed from sequence records");}
if(verbose){System.out.println("Total alpha sequence wells removed: " + alphaWellsRemoved);}
if(verbose){System.out.println("Total beta sequence wells removed: " + betaWellsRemoved);}
}
//construct the graph. For simplicity, going to make
if(verbose){System.out.println("Making vertex maps");}
@@ -131,9 +128,13 @@ public class Simulator implements GraphModificationFunctions {
Duration time = Duration.between(start, stop);
//create GraphWithMapData object
GraphWithMapData output = new GraphWithMapData(graph, numWells, samplePlate.getPopulations(), distCellsMapAlphaKey,
alphaCount, betaCount, readDepth, readErrorRate, errorCollisionRate, time);
//Set source file name in graph to name of sample plate
output.setSourceFilename(samplePlate.getFilename());
alphaCount, betaCount, samplePlate.getError(), readDepth, readErrorRate, errorCollisionRate, realSequenceCollisionRate, time);
//Set cell sample file name in graph to name of cell sample
output.setCellFilename(cellSample.getFilename());
//Set cell sample size in graph
output.setCellSampleSize(cellSample.getCellCount());
//Set sample plate file name in graph to name of sample plate
output.setPlateFilename(samplePlate.getFilename());
//return GraphWithMapData object
return output;
}
@@ -141,7 +142,7 @@ public class Simulator implements GraphModificationFunctions {
//match CDR3s.
public static MatchingResult matchCDR3s(GraphWithMapData data, String dataFilename, Integer lowThreshold,
Integer highThreshold, Integer maxOccupancyDifference,
Integer minOverlapPercent, boolean verbose) {
Integer minOverlapPercent, boolean verbose, boolean calculatePValue) {
Instant start = Instant.now();
SimpleWeightedGraph<Vertex, DefaultWeightedEdge> graph = data.getGraph();
Map<Vertex[], Integer> removedEdges = new HashMap<>();
@@ -219,7 +220,7 @@ public class Simulator implements GraphModificationFunctions {
header.add("Beta well count");
header.add("Overlap well count");
header.add("Matched correctly?");
header.add("P-value");
if(calculatePValue) { header.add("P-value"); }
//Results for csv file
List<List<String>> allResults = new ArrayList<>();
@@ -256,10 +257,12 @@ public class Simulator implements GraphModificationFunctions {
//overlap count
result.add(Double.toString(graph.getEdgeWeight(e)));
result.add(Boolean.toString(check));
if (calculatePValue) {
double pValue = Equations.pValue(numWells, source.getOccupancy(),
target.getOccupancy(), graph.getEdgeWeight(e));
BigDecimal pValueTrunc = new BigDecimal(pValue, mc);
result.add(pValueTrunc.toString());
}
allResults.add(result);
}
@@ -299,7 +302,11 @@ public class Simulator implements GraphModificationFunctions {
Map<String, String> metadata = new LinkedHashMap<>();
metadata.put("sample plate filename", data.getSourceFilename());
metadata.put("cell sample filename", data.getCellFilename());
metadata.put("cell sample size", data.getCellSampleSize().toString());
metadata.put("sample plate filename", data.getPlateFilename());
metadata.put("sample plate well count", data.getNumWells().toString());
metadata.put("sequence dropout rate", data.getDropoutRate().toString());
metadata.put("graph filename", dataFilename);
metadata.put("MWM algorithm type", algoType);
metadata.put("matching weight", totalMatchingWeight.toString());
@@ -307,12 +314,9 @@ public class Simulator implements GraphModificationFunctions {
metadata.put("sequence read depth", data.getReadDepth().toString());
metadata.put("sequence read error rate", data.getReadErrorRate().toString());
metadata.put("read error collision rate", data.getErrorCollisionRate().toString());
metadata.put("real sequence collision rate", data.getRealSequenceCollisionRate().toString());
metadata.put("total alphas read from plate", data.getAlphaCount().toString());
metadata.put("total betas read from plate", data.getBetaCount().toString());
//HARD CODED, PARAMETERIZE LATER
metadata.put("pre-filter sequences present in all wells", "true");
//HARD CODED, PARAMETERIZE LATER
metadata.put("pre-filter sequences based on occupancy/read count discrepancy", "true");
metadata.put("alphas in graph (after pre-filtering)", graphAlphaCount.toString());
metadata.put("betas in graph (after pre-filtering)", graphBetaCount.toString());
metadata.put("high overlap threshold for pairing", highThreshold.toString());
@@ -649,7 +653,7 @@ public class Simulator implements GraphModificationFunctions {
// }
//Remove sequences based on occupancy
public static void filterByOccupancyThresholds(Map<String, SequenceRecord> wellMap, int low, int high){
private static void filterByOccupancyThresholds(Map<String, SequenceRecord> wellMap, int low, int high){
List<String> noise = new ArrayList<>();
for(String k: wellMap.keySet()){
if((wellMap.get(k).getOccupancy() > high) || (wellMap.get(k).getOccupancy() < low)){
@@ -661,10 +665,10 @@ public class Simulator implements GraphModificationFunctions {
}
}
public static void filterByOccupancyAndReadCount(Map<String, SequenceRecord> sequences, int readDepth) {
private static void filterByOccupancyAndReadCount(Map<String, SequenceRecord> sequences, int readDepth) {
List<String> noise = new ArrayList<>();
for(String k : sequences.keySet()){
//occupancy times read depth should be more than half the sequence read count if the read error rate is low
//the sequence read count should be more than half the occupancy times read depth if the read error rate is low
Integer threshold = (sequences.get(k).getOccupancy() * readDepth) / 2;
if(sequences.get(k).getReadCount() < threshold) {
noise.add(k);
@@ -675,6 +679,26 @@ public class Simulator implements GraphModificationFunctions {
}
}
private static int filterWellsByReadCount(Map<String, SequenceRecord> sequences) {
int count = 0;
for (String k: sequences.keySet()) {
//If a sequence has read count R and appears in W wells, then on average its read count in each
//well should be R/W. Delete any wells where the read count is less than R/2W.
Integer threshold = sequences.get(k).getReadCount() / (2 * sequences.get(k).getOccupancy());
List<Integer> noise = new ArrayList<>();
for (Integer well: sequences.get(k).getWells()) {
if (sequences.get(k).getReadCount(well) < threshold) {
noise.add(well);
count++;
}
}
for (Integer well: noise) {
sequences.get(k).deleteWell(well);
}
}
return count;
}
private static Map<String, String> makeSequenceToSequenceMap(List<String[]> cells, int keySequenceIndex,
int valueSequenceIndex){
Map<String, String> keySequenceToValueSequenceMap = new HashMap<>();

View File

@@ -32,6 +32,8 @@ public class Vertex implements Serializable, Comparable<Vertex> {
public Integer getReadCount() { return record.getReadCount(); }
public Integer getReadCount(Integer well) { return record.getReadCount(well); }
public Map<Integer, Integer> getWellOccupancies() { return record.getWellOccupancies(); }
@Override //adapted from JGraphT example code