Refactor to read/write files of graph and map data
This commit is contained in:
Binary file not shown.
32
src/main/java/GraphDataObjectReader.java
Normal file
32
src/main/java/GraphDataObjectReader.java
Normal file
@@ -0,0 +1,32 @@
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
|
||||
public class GraphDataObjectReader {
|
||||
private GraphWithMapData data;
|
||||
private String filename;
|
||||
|
||||
public GraphDataObjectReader(String filename) throws IOException {
|
||||
if(!filename.matches(".*\\.ser")){
|
||||
filename = filename + ".ser";
|
||||
}
|
||||
this.filename = filename;
|
||||
try(//don't need to close these because of try-with-resources
|
||||
FileInputStream fileIn = new FileInputStream(filename);
|
||||
ObjectInputStream in = new ObjectInputStream(fileIn))
|
||||
{
|
||||
data = (GraphWithMapData) in.readObject();
|
||||
} catch (FileNotFoundException | ClassNotFoundException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public GraphWithMapData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
27
src/main/java/GraphDataObjectWriter.java
Normal file
27
src/main/java/GraphDataObjectWriter.java
Normal file
@@ -0,0 +1,27 @@
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
public class GraphDataObjectWriter {
|
||||
|
||||
private GraphWithMapData data;
|
||||
private String filename;
|
||||
|
||||
public GraphDataObjectWriter(String filename, GraphWithMapData data) {
|
||||
if(!filename.matches(".*\\.ser")){
|
||||
filename = filename + ".ser";
|
||||
}
|
||||
this.filename = filename;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void writeDataToFile() {
|
||||
try (FileOutputStream fileOut = new FileOutputStream(filename);
|
||||
ObjectOutputStream out = new ObjectOutputStream(fileOut);
|
||||
){
|
||||
out.writeObject(data);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,15 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class GraphFileReader {
|
||||
public class GraphMLFileReader {
|
||||
|
||||
private String filename;
|
||||
private SimpleWeightedGraph graph;
|
||||
|
||||
public GraphFileReader(String filename, SimpleWeightedGraph graph) {
|
||||
public GraphMLFileReader(String filename, SimpleWeightedGraph graph) {
|
||||
if(!filename.matches(".*\\.graphml")){
|
||||
filename = filename + ".graphml";
|
||||
}
|
||||
this.filename = filename;
|
||||
this.graph = graph;
|
||||
|
||||
@@ -8,14 +8,15 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
public class GraphFileWriter {
|
||||
public class GraphMLFileWriter {
|
||||
|
||||
String filename;
|
||||
SimpleWeightedGraph graph;
|
||||
|
||||
public GraphFileWriter(String filename, SimpleWeightedGraph graph) {
|
||||
if(!filename.matches(".*\\.gv")){
|
||||
filename = filename + ".gv";
|
||||
|
||||
public GraphMLFileWriter(String filename, SimpleWeightedGraph graph) {
|
||||
if(!filename.matches(".*\\.graphml")){
|
||||
filename = filename + ".graphml";
|
||||
}
|
||||
this.filename = filename;
|
||||
this.graph = graph;
|
||||
@@ -3,52 +3,91 @@ import org.jgrapht.graph.SimpleWeightedGraph;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
|
||||
public class GraphWithMapData {
|
||||
//Can't just write the graph, because I need the occupancy data too.
|
||||
//Makes most sense to serialize object and write that to a file.
|
||||
//Which means there's no reason to split map data and graph data up.
|
||||
public class GraphWithMapData implements java.io.Serializable {
|
||||
|
||||
private String sourceFilename;
|
||||
private final SimpleWeightedGraph graph;
|
||||
private final MapData maps;
|
||||
private Integer numWells;
|
||||
private Integer lowThreshold;
|
||||
private Integer highThreshold;
|
||||
private final Map<Integer, Integer> distCellsMapAlphaKey;
|
||||
private final Map<Integer, Integer> allAlphas;
|
||||
private final Map<Integer, Integer> allBetas;
|
||||
private final Map<Integer, Integer> plateVtoAMap;
|
||||
private final Map<Integer, Integer> plateVtoBMap;
|
||||
private final Map<Integer, Integer> plateAtoVMap;
|
||||
private final Map<Integer, Integer> plateBtoVMap;
|
||||
private final Map<Integer, Integer> alphaWellCounts;
|
||||
private final Map<Integer, Integer> betaWellCounts;
|
||||
private final Duration time;
|
||||
|
||||
public GraphWithMapData(SimpleWeightedGraph graph, MapData maps, Map<Integer, Integer> alphaWellCounts,
|
||||
public GraphWithMapData(SimpleWeightedGraph graph, Integer numWells, Integer lowThreshold, Integer highThreshold,
|
||||
Map<Integer, Integer> distCellsMapAlphaKey, Map<Integer, Integer> allAlphas,
|
||||
Map<Integer, Integer> allBetas, Map<Integer, Integer> plateVtoAMap,
|
||||
Map<Integer,Integer> plateVtoBMap, Map<Integer, Integer> plateAtoVMap,
|
||||
Map<Integer, Integer> plateBtoVMap, Map<Integer, Integer> alphaWellCounts,
|
||||
Map<Integer, Integer> betaWellCounts, Duration time) {
|
||||
this.graph = graph;
|
||||
this.maps = maps;
|
||||
this.numWells = numWells;
|
||||
this.lowThreshold = lowThreshold;
|
||||
this.highThreshold = highThreshold;
|
||||
this.distCellsMapAlphaKey = distCellsMapAlphaKey;
|
||||
this.allAlphas = allAlphas;
|
||||
this.allBetas = allBetas;
|
||||
this.plateVtoAMap = plateVtoAMap;
|
||||
this.plateVtoBMap = plateVtoBMap;
|
||||
this.plateAtoVMap = plateAtoVMap;
|
||||
this.plateBtoVMap = plateBtoVMap;
|
||||
this.alphaWellCounts = alphaWellCounts;
|
||||
this.betaWellCounts = betaWellCounts;
|
||||
this.time = time.plus(maps.getTime());
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public SimpleWeightedGraph getGraph() {
|
||||
return graph;
|
||||
}
|
||||
|
||||
public Integer getNumWells() {
|
||||
return numWells;
|
||||
}
|
||||
|
||||
public Integer getLowThreshold() {
|
||||
return lowThreshold;
|
||||
}
|
||||
|
||||
public Integer getHighThreshold() {
|
||||
return highThreshold;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getDistCellsMapAlphaKey() {
|
||||
return maps.getDistCellsMapAlphaKey();
|
||||
return distCellsMapAlphaKey;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getAllAlphas() {
|
||||
return maps.getAllAlphas();
|
||||
return allAlphas;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getAllBetas() {
|
||||
return maps.getAllBetas();
|
||||
return allBetas;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getPlateVtoAMap() {
|
||||
return maps.getPlateVtoAMap();
|
||||
return plateVtoAMap;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getPlateVtoBMap() {
|
||||
return maps.getPlateVtoBMap();
|
||||
return plateVtoBMap;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getPlateAtoVMap() {
|
||||
return maps.getPlateAtoVMap();
|
||||
return plateAtoVMap;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getPlateBtoVMap() {
|
||||
return maps.getPlateBtoVMap();
|
||||
return plateBtoVMap;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getAlphaWellCounts() {
|
||||
@@ -62,4 +101,12 @@ public class GraphWithMapData {
|
||||
public Duration getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setSourceFilename(String filename) {
|
||||
this.sourceFilename = filename;
|
||||
}
|
||||
|
||||
public String getSourceFilename() {
|
||||
return sourceFilename;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import org.jgrapht.graph.SimpleWeightedGraph;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
|
||||
public class MapData {
|
||||
private final Map<Integer, Integer> distCellsMapAlphaKey;
|
||||
private final Map<Integer, Integer> allAlphas;
|
||||
private final Map<Integer, Integer> allBetas;
|
||||
private final Map<Integer, Integer> plateVtoAMap;
|
||||
private final Map<Integer, Integer> plateVtoBMap;
|
||||
private final Map<Integer, Integer> plateAtoVMap;
|
||||
private final Map<Integer, Integer> plateBtoVMap;
|
||||
|
||||
private final Duration time;
|
||||
|
||||
public MapData(Map<Integer, Integer> distCellsMapAlphaKey,
|
||||
Map<Integer, Integer> allAlphas, Map<Integer, Integer> allBetas,
|
||||
Map<Integer, Integer> plateVtoAMap, Map<Integer, Integer> plateVtoBMap,
|
||||
Map<Integer, Integer> plateAtoVMap, Map<Integer, Integer> plateBtoVMap,
|
||||
Duration time) {
|
||||
this.distCellsMapAlphaKey = distCellsMapAlphaKey;
|
||||
this.allAlphas = allAlphas;
|
||||
this.allBetas = allBetas;
|
||||
this.plateVtoAMap = plateVtoAMap;
|
||||
this.plateVtoBMap = plateVtoBMap;
|
||||
this.plateAtoVMap = plateAtoVMap;
|
||||
this.plateBtoVMap = plateBtoVMap;
|
||||
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getDistCellsMapAlphaKey() {
|
||||
return distCellsMapAlphaKey;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getAllAlphas() {
|
||||
return allAlphas;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getAllBetas() {
|
||||
return allBetas;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getPlateVtoAMap() {
|
||||
return plateVtoAMap;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getPlateVtoBMap() {
|
||||
return plateVtoBMap;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getPlateAtoVMap() {
|
||||
return plateAtoVMap;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getPlateBtoVMap() {
|
||||
return plateBtoVMap;
|
||||
}
|
||||
|
||||
public Duration getTime() {
|
||||
return time;
|
||||
}
|
||||
}
|
||||
@@ -55,13 +55,13 @@ public class Simulator {
|
||||
// }
|
||||
|
||||
|
||||
//Make the maps needed for matching CDR3s
|
||||
public static MapData makeMaps(List<Integer[]> distinctCells,
|
||||
Plate samplePlate, Integer lowThreshold, boolean verbose) {
|
||||
//Make the graph needed for matching CDR3s
|
||||
public static GraphWithMapData makeGraph(List<Integer[]> distinctCells, Plate samplePlate, Integer lowThreshold,
|
||||
Integer highThreshold, boolean verbose) {
|
||||
Instant start = Instant.now();
|
||||
int numWells = samplePlate.getSize();
|
||||
int[] alphaIndex = {cdr3AlphaIndex};
|
||||
int[] betaIndex = {cdr3BetaIndex};
|
||||
int numWells = samplePlate.getSize();
|
||||
|
||||
if(verbose){System.out.println("Making cell maps");}
|
||||
//HashMap keyed to Alphas, values Betas
|
||||
@@ -109,24 +109,6 @@ public class Simulator {
|
||||
//keys are betas, values are sequential integer vertices from previous map
|
||||
Map<Integer, Integer> plateBtoVMap = invertVertexMap(plateVtoBMap);
|
||||
if(verbose){System.out.println("Vertex maps made");}
|
||||
Instant stop = Instant.now();
|
||||
Duration time = Duration.between(start, stop);
|
||||
return new MapData(distCellsMapAlphaKey, allAlphas, allBetas, plateVtoAMap, plateVtoBMap, plateAtoVMap,
|
||||
plateBtoVMap, time);
|
||||
}
|
||||
|
||||
//Make the graph needed for matching CDR3s
|
||||
public static GraphWithMapData makeGraph(Plate samplePlate, MapData maps, Integer lowThreshold,
|
||||
Integer highThreshold, boolean verbose) {
|
||||
int[] alphaIndex = {cdr3AlphaIndex};
|
||||
int[] betaIndex = {cdr3BetaIndex};
|
||||
Instant start = Instant.now();
|
||||
Map<Integer, Integer> plateVtoAMap = maps.getPlateVtoAMap();
|
||||
Map<Integer, Integer> plateVtoBMap = maps.getPlateVtoBMap();
|
||||
Map<Integer, Integer> plateAtoVMap = maps.getPlateAtoVMap();
|
||||
Map<Integer, Integer> plateBtoVMap = maps.getPlateBtoVMap();
|
||||
Map<Integer, Integer> allAlphas = maps.getAllAlphas();
|
||||
Map<Integer, Integer> allBetas = maps.getAllBetas();
|
||||
|
||||
if(verbose){System.out.println("Creating adjacency matrix");}
|
||||
//Count how many wells each alpha appears in
|
||||
@@ -160,16 +142,18 @@ public class Simulator {
|
||||
if(verbose){System.out.println("Over- and under-weight edges set to 0.0");}
|
||||
Instant stop = Instant.now();
|
||||
Duration time = Duration.between(start, stop);
|
||||
time = time.plus(maps.getTime());
|
||||
return new GraphWithMapData(graph, maps, alphaWellCounts, betaWellCounts, time);
|
||||
return new GraphWithMapData(graph, numWells, lowThreshold, highThreshold, distCellsMapAlphaKey, allAlphas,
|
||||
allBetas, plateVtoAMap, plateVtoBMap, plateAtoVMap, plateBtoVMap, alphaWellCounts, betaWellCounts,
|
||||
time);
|
||||
}
|
||||
|
||||
//match CDR3s
|
||||
public static MatchingResult matchCDR3s(Plate samplePlate, GraphWithMapData data, Integer lowThreshold,
|
||||
Integer highThreshold, Integer maxOccupancyDifference,
|
||||
public static MatchingResult matchCDR3s(GraphWithMapData data, Integer maxOccupancyDifference,
|
||||
Integer minOverlapPercent, boolean verbose) {
|
||||
Instant start = Instant.now();
|
||||
int numWells = samplePlate.getSize();
|
||||
int numWells = data.getNumWells();
|
||||
Integer highThreshold = data.getHighThreshold();
|
||||
Integer lowThreshold = data.getLowThreshold();
|
||||
Map<Integer, Integer> distCellsMapAlphaKey = data.getDistCellsMapAlphaKey();
|
||||
Map<Integer, Integer> plateVtoAMap = data.getPlateVtoAMap();
|
||||
Map<Integer, Integer> plateVtoBMap = data.getPlateVtoBMap();
|
||||
@@ -280,7 +264,7 @@ public class Simulator {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
return new MatchingResult(samplePlate.getSourceFileName(), comments, header, allResults, matchMap, time);
|
||||
return new MatchingResult(data.getSourceFilename(), comments, header, allResults, matchMap, time);
|
||||
}
|
||||
|
||||
public static MatchingResult matchCDR3s(List<Integer[]> distinctCells,
|
||||
@@ -371,7 +355,7 @@ public class Simulator {
|
||||
if(verbose){System.out.println("Graph created");}
|
||||
|
||||
//write graph to file
|
||||
GraphFileWriter writer = new GraphFileWriter("graph", graph);
|
||||
GraphMLFileWriter writer = new GraphMLFileWriter("graph", graph);
|
||||
writer.writeGraphToFile();
|
||||
|
||||
if(verbose){System.out.println("Eliminating edges with weights outside threshold values");}
|
||||
|
||||
@@ -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