From 26f700519ce0b9cf7b6bc2fcde1f0e8c4420a7d7 Mon Sep 17 00:00:00 2001 From: Andrewss Date: Tue, 18 Aug 2020 17:35:15 +0100 Subject: [PATCH] Add CRAM reference to the options in the wrapper. Relates to #54 --- fastqc | 19 +++++++++++++++++-- uk/ac/babraham/FastQC/FastQCConfig.java | 11 ++++++++++- uk/ac/babraham/FastQC/Sequence/BAMFile.java | 8 +++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/fastqc b/fastqc index eb52c8d..c221ee1 100755 --- a/fastqc +++ b/fastqc @@ -88,6 +88,7 @@ if ($^O =~/darwin/) { my $version; my $help; my $outdir; +my $reference; my $unzip; my $format; my $contaminant; @@ -110,6 +111,7 @@ my $result = GetOptions('version' => \$version, 'nogroup' => \$nogroup, 'expgroup' => \$expgroup, 'outdir=s' => \$outdir, + 'reference=s' -> \$reference, 'extract!' => \$unzip, 'format=s' => \$format, 'threads=i' => \$threads, @@ -146,6 +148,14 @@ if ($outdir) { push @java_args ,"-Dfastqc.output_dir=$outdir"; } +if ($reference) { + unless(-e $reference and -f $reference) { + die "Specified reference file '$reference' does not exist\n"; + } + + push @java_args ,"-Dfastqc.reference=$reference"; +} + if ($contaminant) { unless (-e $contaminant and -r $contaminant) { die "Contaminant file '$contaminant' did not exist, or could not be read\n"; @@ -387,7 +397,12 @@ DESCRIPTION -f --format Bypasses the normal sequence file format detection and forces the program to use the specified format. Valid - formats are bam,sam,bam_mapped,sam_mapped and fastq + formats are bam,sam,cram,bam_mapped,sam_mapped,cram_mapped + and fastq + + -r --reference Only relevant when parsing CRAM files. Specifies a fasta format + file of reference sequences which can be used to decode the + CRAM entries. -t --threads Specifies the number of files which can be processed simultaneously. Each thread will be allocated 250MB of @@ -427,6 +442,6 @@ DESCRIPTION BUGS Any bugs in fastqc should be reported either to simon.andrews@babraham.ac.uk - or in www.bioinformatics.babraham.ac.uk/bugzilla/ + or in https://github.com/s-andrews/fastqc/issues diff --git a/uk/ac/babraham/FastQC/FastQCConfig.java b/uk/ac/babraham/FastQC/FastQCConfig.java index 649a7a8..4bb18d5 100644 --- a/uk/ac/babraham/FastQC/FastQCConfig.java +++ b/uk/ac/babraham/FastQC/FastQCConfig.java @@ -32,6 +32,7 @@ public class FastQCConfig { public Integer threads = null; public boolean showUpdates = true; public File output_dir = null; + public File reference = null; public boolean casava = false; public boolean nano = false; public boolean nofilter = false; @@ -52,7 +53,15 @@ private FastQCConfig () { throw new IllegalArgumentException("Output dir "+output_dir+" doesn't exist or isn't writeable"); } } - + + // CRAM Reference + if (System.getProperty("fastqc.reference") != null) { + reference = new File(System.getProperty("fastqc.reference")); + if (!(reference.exists() && reference.canRead())) { + throw new IllegalArgumentException("Reference file "+reference+" doesn't exist or can't be read"); + } + } + // Contaminant file if (System.getProperty("fastqc.contaminant_file") != null) { contaminant_file = new File(System.getProperty("fastqc.contaminant_file")); diff --git a/uk/ac/babraham/FastQC/Sequence/BAMFile.java b/uk/ac/babraham/FastQC/Sequence/BAMFile.java index c26eb21..ab267ab 100644 --- a/uk/ac/babraham/FastQC/Sequence/BAMFile.java +++ b/uk/ac/babraham/FastQC/Sequence/BAMFile.java @@ -33,6 +33,7 @@ import htsjdk.samtools.SamReader; import htsjdk.samtools.SamReaderFactory; import htsjdk.samtools.ValidationStringency; +import uk.ac.babraham.FastQC.FastQCConfig; public class BAMFile implements SequenceFile { @@ -63,7 +64,12 @@ protected BAMFile (File file, boolean onlyMapped) throws SequenceFormatException SamInputResource sir = SamInputResource.of(fis); - br = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).referenceSequence(new File("c:/Users/andrewss/Desktop/phix-illumina.fa")).open(sir); + if (FastQCConfig.getInstance().reference != null) { + br = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).referenceSequence(FastQCConfig.getInstance().reference).open(sir); + } + else { + br = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).open(sir); + } it = br.iterator(); readNext();