1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import jalview.datamodel.Sequence; |
24 |
|
import jalview.datamodel.SequenceI; |
25 |
|
import jalview.util.Format; |
26 |
|
import jalview.util.MessageManager; |
27 |
|
|
28 |
|
import java.io.IOException; |
29 |
|
import java.util.ArrayList; |
30 |
|
import java.util.HashMap; |
31 |
|
|
|
|
| 82.8% |
Uncovered Elements: 17 (99) |
Complexity: 25 |
Complexity Density: 0.41 |
|
32 |
|
public class PfamFile extends AlignFile |
33 |
|
{ |
34 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
35 |
1 |
public PfamFile()... |
36 |
|
{ |
37 |
|
} |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
39 |
0 |
public PfamFile(String inFile, DataSourceType sourceType)... |
40 |
|
throws IOException |
41 |
|
{ |
42 |
0 |
super(inFile, sourceType); |
43 |
|
} |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
9 |
public PfamFile(FileParse source) throws IOException... |
46 |
|
{ |
47 |
9 |
super(source); |
48 |
|
} |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
10 |
@Override... |
51 |
|
public void initData() |
52 |
|
{ |
53 |
10 |
super.initData(); |
54 |
|
} |
55 |
|
|
|
|
| 77.4% |
Uncovered Elements: 14 (62) |
Complexity: 14 |
Complexity Density: 0.37 |
|
56 |
9 |
@Override... |
57 |
|
public void parse() throws IOException |
58 |
|
{ |
59 |
9 |
int i = 0; |
60 |
9 |
String line; |
61 |
|
|
62 |
9 |
HashMap<String, StringBuffer> seqhash = new HashMap<String, StringBuffer>(); |
63 |
9 |
ArrayList<String> headers = new ArrayList<String>(); |
64 |
9 |
boolean useTabs = false; |
65 |
9 |
int spces; |
66 |
? |
while ((line = nextLine()) != null) |
67 |
|
{ |
68 |
41 |
if (line.indexOf("#") == 0) |
69 |
|
{ |
70 |
|
|
71 |
0 |
continue; |
72 |
|
} |
73 |
|
|
74 |
41 |
if (useTabs) |
75 |
|
{ |
76 |
0 |
spces = line.indexOf("\t"); |
77 |
|
} |
78 |
|
else |
79 |
|
{ |
80 |
41 |
spces = line.indexOf(" "); |
81 |
|
|
82 |
41 |
if (!useTabs && spces == -1) |
83 |
|
{ |
84 |
3 |
useTabs = true; |
85 |
3 |
spces = line.indexOf("\t"); |
86 |
|
} |
87 |
|
} |
88 |
41 |
if (spces <= 0) |
89 |
|
{ |
90 |
|
|
91 |
1 |
continue; |
92 |
|
} |
93 |
40 |
String id = line.substring(0, spces); |
94 |
40 |
StringBuffer tempseq; |
95 |
|
|
96 |
40 |
if (seqhash.containsKey(id)) |
97 |
|
{ |
98 |
0 |
tempseq = seqhash.get(id); |
99 |
|
} |
100 |
|
else |
101 |
|
{ |
102 |
40 |
tempseq = new StringBuffer(); |
103 |
40 |
seqhash.put(id, tempseq); |
104 |
|
} |
105 |
|
|
106 |
40 |
if (!(headers.contains(id))) |
107 |
|
{ |
108 |
40 |
headers.add(id); |
109 |
|
} |
110 |
40 |
if (spces + 1 < line.length()) |
111 |
|
{ |
112 |
40 |
tempseq.append(line.substring(spces + 1).trim()); |
113 |
|
} |
114 |
|
} |
115 |
|
|
116 |
9 |
this.noSeqs = headers.size(); |
117 |
|
|
118 |
9 |
if (noSeqs < 1) |
119 |
|
{ |
120 |
0 |
throw new IOException(MessageManager |
121 |
|
.getString("exception.pfam_no_sequences_found")); |
122 |
|
} |
123 |
|
|
124 |
49 |
for (i = 0; i < headers.size(); i++) |
125 |
|
{ |
126 |
40 |
if (seqhash.get(headers.get(i)) != null) |
127 |
|
{ |
128 |
40 |
if (maxLength < seqhash.get(headers.get(i)).toString().length()) |
129 |
|
{ |
130 |
10 |
maxLength = seqhash.get(headers.get(i)).toString().length(); |
131 |
|
} |
132 |
|
|
133 |
40 |
Sequence newSeq = parseId(headers.get(i).toString()); |
134 |
40 |
newSeq.setSequence( |
135 |
|
seqhash.get(headers.get(i).toString()).toString()); |
136 |
40 |
seqs.addElement(newSeq); |
137 |
|
} |
138 |
|
else |
139 |
|
{ |
140 |
0 |
System.err.println("PFAM File reader: Can't find sequence for " |
141 |
|
+ headers.get(i)); |
142 |
|
} |
143 |
|
} |
144 |
|
} |
145 |
|
|
|
|
| 96.4% |
Uncovered Elements: 1 (28) |
Complexity: 7 |
Complexity Density: 0.35 |
|
146 |
1 |
@Override... |
147 |
|
public String print(SequenceI[] s, boolean jvsuffix) |
148 |
|
{ |
149 |
1 |
StringBuffer out = new StringBuffer(""); |
150 |
|
|
151 |
1 |
int max = 0; |
152 |
1 |
int maxid = 0; |
153 |
|
|
154 |
1 |
int i = 0; |
155 |
|
|
156 |
16 |
while ((i < s.length) && (s[i] != null)) |
157 |
|
{ |
158 |
15 |
String tmp = printId(s[i], jvsuffix); |
159 |
|
|
160 |
15 |
max = Math.max(max, s[i].getLength()); |
161 |
|
|
162 |
15 |
if (tmp.length() > maxid) |
163 |
|
{ |
164 |
3 |
maxid = tmp.length(); |
165 |
|
} |
166 |
|
|
167 |
15 |
i++; |
168 |
|
} |
169 |
|
|
170 |
1 |
if (maxid < 15) |
171 |
|
{ |
172 |
1 |
maxid = 15; |
173 |
|
} |
174 |
|
|
175 |
1 |
int j = 0; |
176 |
|
|
177 |
16 |
while ((j < s.length) && (s[j] != null)) |
178 |
|
{ |
179 |
15 |
out.append(new Format("%-" + maxid + "s") |
180 |
|
.form(printId(s[j], jvsuffix) + " ")); |
181 |
|
|
182 |
15 |
out.append(s[j].getSequenceAsString()); |
183 |
15 |
out.append(newline); |
184 |
15 |
j++; |
185 |
|
} |
186 |
|
|
187 |
1 |
out.append(newline); |
188 |
|
|
189 |
1 |
return out.toString(); |
190 |
|
} |
191 |
|
} |