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