Skip to content

Commit

Permalink
Added a basic test implementation using the latest htsjdk
Browse files Browse the repository at this point in the history
This uses htsjdk 2.23.0 but currently hardcodes the reference path.

It fails for the test case because of versioning issues.

Refers to #54
  • Loading branch information
Andrewss authored and Andrewss committed Aug 18, 2020
1 parent 3e35053 commit 36d48a4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="jbzip2-0.9.jar"/>
<classpathentry kind="lib" path="sam-1.103.jar"/>
<classpathentry kind="lib" path="cisd-jhdf5.jar"/>
<classpathentry kind="lib" path="htsjdk.jar"/>
<classpathentry kind="lib" path="commons-compress.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file removed sam-1.103.jar
Binary file not shown.
1 change: 1 addition & 0 deletions uk/ac/babraham/FastQC/FileFilters/SequenceFileFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public boolean accept(File f) {
|| f.getName().toLowerCase().endsWith(".fastq")
|| f.getName().toLowerCase().endsWith(".bam")
|| f.getName().toLowerCase().endsWith(".sam")
|| f.getName().toLowerCase().endsWith(".cram")
|| f.getName().toLowerCase().endsWith(".compact-reads")
|| f.getName().toLowerCase().endsWith(".goby")

Expand Down
27 changes: 17 additions & 10 deletions uk/ac/babraham/FastQC/Sequence/BAMFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
import java.util.Iterator;
import java.util.List;

import net.sf.samtools.CigarElement;
import net.sf.samtools.CigarOperator;
import net.sf.samtools.SAMFileReader;
import net.sf.samtools.SAMFormatException;
import net.sf.samtools.SAMRecord;
import htsjdk.samtools.CigarElement;
import htsjdk.samtools.CigarOperator;
import htsjdk.samtools.SAMFormatException;
import htsjdk.samtools.SAMRecord;
import htsjdk.samtools.SamInputResource;
import htsjdk.samtools.SamReader;
import htsjdk.samtools.SamReaderFactory;
import htsjdk.samtools.ValidationStringency;


public class BAMFile implements SequenceFile {

Expand All @@ -43,7 +47,7 @@ public class BAMFile implements SequenceFile {
// only way to access the file pointer.
private FileInputStream fis;

private SAMFileReader br;
private SamReader br;
private String name;
private Sequence nextSequence = null;
Iterator<SAMRecord> it;
Expand All @@ -55,11 +59,11 @@ protected BAMFile (File file, boolean onlyMapped) throws SequenceFormatException
name = file.getName();
this.onlyMapped = onlyMapped;

SAMFileReader.setDefaultValidationStringency(SAMFileReader.ValidationStringency.SILENT);

fis = new FileInputStream(file);

br = new SAMFileReader(fis);
SamInputResource sir = SamInputResource.of(fis);

br = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).referenceSequence(new File("c:/Users/andrewss/Desktop/phix-illumina.fa")).open(sir);

it = br.iterator();
readNext();
Expand Down Expand Up @@ -134,7 +138,10 @@ record = it.next();
// through the file.
if (recordSize == 0) {
recordSize = (record.getReadLength()*2)+150;
if (br.isBinary()) {

// TODO: Work out if this is actually needed or if we can pull
// what we need from the fis
if (true) {
recordSize /= 4;
}
}
Expand Down
6 changes: 3 additions & 3 deletions uk/ac/babraham/FastQC/Sequence/SequenceFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public static SequenceFile getSequenceFile(File file) throws SequenceFormatExcep
if (config.sequence_format != null) {
// We're not autodetecting the format, but taking whatever they said

if (config.sequence_format.equals("bam") || config.sequence_format.equals("sam")) {
if (config.sequence_format.equals("bam") || config.sequence_format.equals("sam") || config.sequence_format.equals("cram")) {
return new BAMFile(file,false);
}
else if (config.sequence_format.equals("bam_mapped") || config.sequence_format.equals("sam_mapped")) {
else if (config.sequence_format.equals("bam_mapped") || config.sequence_format.equals("sam_mapped") || config.sequence_format.equals("cram_mapped")) {
return new BAMFile(file,true);
}
else if (config.sequence_format.equals("fastq")) {
Expand All @@ -95,7 +95,7 @@ else if (config.sequence_format.equals("fastq")) {

// Otherwise we just use the extension on the end of the file name to try to determine
// the type
if (file.getName().toLowerCase().endsWith(".bam") || file.getName().toLowerCase().endsWith(".sam")) {
if (file.getName().toLowerCase().endsWith(".bam") || file.getName().toLowerCase().endsWith(".sam") || file.getName().toLowerCase().endsWith(".cram")) {
// We default to using all reads
return new BAMFile(file,false);
}
Expand Down

0 comments on commit 36d48a4

Please sign in to comment.