Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Jan 16, 2024
2 parents 5c2d7cb + e01eb97 commit 4c89e37
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>genepi</groupId>
<artifactId>genomic-utils</artifactId>
<version>0.3.6</version>
<version>0.3.7</version>
<packaging>jar</packaging>

<name>genomic-utils</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/genepi/genomic/utils/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class App {

public static final String APP = "genomic-utils";

public static final String VERSION = "0.3.6";
public static final String VERSION = "0.3.7";

public static final String URL = "https://github.com/genepi/genomic-utils";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public class CsvFilterCommand implements Callable<Integer> {

@Option(names = "--output", description = "Output file ", required = true)
private String output;

@Option(names = "--filter-column", description = "Column name to apply filter", required = true)
private String filterColumn = "";

@Option(names = "--ignore-values", description = "Values to ignore from the filter column", required = false)
private String ignoreValues = "";

@Option(names = "--limit", description = "Specifiy upper limit to filter", required = true)
private double limit;

Expand All @@ -35,7 +35,7 @@ public class CsvFilterCommand implements Callable<Integer> {

@Option(names = "--output-sep", description = "Separator of output file. default: ,", required = false, showDefaultValue = Visibility.ALWAYS)
private char outputSeparator = ',';

@Option(names = { "--gz" }, description = "Write file as gzip", required = false)
private boolean outputGzip = false;

Expand All @@ -49,27 +49,27 @@ public void setInput(String input) {
public void setOutput(String output) {
this.output = output;
}

public void setGzip(boolean outputGzip) {
this.outputGzip = outputGzip;
}

public void setSeparator(char sep) {
this.separator = sep;
}

public void setOutputSeparator(char outputSep) {
this.outputSeparator = outputSep;
}

public void setLimit(int limit) {
this.limit = limit;
}

public void setFilterColumn(String filterColumn) {
this.filterColumn = filterColumn;
}

public void setIgnoreValues(String ignoreValues) {
this.ignoreValues = ignoreValues;
}
Expand All @@ -78,33 +78,39 @@ public Integer call() throws Exception {

assert (input != null);
assert (output != null);

ITableWriter writer = null;
if (outputGzip) {
writer = new GzipCsvTableWriter(output, outputSeparator, outputQuote);
} else {
writer = new CsvTableWriter(output, outputSeparator, outputQuote);
}

List<String> ignoreList = Arrays.asList(ignoreValues.split(","));
List<String> ignoreList = Arrays.asList(ignoreValues.split(","));

CsvTableReader reader = new CsvTableReader(input, separator);

writer.setColumns(reader.getColumns());
if(!reader.hasColumn(filterColumn)) {

if (!reader.hasColumn(filterColumn)) {
System.err.println("Column " + filterColumn + "not found.");
return 1;
}

int line = 0;
while (reader.next()) {

line++;
String value = reader.getString(filterColumn);
if (ignoreList.contains(value) || Double.valueOf(value) < limit) {
continue;
try {

if (ignoreList.contains(value) || Double.valueOf(value) < limit) {
continue;
}
writer.setRow(reader.getRow());
writer.next();
} catch (NumberFormatException e) {
System.out.println("Ignoring line " + line + ". Value '" + value + "' cannot be parsed.");
}
writer.setRow(reader.getRow());
writer.next();
}

reader.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void testGzFilteringWithNAValues() throws Exception {
command.setLimit(2);
command.setGzip(true);
command.setFilterColumn("LOG10P");
command.setIgnoreValues("NA");
//command.setIgnoreValues("NA");
assertEquals(0, (int) command.call());

assertEquals(FileUtil.readFileAsString(new GzipCompressorInputStream(new FileInputStream(output))),
Expand Down

0 comments on commit 4c89e37

Please sign in to comment.