Implemented parameter for CDR1 frequency
This commit is contained in:
@@ -13,6 +13,7 @@ public class CellFileWriter {
|
||||
private String[] headers = {"Alpha CDR3", "Beta CDR3", "Alpha CDR1", "Beta CDR1"};
|
||||
List<Integer[]> cells;
|
||||
String filename;
|
||||
Integer cdr1Freq;
|
||||
|
||||
public CellFileWriter(String filename, CellSample cells) {
|
||||
if(!filename.matches(".*\\.csv")){
|
||||
@@ -20,15 +21,18 @@ public class CellFileWriter {
|
||||
}
|
||||
this.filename = filename;
|
||||
this.cells = cells.getCells();
|
||||
this.cdr1Freq = cells.getCdr1Freq();
|
||||
}
|
||||
|
||||
public void writeCellsToFile() {
|
||||
CSVFormat cellFileFormat = CSVFormat.Builder.create()
|
||||
.setCommentMarker('#')
|
||||
.setHeader(headers)
|
||||
.build();
|
||||
try(BufferedWriter writer = Files.newBufferedWriter(Path.of(filename), StandardOpenOption.CREATE_NEW);
|
||||
CSVPrinter printer = new CSVPrinter(writer, cellFileFormat);
|
||||
){
|
||||
printer.printComment("Sample contains 1 unique CDR1 for every " + cdr1Freq + "unique CDR3s.");
|
||||
printer.printRecords(cells);
|
||||
} catch(IOException ex){
|
||||
System.out.println("Could not make new file named "+filename);
|
||||
|
||||
@@ -3,15 +3,21 @@ import java.util.List;
|
||||
public class CellSample {
|
||||
|
||||
private List<Integer[]> cells;
|
||||
private Integer cdr1Freq;
|
||||
|
||||
public CellSample(List<Integer[]> cells){
|
||||
public CellSample(List<Integer[]> cells, Integer cdr1Freq){
|
||||
this.cells = cells;
|
||||
this.cdr1Freq = cdr1Freq;
|
||||
}
|
||||
|
||||
public List<Integer[]> getCells(){
|
||||
return cells;
|
||||
}
|
||||
|
||||
public Integer getCdr1Freq() {
|
||||
return cdr1Freq;
|
||||
}
|
||||
|
||||
public Integer population(){
|
||||
return cells.size();
|
||||
}
|
||||
|
||||
@@ -29,31 +29,14 @@ public class Simulator {
|
||||
private static boolean useJGraphTGraphMatrixGenerator = true; //fastest option
|
||||
*/
|
||||
|
||||
public static CellSample generateCellSample(Integer numDistinctCells) {
|
||||
List<Integer> numbers = new ArrayList<>();
|
||||
IntStream.range(1, (2 * numDistinctCells) + 1).forEach(i -> numbers.add(i));
|
||||
Collections.shuffle(numbers);
|
||||
|
||||
//Each cell represented by two numbers from the random permutation
|
||||
//These represent unique alpha and beta peptides
|
||||
List<Integer[]> distinctCells = new ArrayList<>();
|
||||
for(int i = 0; i < numbers.size() - 1; i = i + 2) {
|
||||
Integer tmp1 = numbers.get(i);
|
||||
Integer tmp2 = numbers.get(i+1);
|
||||
Integer[] tmp = {tmp1, tmp2};
|
||||
distinctCells.add(tmp);
|
||||
}
|
||||
return new CellSample(distinctCells);
|
||||
}
|
||||
|
||||
public static CellSample generateExpandedCellSample(Integer numDistinctCells) {
|
||||
public static CellSample generateCellSample(Integer numDistinctCells, Integer cdr1Freq) {
|
||||
//In real T cells, CDR1s have about one third the diversity of CDR3s
|
||||
//previous sim was only CDR3s
|
||||
List<Integer> numbersCDR3 = new ArrayList<>();
|
||||
List<Integer> numbersCDR1 = new ArrayList<>();
|
||||
Integer numDistCDR3s = 2 * numDistinctCells + 1;
|
||||
IntStream.range(1, numDistCDR3s + 1).forEach(i -> numbersCDR3.add(i));
|
||||
IntStream.range(numDistCDR3s + 1, numDistCDR3s + 1 + (numDistCDR3s / 3) + 1).forEach(i -> numbersCDR1.add(i));
|
||||
IntStream.range(numDistCDR3s + 1, numDistCDR3s + 1 + (numDistCDR3s / cdr1Freq) + 1).forEach(i -> numbersCDR1.add(i));
|
||||
Collections.shuffle(numbersCDR3);
|
||||
Collections.shuffle(numbersCDR1);
|
||||
|
||||
@@ -68,7 +51,7 @@ public class Simulator {
|
||||
Integer[] tmp = {tmpCDR3a, tmpCDR3b, tmpCDR1a, tmpCDR1b};
|
||||
distinctCells.add(tmp);
|
||||
}
|
||||
return new CellSample(distinctCells);
|
||||
return new CellSample(distinctCells, cdr1Freq);
|
||||
}
|
||||
|
||||
public static MatchingResult matchCDR3s(List<Integer[]> distinctCells,
|
||||
|
||||
@@ -41,6 +41,7 @@ public class UserInterface {
|
||||
private static void makeCells() {
|
||||
String filename = null;
|
||||
Integer numCells = 0;
|
||||
Integer cdr1Freq = 1;
|
||||
try {
|
||||
System.out.println("\nSimulated T-Cells consist of integer values representing:\n" +
|
||||
"* a pair of alpha and beta CDR3 peptides (unique within simulated population)\n" +
|
||||
@@ -48,6 +49,9 @@ public class UserInterface {
|
||||
System.out.println("\nThe cells will be written to a file.");
|
||||
System.out.print("Please enter a file name: ");
|
||||
filename = sc.next();
|
||||
System.out.println("CDR3 sequences are more diverse than CDR1 sequences.");
|
||||
System.out.println("Please enter the factor by which distinct CDR3s outnumber CDR1s: ");
|
||||
cdr1Freq = sc.nextInt();
|
||||
System.out.print("Please enter the number of T-cells to generate: ");
|
||||
numCells = sc.nextInt();
|
||||
if(numCells <= 0){
|
||||
@@ -57,7 +61,7 @@ public class UserInterface {
|
||||
System.out.println(ex);
|
||||
sc.next();
|
||||
}
|
||||
CellSample sample = Simulator.generateExpandedCellSample(numCells);
|
||||
CellSample sample = Simulator.generateCellSample(numCells, cdr1Freq);
|
||||
CellFileWriter writer = new CellFileWriter(filename, sample);
|
||||
writer.writeCellsToFile();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user