1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
/**
* Copyright Copyright 2010-15 Simon Andrews
*
* This file is part of FastQC.
*
* FastQC is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* FastQC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FastQC; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package uk.ac.babraham.FastQC.Sequence.Contaminant;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Vector;
import uk.ac.babraham.FastQC.FastQCConfig;
public class ContaminentFinder {
private static Contaminant [] contaminants;
public static ContaminantHit findContaminantHit (String sequence) {
if (contaminants == null) {
contaminants = makeContaminantList();
}
ContaminantHit bestHit = null;
for (int c=0;c<contaminants.length;c++) {
ContaminantHit thisHit = contaminants[c].findMatch(sequence);
// System.out.println("Best hit from "+c+" is "+thisHit);
if (thisHit == null) continue; // No hit
if (bestHit == null || thisHit.length() > bestHit.length()) {
bestHit = thisHit;
}
}
return bestHit;
}
private static Contaminant [] makeContaminantList () {
Vector<Contaminant>c = new Vector<Contaminant>();
try {
BufferedReader br = null;
if (FastQCConfig.getInstance().contaminant_file == null) {
//InputStream rsrc=ContaminentFinder.class.getResourceAsStream("/Configuration/contaminant_list.txt");
//if (rsrc==null) throw new FileNotFoundException("cannot find Confituration/contaminant_list.txt");
InputStream rsrc = new FileInputStream("/etc/fastqc/Configuration/contaminant_list.txt");
if (rsrc==null) throw new FileNotFoundException("cannot find Configuration/contaminant_list.txt");
br =new BufferedReader(new InputStreamReader(rsrc));
}
else {
br=new BufferedReader(new FileReader(FastQCConfig.getInstance().contaminant_file));
}
String line;
while ((line = br.readLine())!= null){
if (line.startsWith("#")) continue; // Skip comments
if (line.trim().length() == 0) continue; // Skip blank lines
String [] sections = line.split("\\t+");
if (sections.length != 2) {
System.err.println("Expected 2 sections for contaminant line but got "+sections.length+" from "+line);
continue;
}
Contaminant con = new Contaminant(sections[0], sections[1]);
c.add(con);
}
br.close();
}
catch (IOException e) {
e.printStackTrace();
}
return c.toArray(new Contaminant[0]);
}
/*
public static void main (String [] args) {
Config cfg=new Config();
String query = "agagtgtagatctccgtggtcgccgtatca";
ContaminantHit c = findContaminantHit(cfg,query);
System.out.println("Query was "+query.length()+"bp Found hit "+c);
}*/
}
|