diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/transformers/ImageAnalysisLMCSplitter.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/transformers/ImageAnalysisLMCSplitter.java new file mode 100644 index 0000000000000000000000000000000000000000..c4aeb0e7c3ccfad031744a03d893783e50609ff4 --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/transformers/ImageAnalysisLMCSplitter.java @@ -0,0 +1,83 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.screening.transformers; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; + +import com.csvreader.CsvReader; + +/** + * Splits a file with image analysis results for all plates into a set of files, one for each plate. + * + * @author Tomasz Pylak + */ +public class ImageAnalysisLMCSplitter +{ + public static void main(String[] args) throws FileNotFoundException, IOException + { + CsvReader reader = ScreeningLibraryTransformer.readFile(args[0]); + boolean ok = reader.readRecord(); + assert ok; + String[] header = reader.getValues(); + splitPlates(reader, header); + } + + private static void splitPlates(CsvReader reader, String[] header) throws IOException, + FileNotFoundException + { + String prevPlateCode = ""; + OutputStream out = null; + while (reader.readRecord()) + { + String[] row = reader.getValues(); + String plateCode = row[0]; + if (plateCode.equals(prevPlateCode) == false) + { + if (out != null) + { + out.close(); + } + System.out.println("Generating " + plateCode); + out = new FileOutputStream(new File(plateCode + ".csv")); + writeLine(header, out); + prevPlateCode = plateCode; + } + writeLine(row, out); + } + } + + private static void writeLine(String[] header, OutputStream out) throws IOException + { + IOUtils.write(join(header) + "\n", out); + } + + private static String join(String[] tokens) + { + for (int i = 0; i < tokens.length; i++) + { + tokens[i] = tokens[i].replace(';', ','); + } + return StringUtils.join(tokens, ";"); + } +} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/transformers/ScreeningLibraryTransformer.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/transformers/ScreeningLibraryTransformer.java index 1a22475d429af1a4557fdb144b1899c606c39bd3..0a313ee21fb1646292bf86358c87885ded0599ea 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/transformers/ScreeningLibraryTransformer.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/transformers/ScreeningLibraryTransformer.java @@ -60,9 +60,11 @@ public class ScreeningLibraryTransformer return; } String[] headers = csvReader.getValues(); - IScreeningLibraryColumnExtractor extractor = new QiagenScreeningLibraryColumnExtractor(headers); + IScreeningLibraryColumnExtractor extractor = + new QiagenScreeningLibraryColumnExtractor(headers); LibraryEntityRegistrator registrator = - new LibraryEntityRegistrator(extractor, experimentIdentifier, plateGeometry, groupCode); + new LibraryEntityRegistrator(extractor, experimentIdentifier, plateGeometry, + groupCode); while (csvReader.readRecord()) { String[] row = csvReader.getValues(); @@ -71,14 +73,14 @@ public class ScreeningLibraryTransformer System.out.println("Done, look for results in " + new File(".").getAbsolutePath()); } - private static CsvReader readFile(String path) throws FileNotFoundException, IOException + static CsvReader readFile(String path) throws FileNotFoundException, IOException { - File masterPlatesFile = new File(path); - if (masterPlatesFile.isFile() == false) + File file = new File(path); + if (file.isFile() == false) { - error(masterPlatesFile + " does not exist or is not a file."); + error(file + " does not exist or is not a file."); } - FileInputStream fileInputStream = new FileInputStream(masterPlatesFile); + FileInputStream fileInputStream = new FileInputStream(file); CsvReader csvReader = new CsvReader(fileInputStream, Charset.defaultCharset()); csvReader.setDelimiter(SEPARATOR);