1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.utgenome.format.fasta;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.util.HashMap;
28 import java.util.Map;
29
30 import org.utgenome.UTGBException;
31
32 public class FASTA {
33
34 Map<String, RawStringWrapper> chrToSequence = new HashMap<String, RawStringWrapper>();
35
36 public FASTA(File fastaFile) throws IOException, UTGBException {
37 loadFASTA(fastaFile);
38 }
39
40 public static class RawStringWrapper implements GenomeSequence {
41
42 public final String seq;
43
44 public RawStringWrapper(String seq) {
45 this.seq = seq;
46 }
47
48 public int length() {
49 return seq.length();
50 }
51
52 public char charAt(int index) {
53 return seq.charAt(index);
54 }
55
56 }
57
58 public String getRawSequence(String chr) {
59 return getSequence(chr).seq;
60 }
61
62 public RawStringWrapper getSequence(String chr) {
63 return chrToSequence.get(chr);
64 }
65
66 void loadFASTA(File fastaFile) throws IOException, UTGBException {
67 FASTAPullParser fastaPullParser = new FASTAPullParser(fastaFile);
68 for (FASTASequence seq; (seq = fastaPullParser.nextSequence()) != null;) {
69 chrToSequence.put(seq.getSequenceName(), new RawStringWrapper(seq.getSequence()));
70 }
71 fastaPullParser.close();
72 }
73
74 }