Change plate reader/writer to use columns as wells

This commit is contained in:
2022-02-20 19:12:11 -06:00
parent 9adb7dffb8
commit d1bb49b482
2 changed files with 48 additions and 16 deletions

View File

@@ -31,23 +31,55 @@ public class PlateFileReader {
BufferedReader reader = Files.newBufferedReader(Path.of(filename));
CSVParser parser = new CSVParser(reader, plateFileFormat);
){
for(CSVRecord record: parser.getRecords()) {
List<Integer[]> well = new ArrayList<>();
for(String s: record) {
if(!"".equals(s)) {
String[] intString = s.replaceAll("\\[", "")
.replaceAll("]", "")
.replaceAll(" ", "")
.split(",");
//System.out.println(intString);
Integer[] arr = new Integer[intString.length];
for (int i = 0; i < intString.length; i++) {
arr[i] = Integer.valueOf(intString[i]);
}
well.add(arr);
}
//old code for wells as rows
// for(CSVRecord record: parser.getRecords()) {
// List<Integer[]> well = new ArrayList<>();
// for(String s: record) {
// if(!"".equals(s)) {
// String[] intString = s.replaceAll("\\[", "")
// .replaceAll("]", "")
// .replaceAll(" ", "")
// .split(",");
// //System.out.println(intString);
// Integer[] arr = new Integer[intString.length];
// for (int i = 0; i < intString.length; i++) {
// arr[i] = Integer.valueOf(intString[i]);
// }
// well.add(arr);
// }
// }
// wells.add(well);
for(CSVRecord record: parser) {
if (record.hasComment()) {
continue;
}
if (wells.size() == 0) {
int num = record.size();
for (int i = 0; i < num; i++) {
wells.add(new ArrayList<>());
}
continue;
} else {
int i = 0;
for (String s : record) {
if (!"".equals(s)) { //if value isn't the empty string
//get rid of brackts, split at commas into a string array
String[] intsAsStrings = s.replaceAll("\\[", "")
.replaceAll("]", "")
.replaceAll(" ", "")
.split(",");
//Make Integer array with the same values
Integer[] arr = new Integer[intsAsStrings.length];
for (int j = 0; j < intsAsStrings.length; j++) {
arr[j] = Integer.valueOf(intsAsStrings[j]);
}
//Add Integer array to the correct well
wells.get(i).add(arr);
i++;
}
}
}
wells.add(well);
}
} catch(IOException ex){
System.out.println("plate file " + filename + " not found.");