| 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 java.io.IOException; |
| 24 |
|
|
| 25 |
|
import jalview.datamodel.Alignment; |
| 26 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 27 |
|
import jalview.datamodel.Annotation; |
| 28 |
|
import jalview.datamodel.Sequence; |
| 29 |
|
import jalview.datamodel.SequenceI; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@author |
| 35 |
|
@version |
| 36 |
|
|
| |
|
| 0% |
Uncovered Elements: 111 (111) |
Complexity: 30 |
Complexity Density: 0.48 |
|
| 37 |
|
public class FastaFile extends AlignFile |
| 38 |
|
{ |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
int len = 72; |
| 43 |
|
|
| 44 |
|
StringBuffer out; |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 49 |
0 |
public FastaFile()... |
| 50 |
|
{ |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
@param |
| 57 |
|
|
| 58 |
|
@param |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
@throws |
| 62 |
|
|
| 63 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 64 |
0 |
public FastaFile(String inFile, DataSourceType sourceType)... |
| 65 |
|
throws IOException |
| 66 |
|
{ |
| 67 |
0 |
super(inFile, sourceType); |
| 68 |
|
} |
| 69 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 70 |
0 |
public FastaFile(FileParse source) throws IOException... |
| 71 |
|
{ |
| 72 |
0 |
this(source, true); |
| 73 |
|
} |
| 74 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 75 |
0 |
public FastaFile(FileParse source, boolean closeData) throws IOException... |
| 76 |
|
{ |
| 77 |
0 |
super(true, source, closeData); |
| 78 |
|
} |
| 79 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 80 |
0 |
public FastaFile(SequenceI[] seqs)... |
| 81 |
|
{ |
| 82 |
0 |
super(seqs); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
@throws |
| 89 |
|
|
| 90 |
|
|
| |
|
| 0% |
Uncovered Elements: 50 (50) |
Complexity: 12 |
Complexity Density: 0.43 |
|
| 91 |
0 |
@Override... |
| 92 |
|
public void parse() throws IOException |
| 93 |
|
{ |
| 94 |
0 |
StringBuffer sb = new StringBuffer(); |
| 95 |
0 |
boolean firstLine = true; |
| 96 |
|
|
| 97 |
0 |
String line, uline; |
| 98 |
0 |
Sequence seq = null; |
| 99 |
|
|
| 100 |
0 |
boolean annotation = false; |
| 101 |
|
|
| 102 |
0 |
while ((uline = nextLine()) != null) |
| 103 |
|
{ |
| 104 |
0 |
line = uline.trim(); |
| 105 |
0 |
if (line.length() > 0) |
| 106 |
|
{ |
| 107 |
0 |
if (line.charAt(0) == '>') |
| 108 |
|
{ |
| 109 |
0 |
if (line.startsWith(">#_")) |
| 110 |
|
{ |
| 111 |
0 |
if (annotation) |
| 112 |
|
{ |
| 113 |
0 |
annotations.addElement(makeAnnotation(seq, sb)); |
| 114 |
|
} |
| 115 |
|
} |
| 116 |
|
else |
| 117 |
|
{ |
| 118 |
0 |
annotation = false; |
| 119 |
|
} |
| 120 |
|
|
| 121 |
0 |
if (!firstLine) |
| 122 |
|
{ |
| 123 |
0 |
seq.setSequence(sb.toString()); |
| 124 |
|
|
| 125 |
0 |
if (!annotation) |
| 126 |
|
{ |
| 127 |
0 |
seqs.addElement(seq); |
| 128 |
|
} |
| 129 |
|
} |
| 130 |
|
|
| 131 |
0 |
seq = parseId(line.substring(1)); |
| 132 |
0 |
firstLine = false; |
| 133 |
|
|
| 134 |
0 |
sb = new StringBuffer(); |
| 135 |
|
|
| 136 |
0 |
if (line.startsWith(">#_")) |
| 137 |
|
{ |
| 138 |
0 |
annotation = true; |
| 139 |
|
} |
| 140 |
|
} |
| 141 |
|
else |
| 142 |
|
{ |
| 143 |
0 |
sb.append(annotation ? uline : line); |
| 144 |
|
} |
| 145 |
|
} |
| 146 |
|
} |
| 147 |
|
|
| 148 |
0 |
if (annotation) |
| 149 |
|
{ |
| 150 |
0 |
annotations.addElement(makeAnnotation(seq, sb)); |
| 151 |
|
} |
| 152 |
|
|
| 153 |
0 |
else if (!firstLine) |
| 154 |
|
{ |
| 155 |
0 |
seq.setSequence(sb.toString()); |
| 156 |
0 |
seqs.addElement(seq); |
| 157 |
|
} |
| 158 |
|
} |
| 159 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 160 |
0 |
private AlignmentAnnotation makeAnnotation(SequenceI seq, StringBuffer sb)... |
| 161 |
|
{ |
| 162 |
0 |
Annotation[] anots = new Annotation[sb.length()]; |
| 163 |
0 |
char cb; |
| 164 |
0 |
for (int i = 0; i < anots.length; i++) |
| 165 |
|
{ |
| 166 |
0 |
char cn = sb.charAt(i); |
| 167 |
0 |
if (cn != ' ') |
| 168 |
|
{ |
| 169 |
0 |
anots[i] = new Annotation("" + cn, null, ' ', Float.NaN); |
| 170 |
|
} |
| 171 |
|
} |
| 172 |
0 |
AlignmentAnnotation aa = new AlignmentAnnotation( |
| 173 |
|
seq.getName().substring(2), seq.getDescription(), anots); |
| 174 |
0 |
return aa; |
| 175 |
|
} |
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
@param |
| 182 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 183 |
0 |
public void addAnnotations(Alignment al)... |
| 184 |
|
{ |
| 185 |
0 |
addProperties(al); |
| 186 |
0 |
for (int i = 0; i < annotations.size(); i++) |
| 187 |
|
{ |
| 188 |
0 |
AlignmentAnnotation aa = annotations.elementAt(i); |
| 189 |
0 |
aa.setPadGaps(true, al.getGapCharacter()); |
| 190 |
0 |
al.addAnnotation(aa); |
| 191 |
|
} |
| 192 |
|
} |
| 193 |
|
|
| |
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 8 |
Complexity Density: 0.47 |
|
| 194 |
0 |
@Override... |
| 195 |
|
public String print(SequenceI[] s, boolean jvsuffix) |
| 196 |
|
{ |
| 197 |
0 |
out = new StringBuffer(); |
| 198 |
0 |
int i = 0; |
| 199 |
|
|
| 200 |
0 |
while ((i < s.length) && (s[i] != null)) |
| 201 |
|
{ |
| 202 |
0 |
out.append(">" + printId(s[i], jvsuffix)); |
| 203 |
0 |
if (s[i].getDescription() != null) |
| 204 |
|
{ |
| 205 |
0 |
out.append(" " + s[i].getDescription()); |
| 206 |
|
} |
| 207 |
|
|
| 208 |
0 |
out.append(newline); |
| 209 |
|
|
| 210 |
0 |
int nochunks = (s[i].getLength() / len) |
| 211 |
0 |
+ (s[i].getLength() % len > 0 ? 1 : 0); |
| 212 |
|
|
| 213 |
0 |
for (int j = 0; j < nochunks; j++) |
| 214 |
|
{ |
| 215 |
0 |
int start = j * len; |
| 216 |
0 |
int end = start + len; |
| 217 |
|
|
| 218 |
0 |
if (end < s[i].getLength()) |
| 219 |
|
{ |
| 220 |
0 |
out.append(s[i].getSequenceAsString(start, end) + newline); |
| 221 |
|
} |
| 222 |
0 |
else if (start < s[i].getLength()) |
| 223 |
|
{ |
| 224 |
0 |
out.append(s[i].getSequenceAsString(start, s[i].getLength()) |
| 225 |
|
+ newline); |
| 226 |
|
} |
| 227 |
|
} |
| 228 |
|
|
| 229 |
0 |
i++; |
| 230 |
|
} |
| 231 |
|
|
| 232 |
0 |
return out.toString(); |
| 233 |
|
} |
| 234 |
|
} |