File: SequenceFactory.java

package info (click to toggle)
fastqc 0.11.5%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,328 kB
  • ctags: 1,052
  • sloc: java: 6,765; perl: 255; xml: 56; sh: 21; makefile: 7
file content (110 lines) | stat: -rw-r--r-- 3,682 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
 * Copyright Copyright 2010-15 Simon Andrews
 *
 *    This file is part of FastQC.
 *
 *    FastQC is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    FastQC is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with FastQC; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
package uk.ac.babraham.FastQC.Sequence;

import java.io.File;
import java.io.IOException;

import uk.ac.babraham.FastQC.FastQCConfig;
import uk.ac.babraham.FastQC.Utilities.CasavaBasename;
import uk.ac.babraham.FastQC.Utilities.NameFormatException;

public class SequenceFactory {
	/**
	 * 
	 * This option is used when multiple files are to be treated as a group to produce
	 * a single output.  This is currently used for groups of files generated by casava
	 * 
	 * @param files
	 * @return
	 * @throws SequenceFormatException
	 * @throws IOException
	 */
	public static SequenceFile getSequenceFile (File [] files) throws SequenceFormatException, IOException {
		
		/*
		 * We used to build a set of SequenceFile objects to make a sequence group, but we found that
		 * doing this caused too many files to be open simultaneously and caused crashes on large
		 * runs.  We now just pass the files to the group and let it open them as and when they're needed.
		 */
		
		if (files.length == 1) {
			
			if (FastQCConfig.getInstance().casava) {
				try {
					// We do this simply to find out if the casava basename is valid.  If it is then the 
					// Sequencefilegroup is created at the end of this sub.  If it's not then we do a 
					// simple creation without modifying the file name.
					CasavaBasename.getCasavaBasename(files[0].getName());
				}
				catch (NameFormatException nfe) {
					return getSequenceFile(files[0]);
				}
			}
			else {
				return getSequenceFile(files[0]);	
			}
		}
		
		
		return new SequenceFileGroup(files);
		
	}
	
	public static SequenceFile getSequenceFile(File file) throws SequenceFormatException, IOException {
		
		FastQCConfig config = FastQCConfig.getInstance();

//		System.err.println("Format is "+config.sequence_format);
		
		if (config.sequence_format != null) {
			// We're not autodetecting the format, but taking whatever they said
			
			if (config.sequence_format.equals("bam") || config.sequence_format.equals("sam")) {
				return new BAMFile(file,false);				
			}
			else if (config.sequence_format.equals("bam_mapped") || config.sequence_format.equals("sam_mapped")) {
				return new BAMFile(file,true);				
			}
			else if (config.sequence_format.equals("fastq")) {
				return new FastQFile(config,file);
			}
			else {
				throw new SequenceFormatException("Didn't understand format name '"+config.sequence_format+"'");
			}
			
		}
		
		
		// Otherwise we just use the extension on the end of the file name to try to determine
		// the type
		if (file.getName().toLowerCase().endsWith(".bam") || file.getName().toLowerCase().endsWith(".sam")) {
			// We default to using all reads
			return new BAMFile(file,false);
		}
		else {
			return new FastQFile(config,file);
		}

		
	}
	
	
}