Debian Codegraph @

uk/ac/babraham/FastQC/Sequence/SequenceFileGroup.java

raw symbols SCIP
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.Sequence;
21
22 import java.io.File;
23 import java.io.IOException;
24
25 import uk.ac.babraham.FastQC.Utilities.CasavaBasename;
26 import uk.ac.babraham.FastQC.Utilities.NameFormatException;
27
28 public class SequenceFileGroup implements SequenceFile {
29
30 private File [] files;
31 private SequenceFile sequenceFile;
32 private File groupFile;
33 private int currentIndex = 0;
34
35 public SequenceFileGroup( File [] files) throws IOException, SequenceFormatException {
36 this.files = files;
37 sequenceFile = SequenceFactory.getSequenceFile(files[0]);
38
39 try {
40 String baseName = CasavaBasename.getCasavaBasename(sequenceFile.name());
41 if (sequenceFile.getFile().getParent() == null) {
42 groupFile = new File(baseName);
43 } else {
44 groupFile = new File(sequenceFile.getFile().getParent() + "/"
45 + baseName);
46 }
47 } catch (NameFormatException nfe) {
48 groupFile = sequenceFile.getFile();
49 }
50 }
51
52 public File getFile() {
53 return groupFile;
54 }
55
56 public int getPercentComplete() {
57 return ((100 * currentIndex) / files.length)
58 + (sequenceFile.getPercentComplete() / files.length);
59 }
60
61 public boolean hasNext() {
62 if (sequenceFile.hasNext()) {
63 return true;
64 }
65 else {
66 while (currentIndex < files.length - 1) {
67 ++currentIndex;
68 try {
69 sequenceFile = SequenceFactory.getSequenceFile(files[currentIndex]);
70 }
71 catch (Exception e) {
72 e.printStackTrace();
73 return false;
74 }
75 if (sequenceFile.hasNext()) break;
76 }
77 return sequenceFile.hasNext();
78 }
79 }
80
81 public boolean isColorspace() {
82 return sequenceFile.isColorspace();
83 }
84
85 public String name() {
86 return groupFile.getName();
87 }
88
89 public Sequence next() throws SequenceFormatException {
90 return sequenceFile.next();
91 }
92
93 }