| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
package uk.ac.babraham.FastQC.Sequence; |
| 21 |
|
| 22 |
import java.io.File; |
| 23 |
import java.io.IOException; |
| 24 |
import java.util.ArrayList; |
| 25 |
import java.util.List; |
| 26 |
|
| 27 |
import ch.systemsx.cisd.hdf5.HDF5Factory; |
| 28 |
import ch.systemsx.cisd.hdf5.IHDF5SimpleReader; |
| 29 |
|
| 30 |
public class Fast5File implements SequenceFile { |
| 31 |
|
| 32 |
private Sequence nextSequence = null; |
| 33 |
private File file; |
| 34 |
private String name; |
| 35 |
private IHDF5SimpleReader reader; |
| 36 |
private String [] readPaths = new String[] {""}; |
| 37 |
|
| 38 |
private int readPathsIndexPosition = 0; |
| 39 |
|
| 40 |
private String [] rdfPaths = new String [] { |
| 41 |
"Analyses/Basecall_2D_000/BaseCalled_template/Fastq", |
| 42 |
"Analyses/Basecall_2D_000/BaseCalled_2D/Fastq", |
| 43 |
"Analyses/Basecall_1D_000/BaseCalled_template/Fastq", |
| 44 |
"Analyses/Basecall_1D_000/BaseCalled_1D/Fastq" |
| 45 |
}; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
protected Fast5File(File file) throws SequenceFormatException, IOException { |
| 50 |
this.file = file; |
| 51 |
name = file.getName(); |
| 52 |
|
| 53 |
reader = HDF5Factory.openForReading(file); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
List<String> topLevelFolders = reader.getGroupMembers("/"); |
| 70 |
|
| 71 |
List<String> readFolders = new ArrayList<String>(); |
| 72 |
|
| 73 |
for (String folder : topLevelFolders) { |
| 74 |
System.err.println("Looking at "+folder); |
| 75 |
|
| 76 |
if (folder.startsWith("read_")) { |
| 77 |
readFolders.add(folder+"/"); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
if (readFolders.size() > 0) { |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
readPaths = readFolders.toArray(new String[0]); |
| 86 |
} |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
public String name() { |
| 91 |
return name; |
| 92 |
} |
| 93 |
|
| 94 |
public int getPercentComplete() { |
| 95 |
return (readPathsIndexPosition*100) / readPaths.length; |
| 96 |
} |
| 97 |
|
| 98 |
public boolean isColorspace() { |
| 99 |
return false; |
| 100 |
} |
| 101 |
|
| 102 |
public boolean hasNext() { |
| 103 |
return readPathsIndexPosition < readPaths.length; |
| 104 |
} |
| 105 |
|
| 106 |
public Sequence next() throws SequenceFormatException { |
| 107 |
|
| 108 |
for (int r=0;r<rdfPaths.length;r++) { |
| 109 |
|
| 110 |
if (reader.exists(readPaths[readPathsIndexPosition]+rdfPaths[r])) { |
| 111 |
|
| 112 |
String fastq = reader.readString(readPaths[readPathsIndexPosition]+rdfPaths[r]); |
| 113 |
|
| 114 |
String [] sections = fastq.split("\\n"); |
| 115 |
|
| 116 |
if (sections.length != 4) { |
| 117 |
throw new SequenceFormatException("Didn't get 4 sections from "+fastq); |
| 118 |
} |
| 119 |
|
| 120 |
Sequence seq = new Sequence(this, sections[1].toUpperCase(),sections[3], sections[0]); |
| 121 |
++readPathsIndexPosition; |
| 122 |
|
| 123 |
if(readPathsIndexPosition >= readPaths.length) { |
| 124 |
reader.close(); |
| 125 |
} |
| 126 |
|
| 127 |
return(seq); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
throw new SequenceFormatException("No valid fastq paths found in "+file); |
| 132 |
} |
| 133 |
|
| 134 |
public void remove() { |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
public File getFile() { |
| 139 |
return file; |
| 140 |
} |
| 141 |
|
| 142 |
} |