Debian Codegraph @

uk/ac/babraham/FastQC/Modules/ModuleConfig.java

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /**
2 * Copyright Copyright 2013-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.Modules;
21
22 import java.io.BufferedReader;
23 import java.io.FileNotFoundException;
24 import java.io.FileReader;
25 import java.io.InputStream;
•26 import java.io.FileInputStream;
27 import java.io.InputStreamReader;
28 import java.util.HashMap;
29
30 import uk.ac.babraham.FastQC.FastQCConfig;
31 import uk.ac.babraham.FastQC.Sequence.Contaminant.ContaminentFinder;
32
33 public class ModuleConfig {
34
35 private static HashMap<String, Double>parameters = readParams();
36
37
38 private static HashMap<String, Double> readParams () {
39
40 HashMap<String, Double>params = new HashMap<String, Double>();
41
42 // Set the defaults to use if we don't have any overrides
43 params.put("duplication:warn",70d);
44 params.put("duplication:error", 50d);
45 params.put("kmer:warn", 2d);
46 params.put("kmer:error",5d);
47 params.put("n_content:warn",5d);
48 params.put("n_content:error",20d);
49 params.put("overrepresented:warn", 0.1);
50 params.put("overrepresented:error",1d);
51 params.put("quality_base_lower:warn",10d);
52 params.put("quality_base_lower:error", 5d);
53 params.put("quality_base_median:warn", 25d);
54 params.put("quality_base_median:error", 20d);
55 params.put("sequence:warn", 10d);
56 params.put("sequence:error",20d);
57 params.put("gc_sequence:warn",15d);
58 params.put("gc_sequence:error",30d);
59 params.put("quality_sequence:warn", 20d);
60 params.put("quality_sequence:error",27d);
61 params.put("tile:warn", 5d);
62 params.put("tile:error",10d);
63 params.put("sequence_length:warn",1d);
64 params.put("sequence_length:error", 1d);
65 params.put("adapter:warn", 5d);
66 params.put("adapter:error", 10d);
67
68 params.put("duplication:ignore",0d);
69 params.put("kmer:ignore",0d);
70 params.put("n_content:ignore",0d);
71 params.put("overrepresented:ignore",0d);
72 params.put("quality_base:ignore",0d);
73 params.put("sequence:ignore",0d);
74 params.put("gc_quality:ignore",0d);
75 params.put("quality_sequence:ignore",0d);
76 params.put("tile:ignore",0d);
77 params.put("sequence_length:ignore",0d);
78 params.put("adapter:ignore",0d);
79
80 // Now read the config file to see if there are updated values for any of these.
81
82 BufferedReader br;
83
84 try {
85 if (FastQCConfig.getInstance().limits_file == null) {
•86 InputStream rsrc = new FileInputStream("/etc/fastqc/Configuration/limits.txt");
87 if (rsrc==null) throw new FileNotFoundException("cannot find Configuration/limits.txt");
88 br =new BufferedReader(new InputStreamReader(rsrc));
89 }
90 else {
91 br=new BufferedReader(new FileReader(FastQCConfig.getInstance().limits_file));
92 }
93
94 String line;
95 while ((line = br.readLine()) != null) {
96
97 if (line.startsWith("#")) continue;
98
99 if (line.trim().length() == 0) continue;
100
101 String [] sections = line.split("\\s+");
102 if (sections.length != 3) {
103 System.err.println("Config line '"+line+"' didn't contain the 3 required sections");
104 }
105
106 if (!(sections[1].equals("warn") || sections[1].equals("error") || sections[1].equals("ignore"))) {
107 System.err.println("Second config field must be error, warn or ignore, not '"+sections[1]+"'");
108 continue;
109 }
110
111 double value;
112 try {
113 value = Double.parseDouble(sections[2]);
114 }
115 catch (NumberFormatException nfe) {
116 System.err.println("Value "+sections[2]+" didn't look like a number");
117 continue;
118 }
119
120 String key = sections[0]+":"+sections[1];
121 params.put(key, value);
122
123
124 }
125
126 }
127 catch (Exception e) {
128 e.printStackTrace();
129 }
130
131
132
133
134 return params;
135
136 }
137
138 public static Double getParam(String module, String level) {
139
140 if (!(level.equals("warn") || level.equals("error") || level.equals("ignore"))) {
141 throw new IllegalArgumentException("Level must be warn, error or ignore");
142 }
143
144 String key = module+":"+level;
145
146 if (! parameters.containsKey(key)) {
147 throw new IllegalArgumentException("No key called "+key+" in the config data");
148 }
149
150 return parameters.get(key);
151
152 }
153
154
155 }