Debian Codegraph @

uk/ac/babraham/FastQC/Analysis/AnalysisRunner.java

raw symbols SCIP
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.Analysis;
21
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import uk.ac.babraham.FastQC.Modules.BasicStats;
27 import uk.ac.babraham.FastQC.Modules.QCModule;
28 import uk.ac.babraham.FastQC.Sequence.Sequence;
29 import uk.ac.babraham.FastQC.Sequence.SequenceFile;
30 import uk.ac.babraham.FastQC.Sequence.SequenceFormatException;
31
32 public class AnalysisRunner implements Runnable {
33
34 private SequenceFile file;
35 private QCModule [] modules;
36 private List<AnalysisListener> listeners = new ArrayList<AnalysisListener>();
37 private int percentComplete = 0;
38
39 public AnalysisRunner (SequenceFile file) {
40 this.file = file;
41 }
42
43 public void addAnalysisListener (AnalysisListener l) {
44 if (l != null && !listeners.contains(l)) {
45 listeners.add(l);
46 }
47 }
48
49 public void removeAnalysisListener (AnalysisListener l) {
50 if (l != null && listeners.contains(l)) {
51 listeners.remove(l);
52 }
53 }
54
55
56 public void startAnalysis (QCModule [] modules) {
57 this.modules = modules;
58 for (int i=0;i<modules.length;i++) {
59 modules[i].reset();
60 }
61 AnalysisQueue.getInstance().addToQueue(this);
62 }
63
64 public void run() {
65
66 Iterator<AnalysisListener> i = listeners.iterator();
67 while (i.hasNext()) {
68 i.next().analysisStarted(file);
69 }
70
71
72 int seqCount = 0;
73 while (file.hasNext()) {
74 ++seqCount;
75 Sequence seq;
76 try {
77 seq = file.next();
78 }
79 catch (SequenceFormatException e) {
80 i = listeners.iterator();
81 while (i.hasNext()) {
82 i.next().analysisExceptionReceived(file,e);
83 }
84 return;
85 }
86
87 for (int m=0;m<modules.length;m++) {
88 if (seq.isFiltered() && modules[m].ignoreFilteredSequences()) continue;
89 modules[m].processSequence(seq);
90 }
91
92 if (seqCount % 1000 == 0) {
93 if (file.getPercentComplete() >= percentComplete+5) {
94
95 percentComplete = (((int)file.getPercentComplete())/5)*5;
96
97 i = listeners.iterator();
98 while (i.hasNext()) {
99 i.next().analysisUpdated(file,seqCount,percentComplete);
100 }
101 try {
102 Thread.sleep(10);
103 }
104 catch (InterruptedException e) {}
105 }
106 }
107 }
108
109 // We need to account for their potentially being no sequences
110 // in the file. In this case the BasicStats module never gets
111 // the file name so we need to explicitly pass it.
112
113 if (seqCount == 0) {
114 for (int m=0; m<modules.length; m++) {
115 if (modules[m] instanceof BasicStats) {
116 ((BasicStats)modules[m]).setFileName(file.name());
117 }
118 }
119 }
120
121 i = listeners.iterator();
122 while (i.hasNext()) {
123 i.next().analysisComplete(file,modules);
124 }
125
126 }
127
128 }