Debian Codegraph @

uk/ac/babraham/FastQC/Sequence/Contaminant/ContaminentFinder.java

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