Debian Codegraph @

uk/ac/babraham/FastQC/Sequence/SequenceFactory.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;
21
22 import java.io.File;
23 import java.io.IOException;
24
25 import uk.ac.babraham.FastQC.FastQCConfig;
26 import uk.ac.babraham.FastQC.Utilities.CasavaBasename;
27 import uk.ac.babraham.FastQC.Utilities.NameFormatException;
28
29 public class SequenceFactory {
30 /**
31 *
32 * This option is used when multiple files are to be treated as a group to produce
33 * a single output. This is currently used for groups of files generated by casava
34 *
35 * @param files
36 * @return
37 * @throws SequenceFormatException
38 * @throws IOException
39 */
40 public static SequenceFile getSequenceFile (File [] files) throws SequenceFormatException, IOException {
41
42 /*
43 * We used to build a set of SequenceFile objects to make a sequence group, but we found that
44 * doing this caused too many files to be open simultaneously and caused crashes on large
45 * runs. We now just pass the files to the group and let it open them as and when they're needed.
46 */
47
48 if (files.length == 1) {
49
50 if (FastQCConfig.getInstance().casava) {
51 try {
52 // We do this simply to find out if the casava basename is valid. If it is then the
53 // Sequencefilegroup is created at the end of this sub. If it's not then we do a
54 // simple creation without modifying the file name.
55 CasavaBasename.getCasavaBasename(files[0].getName());
56 }
57 catch (NameFormatException nfe) {
58 return getSequenceFile(files[0]);
59 }
60 }
61 else {
62 return getSequenceFile(files[0]);
63 }
64 }
65
66
67 return new SequenceFileGroup(files);
68
69 }
70
71 public static SequenceFile getSequenceFile(File file) throws SequenceFormatException, IOException {
72
73 FastQCConfig config = FastQCConfig.getInstance();
74
75 // System.err.println("Format is "+config.sequence_format);
76
77 if (config.sequence_format != null) {
78 // We're not autodetecting the format, but taking whatever they said
79
80 if (config.sequence_format.equals("bam") || config.sequence_format.equals("sam")) {
81 return new BAMFile(file,false);
82 }
83 else if (config.sequence_format.equals("bam_mapped") || config.sequence_format.equals("sam_mapped")) {
84 return new BAMFile(file,true);
85 }
86 else if (config.sequence_format.equals("fastq")) {
87 return new FastQFile(config,file);
88 }
89 else {
90 throw new SequenceFormatException("Didn't understand format name '"+config.sequence_format+"'");
91 }
92
93 }
94
95
96 // Otherwise we just use the extension on the end of the file name to try to determine
97 // the type
98 if (file.getName().toLowerCase().endsWith(".bam") || file.getName().toLowerCase().endsWith(".sam") || file.getName().toLowerCase().endsWith(".ubam")) {
99 // We default to using all reads
100 return new BAMFile(file,false);
101 }
•102 /*else if (file.getName().toLowerCase().endsWith(".fast5")) {
103 return new Fast5File(file);
•104 }*/
105 else {
106 return new FastQFile(config,file);
107 }
108
109
110 }
111
112
113 }