| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
package uk.ac.babraham.FastQC.Utilities; |
| 22 |
|
| 23 |
import java.io.File; |
| 24 |
import java.util.Hashtable; |
| 25 |
import java.util.Vector; |
| 26 |
|
| 27 |
public class NanoporeBasename { |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public static String getNanoporeBasename (String originalName) throws NameFormatException { |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
String [] subNames = originalName.replaceAll(".fast5$", "").split("_"); |
| 51 |
|
| 52 |
if (subNames.length < 3) { |
| 53 |
throw new NameFormatException(); |
| 54 |
} |
| 55 |
|
| 56 |
String basename = subNames[0]+"_"+subNames[1]+"_"+subNames[2]; |
| 57 |
|
| 58 |
System.err.println("Basename is "+basename); |
| 59 |
|
| 60 |
return basename; |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
public static File [][] getNanoporeGroups (File [] files) { |
| 65 |
Hashtable<String, Vector<File>> fileBases = new Hashtable<String, Vector<File>>(); |
| 66 |
|
| 67 |
for (int f=0;f<files.length;f++) { |
| 68 |
|
| 69 |
|
| 70 |
if (files[f].getName().contains("muxscan")) continue; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
try { |
| 75 |
String baseName = NanoporeBasename.getNanoporeBasename(files[f].getName()); |
| 76 |
if (! fileBases.containsKey(baseName)) { |
| 77 |
fileBases.put(baseName,new Vector<File>()); |
| 78 |
} |
| 79 |
fileBases.get(baseName).add(files[f]); |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
catch (NameFormatException nfe) { |
| 86 |
|
| 87 |
System.err.println("File '"+files[f].getName()+"' didn't look like part of a CASAVA group"); |
| 88 |
Vector<File> newVector = new Vector<File>(); |
| 89 |
newVector.add(files[f]); |
| 90 |
fileBases.put(files[f].getName(), newVector); |
| 91 |
} |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
String [] baseNames = fileBases.keySet().toArray(new String [0]); |
| 96 |
|
| 97 |
File [][] fileGroups = new File[baseNames.length][]; |
| 98 |
|
| 99 |
for (int i=0;i<baseNames.length;i++) { |
| 100 |
fileGroups[i] = fileBases.get(baseNames[i]).toArray(new File[0]); |
| 101 |
} |
| 102 |
|
| 103 |
return fileGroups; |
| 104 |
} |
| 105 |
|
| 106 |
} |