Newer
Older
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
/* StreamSequenceFactory.java
*
* created: Mon Jun 14 1999
*
* This file is part of Artemis
*
* Copyright (C) 1999 Genome Research Limited
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/StreamSequenceFactory.java,v 1.1 2004-06-09 09:50:38 tjc Exp $
*/
package uk.ac.sanger.artemis.io;
import uk.ac.sanger.artemis.util.LinePushBackReader;
import java.io.IOException;
/**
* This class contains the method makeStreamSequence (), which reads a
* StreamSequence object from a LinePushBackReader object.
*
* @author Kim Rutherford
* @version $Id: StreamSequenceFactory.java,v 1.1 2004-06-09 09:50:38 tjc Exp $
**/
abstract public class StreamSequenceFactory
{
/** The tag used for sequence that is in EMBL format. */
final public static int EMBL_FORMAT = 1;
/** The tag used for sequence that is in GENBANK format. */
final public static int GENBANK_FORMAT = 2;
/** The tag use for sequence that is in raw format. */
final public static int RAW_FORMAT = 3;
/** The tag use for sequence that is in FASTA or similar format. */
final public static int FASTA_FORMAT = 4;
/**
* Read a StreamSequence object from a LinePushBackReader object.
**/
public static StreamSequence makeStreamSequence(final LinePushBackReader
throws IOException
{
final int sequence_type = getSequenceType(in_stream);
switch (sequence_type)
{
case EMBL_FORMAT:
return new EmblStreamSequence(in_stream);
case FASTA_FORMAT:
{
IndexFastaStream ifs = new IndexFastaStream(entry);
if(ifs.useIndex())
return ifs;
}
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
111
112
113
114
115
116
117
case GENBANK_FORMAT:
return new GenbankStreamSequence(in_stream);
case RAW_FORMAT:
default:
return new RawStreamSequence(in_stream);
}
}
/**
* Return the sequence type that can be read from the given
* LinePushBackReader. ie EMBL_FORMAT, FASTA_FORMAT, etc.
**/
public static int getSequenceType(LinePushBackReader in_stream)
throws IOException
{
final String seq_header_line = in_stream.readLine ();
in_stream.pushBack (seq_header_line);
if(seq_header_line.startsWith ("SQ "))
return EMBL_FORMAT;
else
{
if(seq_header_line.startsWith (">"))
return FASTA_FORMAT;
else
{
if (seq_header_line.startsWith ("BASE COUNT") ||
seq_header_line.startsWith ("ORIGIN"))
return GENBANK_FORMAT;
else
return RAW_FORMAT;
}
}
}
}