Implemented parameter for CDR1 frequency

This commit is contained in:
2021-11-18 11:55:54 -06:00
parent 4157cfb556
commit 2064d7e9fc
4 changed files with 19 additions and 22 deletions

View File

@@ -13,6 +13,7 @@ public class CellFileWriter {
private String[] headers = {"Alpha CDR3", "Beta CDR3", "Alpha CDR1", "Beta CDR1"}; private String[] headers = {"Alpha CDR3", "Beta CDR3", "Alpha CDR1", "Beta CDR1"};
List<Integer[]> cells; List<Integer[]> cells;
String filename; String filename;
Integer cdr1Freq;
public CellFileWriter(String filename, CellSample cells) { public CellFileWriter(String filename, CellSample cells) {
if(!filename.matches(".*\\.csv")){ if(!filename.matches(".*\\.csv")){
@@ -20,15 +21,18 @@ public class CellFileWriter {
} }
this.filename = filename; this.filename = filename;
this.cells = cells.getCells(); this.cells = cells.getCells();
this.cdr1Freq = cells.getCdr1Freq();
} }
public void writeCellsToFile() { public void writeCellsToFile() {
CSVFormat cellFileFormat = CSVFormat.Builder.create() CSVFormat cellFileFormat = CSVFormat.Builder.create()
.setCommentMarker('#')
.setHeader(headers) .setHeader(headers)
.build(); .build();
try(BufferedWriter writer = Files.newBufferedWriter(Path.of(filename), StandardOpenOption.CREATE_NEW); try(BufferedWriter writer = Files.newBufferedWriter(Path.of(filename), StandardOpenOption.CREATE_NEW);
CSVPrinter printer = new CSVPrinter(writer, cellFileFormat); CSVPrinter printer = new CSVPrinter(writer, cellFileFormat);
){ ){
printer.printComment("Sample contains 1 unique CDR1 for every " + cdr1Freq + "unique CDR3s.");
printer.printRecords(cells); printer.printRecords(cells);
} catch(IOException ex){ } catch(IOException ex){
System.out.println("Could not make new file named "+filename); System.out.println("Could not make new file named "+filename);

View File

@@ -3,15 +3,21 @@ import java.util.List;
public class CellSample { public class CellSample {
private List<Integer[]> cells; private List<Integer[]> cells;
private Integer cdr1Freq;
public CellSample(List<Integer[]> cells){ public CellSample(List<Integer[]> cells, Integer cdr1Freq){
this.cells = cells; this.cells = cells;
this.cdr1Freq = cdr1Freq;
} }
public List<Integer[]> getCells(){ public List<Integer[]> getCells(){
return cells; return cells;
} }
public Integer getCdr1Freq() {
return cdr1Freq;
}
public Integer population(){ public Integer population(){
return cells.size(); return cells.size();
} }

View File

@@ -29,31 +29,14 @@ public class Simulator {
private static boolean useJGraphTGraphMatrixGenerator = true; //fastest option private static boolean useJGraphTGraphMatrixGenerator = true; //fastest option
*/ */
public static CellSample generateCellSample(Integer numDistinctCells) { public static CellSample generateCellSample(Integer numDistinctCells, Integer cdr1Freq) {
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) {
//In real T cells, CDR1s have about one third the diversity of CDR3s //In real T cells, CDR1s have about one third the diversity of CDR3s
//previous sim was only CDR3s //previous sim was only CDR3s
List<Integer> numbersCDR3 = new ArrayList<>(); List<Integer> numbersCDR3 = new ArrayList<>();
List<Integer> numbersCDR1 = new ArrayList<>(); List<Integer> numbersCDR1 = new ArrayList<>();
Integer numDistCDR3s = 2 * numDistinctCells + 1; Integer numDistCDR3s = 2 * numDistinctCells + 1;
IntStream.range(1, numDistCDR3s + 1).forEach(i -> numbersCDR3.add(i)); 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(numbersCDR3);
Collections.shuffle(numbersCDR1); Collections.shuffle(numbersCDR1);
@@ -68,7 +51,7 @@ public class Simulator {
Integer[] tmp = {tmpCDR3a, tmpCDR3b, tmpCDR1a, tmpCDR1b}; Integer[] tmp = {tmpCDR3a, tmpCDR3b, tmpCDR1a, tmpCDR1b};
distinctCells.add(tmp); distinctCells.add(tmp);
} }
return new CellSample(distinctCells); return new CellSample(distinctCells, cdr1Freq);
} }
public static MatchingResult matchCDR3s(List<Integer[]> distinctCells, public static MatchingResult matchCDR3s(List<Integer[]> distinctCells,

View File

@@ -41,6 +41,7 @@ public class UserInterface {
private static void makeCells() { private static void makeCells() {
String filename = null; String filename = null;
Integer numCells = 0; Integer numCells = 0;
Integer cdr1Freq = 1;
try { try {
System.out.println("\nSimulated T-Cells consist of integer values representing:\n" + 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" + "* 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.println("\nThe cells will be written to a file.");
System.out.print("Please enter a file name: "); System.out.print("Please enter a file name: ");
filename = sc.next(); 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: "); System.out.print("Please enter the number of T-cells to generate: ");
numCells = sc.nextInt(); numCells = sc.nextInt();
if(numCells <= 0){ if(numCells <= 0){
@@ -57,7 +61,7 @@ public class UserInterface {
System.out.println(ex); System.out.println(ex);
sc.next(); sc.next();
} }
CellSample sample = Simulator.generateExpandedCellSample(numCells); CellSample sample = Simulator.generateCellSample(numCells, cdr1Freq);
CellFileWriter writer = new CellFileWriter(filename, sample); CellFileWriter writer = new CellFileWriter(filename, sample);
writer.writeCellsToFile(); writer.writeCellsToFile();
} }