Skip to content

Commit

Permalink
Check if mapping file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
seppinho committed Mar 2, 2024
1 parent 6361dea commit 125f4b8
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions src/main/java/genepi/mut/commands/StatisticsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class StatisticsCommand implements Callable<Integer> {
@Option(names = { "--input" }, description = "\"Input file", required = true)
private String input;

@Option(names = { "--mapping" }, description = "\"Mapping file", required = true)
private String mapping;
@Option(names = { "--mapping" }, description = "\"Mapping file", required = false)
private String mapping = null;

@Option(names = { "--output-excluded-samples" }, description = "\"Exclude file", required = true)
private String output;
Expand Down Expand Up @@ -93,34 +93,36 @@ public Integer call() throws IOException {
List<String> contigs = new ArrayList<String>();
StringBuffer text = new StringBuffer();

BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(mapping));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return -1;
}
String line;
ArrayList<String> sampleList = new ArrayList<>();

// header
reader.readLine();

while ((line = reader.readLine()) != null) {
String sampleName = line.split("\t")[0];
String fileName = line.split("\t")[1];
if (sampleList.contains(sampleName)) {
text.append("\n<b>Error:</b> Duplicate sample name for sample '" + sampleName + "' (Filename: "
+ fileName + ".<br>mtDNA analysis cannot be started!");
context.error(text.toString());
reader.close();
if (mapping != null) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(mapping));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return -1;
}
String line;
ArrayList<String> sampleList = new ArrayList<>();

// header
reader.readLine();

while ((line = reader.readLine()) != null) {
String sampleName = line.split("\t")[0];
String fileName = line.split("\t")[1];
if (sampleList.contains(sampleName)) {
text.append("\n<b>Error:</b> Duplicate sample name for sample '" + sampleName + "' (Filename: "
+ fileName + ".<br>mtDNA analysis cannot be started!");
context.error(text.toString());
reader.close();
return -1;
}

sampleList.add(sampleName);
sampleList.add(sampleName);
}
reader.close();
}
reader.close();

for (StatisticsFile sample : samples) {

Expand Down

0 comments on commit 125f4b8

Please sign in to comment.