Skip to content
Snippets Groups Projects
Commit fc10139f authored by tpylak's avatar tpylak
Browse files

SE-209 LMC: transformer for analysis data

SVN: 14748
parent 7c3f7c97
No related branches found
No related tags found
No related merge requests found
/*
* 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, ";");
}
}
...@@ -60,9 +60,11 @@ public class ScreeningLibraryTransformer ...@@ -60,9 +60,11 @@ public class ScreeningLibraryTransformer
return; return;
} }
String[] headers = csvReader.getValues(); String[] headers = csvReader.getValues();
IScreeningLibraryColumnExtractor extractor = new QiagenScreeningLibraryColumnExtractor(headers); IScreeningLibraryColumnExtractor extractor =
new QiagenScreeningLibraryColumnExtractor(headers);
LibraryEntityRegistrator registrator = LibraryEntityRegistrator registrator =
new LibraryEntityRegistrator(extractor, experimentIdentifier, plateGeometry, groupCode); new LibraryEntityRegistrator(extractor, experimentIdentifier, plateGeometry,
groupCode);
while (csvReader.readRecord()) while (csvReader.readRecord())
{ {
String[] row = csvReader.getValues(); String[] row = csvReader.getValues();
...@@ -71,14 +73,14 @@ public class ScreeningLibraryTransformer ...@@ -71,14 +73,14 @@ public class ScreeningLibraryTransformer
System.out.println("Done, look for results in " + new File(".").getAbsolutePath()); 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); File file = new File(path);
if (masterPlatesFile.isFile() == false) 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 csvReader = new CsvReader(fileInputStream, Charset.defaultCharset());
csvReader.setDelimiter(SEPARATOR); csvReader.setDelimiter(SEPARATOR);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment