Debian Codegraph @

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

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