Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 11 additions & 44 deletions src/main/java/uk/ac/ebi/ena/readtools/v2/cli/ValidateCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@
import java.util.List;
import java.util.stream.Collectors;
import uk.ac.ebi.ena.readtools.v2.FileFormat;
import uk.ac.ebi.ena.readtools.v2.validator.ReadsValidationException;
import uk.ac.ebi.ena.readtools.v2.validator.ValidatorWrapper;

/**
* Standalone CLI wrapper around {@link ValidatorWrapper}, running the same client-side read
* validation that webin-cli performs, without the manifest / upload machinery.
* Standalone CLI wrapper around the v2 validator, running the same client-side read validation that
* webin-cli performs, without the manifest / upload machinery.
*
* <p>Usage: java -cp readtools-all.jar uk.ac.ebi.ena.readtools.v2.cli.ValidateCli \ --format FASTQ
* [--full] file1 [file2]
*/
public class ValidateCli {
// webin-cli's own limits: quick = first 100k reads, extended = first 100M reads.
private static final long QUICK_READ_LIMIT = 100_000L;
private static final long EXTENDED_READ_LIMIT = 100_000_000L;

@Parameter(
names = {"--format", "-f"},
Expand All @@ -52,8 +47,15 @@ public class ValidateCli {
private boolean help = false;

public static void main(String[] args) {
// `java -jar readtools.jar server ...` starts the warm validation server instead.
if (args.length > 0 && "server".equals(args[0])) {
ValidateServer.main(java.util.Arrays.copyOfRange(args, 1, args.length));
return;
}

ValidateCli cli = new ValidateCli();
JCommander jc = JCommander.newBuilder().addObject(cli).programName("readtools-validate").build();
JCommander jc =
JCommander.newBuilder().addObject(cli).programName("readtools-validate").build();

try {
jc.parse(args);
Expand All @@ -73,41 +75,6 @@ public static void main(String[] args) {

private int run() {
List<File> fileList = files.stream().map(File::new).collect(Collectors.toList());
for (File f : fileList) {
if (!f.isFile()) {
System.err.println("ERROR: file not found: " + f.getPath());
return 2;
}
}

long limit = full ? EXTENDED_READ_LIMIT : QUICK_READ_LIMIT;
ValidatorWrapper wrapper = new ValidatorWrapper(fileList, format, limit);

try {
wrapper.run();
} catch (ReadsValidationException e) {
System.out.println("RESULT: INVALID");
System.out.println(" " + e.getMessage());
return 1;
} catch (RuntimeException e) {
System.out.println("RESULT: INVALID (file structure / parse error)");
System.out.println(" " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
return 1;
}

System.out.println("RESULT: VALID");
System.out.println(" format: " + format);
System.out.println(" mode: " + (full ? "full (<=100M reads)" : "quick (<=100k reads)"));
if (format == FileFormat.FASTQ && fileList.size() > 1) {
System.out.println(" paired: " + wrapper.isPaired());
}
wrapper
.getFileQualityStats()
.forEach(
s ->
System.out.printf(
" %s: reads=%d, highQuality(avg>=30)=%d%n",
s.getFile().getName(), s.getReadCount(), s.getHighQualityReadCount()));
return 0;
return ValidationRunner.validate(fileList, format, full, System.out, System.err);
}
}
Loading