Skip to content

Commit 6a03307

Browse files
authored
Merge pull request #371 from AdamaJava/qprofiler_options
refactor(qprofiler2): add bad option check for longread
2 parents 88a7a94 + 10219ec commit 6a03307

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

qprofiler2/src/org/qcmg/qprofiler2/QProfiler2.java

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ protected int engage() throws Exception {
9999
index = cmdLineIndexFiles[i];
100100
}
101101
ProfileType type = ProfileType.getType2(f);
102+
if (type != ProfileType.BAM & isLongReadBam) {
103+
throw new Exception( Messages.getMessage(msgResource, "FILE_TYPE_LONG_READ_ERROR"));
104+
}
105+
102106
sortedFiles.computeIfAbsent(type, v -> new ArrayList<>()).add(Pair.of(f, index));
103107
}
104108

qprofiler2/src/org/qcmg/qprofiler2/messages.properties

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ DATA_RECORD_ERROR = Data Record is null, or starts with an invalid character
2929
ID_RECORD_ERROR = ID Record is null, or starts with an invalid character
3030
OUTPUT_FILE_WRITE_ERROR = Cannot write to specified output file
3131
INPUT_FILE_ERROR = Cannot read supplied input file {0}
32+
FILE_TYPE_LONG_READ_ERROR = Long read option can only be chosen for BAM files

qprofiler2/test/org/qcmg/qprofiler2/QProfiler2Test.java

+19
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,25 @@ public final void executeWithInvalidFileType() throws Exception {
130130
}
131131
}
132132

133+
@Test
134+
public final void executeWithInvalidFileTypeAndLongReadOption() throws Exception {
135+
File gffFile = testFolder.newFile("executeWithInvalidFileTypeLongRead.vcf");
136+
File logFile = testFolder.newFile("executeWithInvalidFileTypeLongRead.log");
137+
File inputFile = testFolder.newFile("executeWithInvalidFileTypeLongRead.xml");
138+
139+
String[] args1 = {"-input", inputFile.getAbsolutePath(), "-log", logFile.getAbsolutePath(), "--long-read"};
140+
String[] args2 = new String[]{"-input", gffFile.getAbsolutePath(), "-log", logFile.getAbsolutePath(), "--long-read"};
141+
142+
for (String[] args : new String[][]{args1, args2}) {
143+
try {
144+
new QProfiler2().setup(args);
145+
fail("Should have thrown a QProfilerException");
146+
} catch (Exception qpe) {
147+
assertTrue(qpe.getMessage().contains("Long read option can only be chosen for BAM files"));
148+
}
149+
}
150+
}
151+
133152
@Test
134153
public void schmeFileTest() throws IOException {
135154
String nameSpace = "https://adamajava.org/xsd/qprofiler2/v3";

0 commit comments

Comments
 (0)