Skip to content

Commit

Permalink
Can now process compressed or not data files.
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorRodchenkov committed Mar 10, 2024
1 parent e7799c9 commit 26de2a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ to run without any command line options to see the help text:
can use special values: 'defined', 'undefined', and 'null') [optional]
-x,--interaction <arg> structured chemical-gene interaction file (XML)
[optional]
Note: the input data files can be compressed, e.g. CTD_genes.csv.gz

If you want to test the converter though, you can download small (old) example
files from [goal2_ctd_smallSampleInputFiles-20140702.zip](https://bitbucket.org/armish/gsoc14/downloads/goal2_ctd_smallSampleInputFiles-20140702.zip).
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/org/ctdbase/CtdToBiopax.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ctdbase;

import org.apache.commons.lang3.StringUtils;
import org.biopax.paxtools.model.level3.UtilityClass;
import org.ctdbase.converter.CTDChemicalConverter;
import org.ctdbase.converter.CTDGeneConverter;
Expand All @@ -11,14 +12,15 @@
import org.biopax.paxtools.io.SimpleIOHandler;
import org.biopax.paxtools.model.BioPAXElement;
import org.biopax.paxtools.model.Model;
import org.biopax.paxtools.model.level3.EntityReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
import java.util.zip.GZIPInputStream;

public class CtdToBiopax {
private static Logger log = LoggerFactory.getLogger(CtdToBiopax.class);
Expand Down Expand Up @@ -61,23 +63,23 @@ public static void main( String[] args ) {
}
Converter converter = new CTDInteractionConverter(taxonomy);
log.info("Option 'x'. Using " + converter.getClass().getSimpleName() + " to convert: " + fileName);
Model model = converter.convert(new FileInputStream(fileName));
Model model = converter.convert(inputDataStream(fileName));
merger.merge(finalModel, model);
}

if(commandLine.hasOption("g")) {
String fileName = commandLine.getOptionValue("g");
Converter converter = new CTDGeneConverter();
log.info("Option 'g'. Using " + converter.getClass().getSimpleName() + " to convert: " + fileName);
Model model = converter.convert(new FileInputStream(fileName));
Model model = converter.convert(inputDataStream(fileName));
merger.merge(finalModel, model);
}

if(commandLine.hasOption("c")) {
String fileName = commandLine.getOptionValue("c");
Converter converter = new CTDChemicalConverter();
log.info("Option 'c'. Using " + converter.getClass().getSimpleName() + " to convert: " + fileName);
Model model = converter.convert(new FileInputStream(fileName));
Model model = converter.convert(inputDataStream(fileName));
merger.merge(finalModel, model);
}

Expand All @@ -103,4 +105,12 @@ public static void main( String[] args ) {
}
}

static InputStream inputDataStream(String fileName) throws IOException {
InputStream inputStream = new FileInputStream(fileName);
if (StringUtils.endsWith(fileName, ".gz")) {
inputStream = new GZIPInputStream(inputStream);
}
return inputStream;
}

}

0 comments on commit 26de2a6

Please sign in to comment.