Refactor to read/write files of graph and map data
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import org.apache.commons.cli.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.InputMismatchException;
|
||||
@@ -259,9 +260,9 @@ public class UserInterface {
|
||||
System.out.println("Please select an option:");
|
||||
System.out.println("1) Generate a population of distinct cells");
|
||||
System.out.println("2) Generate a sample plate of T cells");
|
||||
System.out.println("3) Generate CDR3 alpha/beta occupancy graph");
|
||||
//System.out.println("4) Generate CDR3/CDR1 occupancy graph");
|
||||
System.out.println("5) Simulate CDR3 alpha/beta T cell matching");
|
||||
System.out.println("3) Generate CDR3 alpha/beta occupancy graph and data");
|
||||
System.out.println("4) Simulate CDR3 alpha/beta T cell matching");
|
||||
//System.out.println("5) Generate CDR3/CDR1 occupancy graph");
|
||||
System.out.println("6) Simulate CDR3/CDR1 T cell matching");
|
||||
System.out.println("7) Acknowledgements");
|
||||
System.out.println("0) Exit");
|
||||
@@ -271,13 +272,13 @@ public class UserInterface {
|
||||
case 1 -> makeCells();
|
||||
case 2 -> makePlate();
|
||||
case 3 -> makeCDR3Graph();
|
||||
case 5 -> matchCells();
|
||||
case 4 -> matchCDR3s();
|
||||
case 6 -> matchCellsCDR1();
|
||||
case 7 -> acknowledge();
|
||||
case 0 -> quit = true;
|
||||
default -> throw new InputMismatchException("Invalid input.");
|
||||
}
|
||||
} catch (InputMismatchException ex) {
|
||||
} catch (InputMismatchException | IOException ex) {
|
||||
System.out.println(ex);
|
||||
sc.next();
|
||||
}
|
||||
@@ -315,40 +316,40 @@ public class UserInterface {
|
||||
writer.writeCellsToFile();
|
||||
}
|
||||
|
||||
//for calling from command line
|
||||
private static void makeCells(String filename, Integer numCells, Integer cdr1Freq){
|
||||
CellSample sample = Simulator.generateCellSample(numCells, cdr1Freq);
|
||||
CellFileWriter writer = new CellFileWriter(filename, sample);
|
||||
writer.writeCellsToFile();
|
||||
}
|
||||
|
||||
private static void makePlateExp(String cellFile, String filename, Double lambda,
|
||||
Integer numWells, Integer[] concentrations, Double dropOutRate){
|
||||
CellFileReader cellReader = new CellFileReader(cellFile);
|
||||
Plate samplePlate = new Plate(numWells, dropOutRate, concentrations);
|
||||
samplePlate.fillWellsExponential(cellReader.getFilename(), cellReader.getCells(), lambda);
|
||||
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
|
||||
writer.writePlateFile();
|
||||
}
|
||||
|
||||
private static void makePlatePoisson(String cellFile, String filename, Integer numWells,
|
||||
Integer[] concentrations, Double dropOutRate){
|
||||
CellFileReader cellReader = new CellFileReader(cellFile);
|
||||
Double stdDev = Math.sqrt(cellReader.getCellCount());
|
||||
Plate samplePlate = new Plate(numWells, dropOutRate, concentrations);
|
||||
samplePlate.fillWells(cellReader.getFilename(), cellReader.getCells(), stdDev);
|
||||
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
|
||||
writer.writePlateFile();
|
||||
}
|
||||
|
||||
private static void makePlate(String cellFile, String filename, Double stdDev,
|
||||
Integer numWells, Integer[] concentrations, Double dropOutRate){
|
||||
CellFileReader cellReader = new CellFileReader(cellFile);
|
||||
Plate samplePlate = new Plate(numWells, dropOutRate, concentrations);
|
||||
samplePlate.fillWells(cellReader.getFilename(), cellReader.getCells(), stdDev);
|
||||
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
|
||||
writer.writePlateFile();
|
||||
}
|
||||
// //for calling from command line
|
||||
// private static void makeCells(String filename, Integer numCells, Integer cdr1Freq){
|
||||
// CellSample sample = Simulator.generateCellSample(numCells, cdr1Freq);
|
||||
// CellFileWriter writer = new CellFileWriter(filename, sample);
|
||||
// writer.writeCellsToFile();
|
||||
// }
|
||||
//
|
||||
// private static void makePlateExp(String cellFile, String filename, Double lambda,
|
||||
// Integer numWells, Integer[] concentrations, Double dropOutRate){
|
||||
// CellFileReader cellReader = new CellFileReader(cellFile);
|
||||
// Plate samplePlate = new Plate(numWells, dropOutRate, concentrations);
|
||||
// samplePlate.fillWellsExponential(cellReader.getFilename(), cellReader.getCells(), lambda);
|
||||
// PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
|
||||
// writer.writePlateFile();
|
||||
// }
|
||||
//
|
||||
// private static void makePlatePoisson(String cellFile, String filename, Integer numWells,
|
||||
// Integer[] concentrations, Double dropOutRate){
|
||||
// CellFileReader cellReader = new CellFileReader(cellFile);
|
||||
// Double stdDev = Math.sqrt(cellReader.getCellCount());
|
||||
// Plate samplePlate = new Plate(numWells, dropOutRate, concentrations);
|
||||
// samplePlate.fillWells(cellReader.getFilename(), cellReader.getCells(), stdDev);
|
||||
// PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
|
||||
// writer.writePlateFile();
|
||||
// }
|
||||
//
|
||||
// private static void makePlate(String cellFile, String filename, Double stdDev,
|
||||
// Integer numWells, Integer[] concentrations, Double dropOutRate){
|
||||
// CellFileReader cellReader = new CellFileReader(cellFile);
|
||||
// Plate samplePlate = new Plate(numWells, dropOutRate, concentrations);
|
||||
// samplePlate.fillWells(cellReader.getFilename(), cellReader.getCells(), stdDev);
|
||||
// PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
|
||||
// writer.writePlateFile();
|
||||
// }
|
||||
|
||||
//method to output a CSV of sample plate
|
||||
private static void makePlate() {
|
||||
@@ -453,69 +454,30 @@ public class UserInterface {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void matchCDR3s(String cellFile, String plateFile, Integer lowThreshold, Integer highThreshold,
|
||||
Integer maxOccupancyDifference, Integer minOverlapPercent){
|
||||
CellFileReader cellReader = new CellFileReader(cellFile);
|
||||
PlateFileReader plateReader = new PlateFileReader(plateFile);
|
||||
Plate plate = new Plate(plateReader.getFilename(), plateReader.getWells());
|
||||
if (cellReader.getCells().size() == 0){
|
||||
System.exit(0);
|
||||
}
|
||||
else if(plate.getWells().size() == 0){
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
else{
|
||||
if(highThreshold >= plate.getSize()){
|
||||
highThreshold = plate.getSize() - 1;
|
||||
}
|
||||
List<Integer[]> cells = cellReader.getCells();
|
||||
MatchingResult results = Simulator.matchCDR3s(cells, plate, lowThreshold, highThreshold, maxOccupancyDifference, minOverlapPercent, false);
|
||||
//result writer
|
||||
MatchingFileWriter writer = new MatchingFileWriter("", results);
|
||||
writer.writeErrorRateToTerminal();
|
||||
}
|
||||
}
|
||||
|
||||
private static void makeCDR3Graph() {
|
||||
String filename = null;
|
||||
String cellFile = null;
|
||||
String plateFile = null;
|
||||
}
|
||||
|
||||
private static void matchCells() {
|
||||
String filename = null;
|
||||
String cellFile = null;
|
||||
String plateFile = null;
|
||||
Integer lowThreshold = 0;
|
||||
Integer highThreshold = Integer.MAX_VALUE;
|
||||
Integer maxOccupancyDiff = 96; //no filtering if max difference is all wells by default
|
||||
Integer minOverlapPercent = 0; //no filtering if min percentage is zero by default
|
||||
try {
|
||||
System.out.println("\nSimulated experiment requires a cell sample file and a sample plate file.");
|
||||
String str = "\nGenerating bipartite weighted graph encoding occupancy data requires ";
|
||||
str.concat("a cell sample file and a sample plate file.");
|
||||
System.out.println(str);
|
||||
System.out.print("Please enter name of an existing cell sample file: ");
|
||||
cellFile = sc.next();
|
||||
System.out.print("Please enter name of an existing sample plate file: ");
|
||||
plateFile = sc.next();
|
||||
System.out.println("The matching results will be written to a file.");
|
||||
System.out.println("The graph and occupancy data will be written to a file.");
|
||||
System.out.print("Please enter a name for the output file: ");
|
||||
filename = sc.next();
|
||||
System.out.println("What is the minimum number of alpha/beta overlap wells to attempt matching?");
|
||||
System.out.println("What is the minimum number of CDR3 alpha/beta overlap wells to include in graph?");
|
||||
lowThreshold = sc.nextInt();
|
||||
if(lowThreshold < 1){
|
||||
throw new InputMismatchException("Minimum value for low threshold is 1");
|
||||
throw new InputMismatchException("Minimum value for low threshold set to 1");
|
||||
}
|
||||
System.out.println("What is the maximum number of alpha/beta overlap wells to attempt matching?");
|
||||
System.out.println("What is the maximum number of CDR3 alpha/beta overlap wells to include in graph?");
|
||||
highThreshold = sc.nextInt();
|
||||
System.out.println("What is the maximum difference in alpha/beta occupancy to attempt matching?");
|
||||
maxOccupancyDiff = sc.nextInt();
|
||||
System.out.println("What is the minimum overlap percentage to attempt matching? (0 - 100)");
|
||||
minOverlapPercent = sc.nextInt();
|
||||
if (minOverlapPercent < 0 || minOverlapPercent > 100) {
|
||||
throw new InputMismatchException("Value outside range. Minimum percent set to 0");
|
||||
}
|
||||
} catch (InputMismatchException ex) {
|
||||
System.out.println(ex);
|
||||
sc.next();
|
||||
@@ -530,23 +492,108 @@ public class UserInterface {
|
||||
else if(plate.getWells().size() == 0){
|
||||
System.out.println("No sample plate found.");
|
||||
System.out.println("Returning to main menu.");
|
||||
|
||||
}
|
||||
else{
|
||||
if(highThreshold >= plate.getSize()){
|
||||
highThreshold = plate.getSize() - 1;
|
||||
}
|
||||
List<Integer[]> cells = cellReader.getCells();
|
||||
MapData maps = Simulator.makeMaps(cells, plate, lowThreshold, true);
|
||||
GraphWithMapData data = Simulator.makeGraph(plate, maps, lowThreshold, highThreshold, true);
|
||||
MatchingResult results = Simulator.matchCDR3s(plate, data, lowThreshold, highThreshold,
|
||||
maxOccupancyDiff,minOverlapPercent, true);
|
||||
//result writer
|
||||
MatchingFileWriter writer = new MatchingFileWriter(filename, results);
|
||||
writer.writeResultsToFile();
|
||||
GraphWithMapData data = Simulator.makeGraph(cells, plate, lowThreshold, highThreshold, true);
|
||||
GraphDataObjectWriter dataWriter = new GraphDataObjectWriter(filename, data);
|
||||
dataWriter.writeDataToFile();
|
||||
}
|
||||
}
|
||||
|
||||
private static void matchCDR3s() throws IOException {
|
||||
String filename = null;
|
||||
String dataFile = null;
|
||||
Integer maxOccupancyDiff = Integer.MAX_VALUE;
|
||||
Integer minOverlapPercent = 0;
|
||||
try {
|
||||
System.out.println("\nSimulated matching experiment requires graph and occupancy data file");
|
||||
System.out.println("Please enter name of an existing graph and occupancy data file: ");
|
||||
dataFile = sc.next();
|
||||
System.out.println("The matching results will be written to a file.");
|
||||
System.out.print("Please enter a name for the output file: ");
|
||||
filename = sc.next();
|
||||
} catch (InputMismatchException ex) {
|
||||
System.out.println(ex);
|
||||
sc.next();
|
||||
}
|
||||
//read object data from file
|
||||
GraphDataObjectReader dataReader = new GraphDataObjectReader(dataFile);
|
||||
GraphWithMapData data = dataReader.getData();
|
||||
//set source file name
|
||||
data.setSourceFilename(dataFile);
|
||||
//simulate matching
|
||||
MatchingResult results = Simulator.matchCDR3s(data, maxOccupancyDiff, minOverlapPercent, true);
|
||||
//write results to file
|
||||
MatchingFileWriter writer = new MatchingFileWriter(filename, results);
|
||||
writer.writeResultsToFile();
|
||||
}
|
||||
|
||||
//old version before I wrote graph data to a file
|
||||
// private static void matchCells() {
|
||||
// String filename = null;
|
||||
// String cellFile = null;
|
||||
// String plateFile = null;
|
||||
// Integer lowThreshold = 0;
|
||||
// Integer highThreshold = Integer.MAX_VALUE;
|
||||
// Integer maxOccupancyDiff = 96; //no filtering if max difference is all wells by default
|
||||
// Integer minOverlapPercent = 0; //no filtering if min percentage is zero by default
|
||||
// try {
|
||||
// System.out.println("\nSimulated experiment requires a cell sample file and a sample plate file.");
|
||||
// System.out.print("Please enter name of an existing cell sample file: ");
|
||||
// cellFile = sc.next();
|
||||
// System.out.print("Please enter name of an existing sample plate file: ");
|
||||
// plateFile = sc.next();
|
||||
// System.out.println("The matching results will be written to a file.");
|
||||
// System.out.print("Please enter a name for the output file: ");
|
||||
// filename = sc.next();
|
||||
// System.out.println("What is the minimum number of alpha/beta overlap wells to attempt matching?");
|
||||
// lowThreshold = sc.nextInt();
|
||||
// if(lowThreshold < 1){
|
||||
// throw new InputMismatchException("Minimum value for low threshold is 1");
|
||||
// }
|
||||
// System.out.println("What is the maximum number of alpha/beta overlap wells to attempt matching?");
|
||||
// highThreshold = sc.nextInt();
|
||||
// System.out.println("What is the maximum difference in alpha/beta occupancy to attempt matching?");
|
||||
// maxOccupancyDiff = sc.nextInt();
|
||||
// System.out.println("What is the minimum overlap percentage to attempt matching? (0 - 100)");
|
||||
// minOverlapPercent = sc.nextInt();
|
||||
// if (minOverlapPercent < 0 || minOverlapPercent > 100) {
|
||||
// throw new InputMismatchException("Value outside range. Minimum percent set to 0");
|
||||
// }
|
||||
// } catch (InputMismatchException ex) {
|
||||
// System.out.println(ex);
|
||||
// sc.next();
|
||||
// }
|
||||
// CellFileReader cellReader = new CellFileReader(cellFile);
|
||||
// PlateFileReader plateReader = new PlateFileReader(plateFile);
|
||||
// Plate plate = new Plate(plateReader.getFilename(), plateReader.getWells());
|
||||
// if (cellReader.getCells().size() == 0){
|
||||
// System.out.println("No cell sample found.");
|
||||
// System.out.println("Returning to main menu.");
|
||||
// }
|
||||
// else if(plate.getWells().size() == 0){
|
||||
// System.out.println("No sample plate found.");
|
||||
// System.out.println("Returning to main menu.");
|
||||
// }
|
||||
// else{
|
||||
// if(highThreshold >= plate.getSize()){
|
||||
// highThreshold = plate.getSize() - 1;
|
||||
// }
|
||||
// List<Integer[]> cells = cellReader.getCells();
|
||||
// GraphWithMapData data = Simulator.makeGraph(cells, plate, lowThreshold, highThreshold, true);
|
||||
// //write data to a file
|
||||
//
|
||||
// MatchingResult results = Simulator.matchCDR3s(data, maxOccupancyDiff,minOverlapPercent, true);
|
||||
// //result writer
|
||||
// MatchingFileWriter writer = new MatchingFileWriter(filename, results);
|
||||
// writer.writeResultsToFile();
|
||||
// }
|
||||
// }
|
||||
|
||||
public static void matchCellsCDR1(){
|
||||
/*
|
||||
The idea here is that we'll get the CDR3 alpha/beta matches first. Then we'll try to match CDR3s to CDR1s by
|
||||
|
||||
Reference in New Issue
Block a user