| 1 |
|
package jalview.io; |
| 2 |
|
|
| 3 |
|
import java.io.IOException; |
| 4 |
|
import java.util.ArrayList; |
| 5 |
|
import java.util.Arrays; |
| 6 |
|
import java.util.LinkedHashMap; |
| 7 |
|
import java.util.List; |
| 8 |
|
import java.util.Map; |
| 9 |
|
import java.util.regex.Matcher; |
| 10 |
|
import java.util.regex.Pattern; |
| 11 |
|
|
| 12 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 13 |
|
import jalview.datamodel.Sequence; |
| 14 |
|
import jalview.datamodel.SequenceI; |
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| |
|
| 71.6% |
Uncovered Elements: 19 (67) |
Complexity: 15 |
Complexity Density: 0.35 |
|
| 34 |
|
public class LayeredDBNParser extends AlignFile |
| 35 |
|
{ |
| 36 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 37 |
1 |
public LayeredDBNParser(String dataObject, DataSourceType sourceType)... |
| 38 |
|
throws IOException |
| 39 |
|
{ |
| 40 |
1 |
super(dataObject, sourceType); |
| 41 |
|
} |
| 42 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 43 |
3 |
public LayeredDBNParser(FileParse source) throws IOException... |
| 44 |
|
{ |
| 45 |
3 |
super(source); |
| 46 |
|
} |
| 47 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 48 |
0 |
public LayeredDBNParser()... |
| 49 |
|
{ |
| 50 |
|
|
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
private Record parsedRecord; |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| |
|
| 50% |
Uncovered Elements: 5 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 58 |
|
public static class Chain |
| 59 |
|
{ |
| 60 |
|
public final String code; |
| 61 |
|
|
| 62 |
|
public final String identifier; |
| 63 |
|
|
| 64 |
|
public final int start; |
| 65 |
|
|
| 66 |
|
public final int end; |
| 67 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 68 |
8 |
public Chain(String code, String identifier, int start, int end)... |
| 69 |
|
{ |
| 70 |
8 |
this.code = code; |
| 71 |
8 |
this.identifier = identifier; |
| 72 |
8 |
this.start = start; |
| 73 |
8 |
this.end = end; |
| 74 |
|
} |
| 75 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 76 |
0 |
@Override... |
| 77 |
|
public String toString() |
| 78 |
|
{ |
| 79 |
0 |
String idStr = (identifier != null) ? "[" + identifier + "]" : ""; |
| 80 |
0 |
return String.format("Chain{code='%s'%s, start=%d, end=%d}", code, |
| 81 |
|
idStr, start, end); |
| 82 |
|
} |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 88 |
|
public static class CompactBp |
| 89 |
|
{ |
| 90 |
|
public final int position; |
| 91 |
|
|
| 92 |
|
public final char bracket; |
| 93 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 94 |
0 |
public CompactBp(int position, char bracket)... |
| 95 |
|
{ |
| 96 |
0 |
this.position = position; |
| 97 |
0 |
this.bracket = bracket; |
| 98 |
|
} |
| 99 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 100 |
0 |
@Override... |
| 101 |
|
public String toString() |
| 102 |
|
{ |
| 103 |
0 |
return String.format("(%d, %c)", position, bracket); |
| 104 |
|
} |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| |
|
| 31.2% |
Uncovered Elements: 11 (16) |
Complexity: 7 |
Complexity Density: 0.88 |
|
| 111 |
|
public static class BpSpec |
| 112 |
|
{ |
| 113 |
|
private final String wuss; |
| 114 |
|
|
| 115 |
|
private final List<CompactBp> compacts; |
| 116 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 117 |
48 |
public BpSpec(String wuss)... |
| 118 |
|
{ |
| 119 |
48 |
this.wuss = wuss; |
| 120 |
48 |
this.compacts = null; |
| 121 |
|
} |
| 122 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 123 |
0 |
public BpSpec(List<CompactBp> compacts)... |
| 124 |
|
{ |
| 125 |
0 |
this.wuss = null; |
| 126 |
0 |
this.compacts = compacts; |
| 127 |
|
} |
| 128 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 129 |
0 |
public boolean isWuss()... |
| 130 |
|
{ |
| 131 |
0 |
return wuss != null; |
| 132 |
|
} |
| 133 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 134 |
60 |
public String getWuss()... |
| 135 |
|
{ |
| 136 |
60 |
return wuss; |
| 137 |
|
} |
| 138 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 139 |
0 |
public List<CompactBp> getCompacts()... |
| 140 |
|
{ |
| 141 |
0 |
return compacts; |
| 142 |
|
} |
| 143 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 144 |
0 |
@Override... |
| 145 |
|
public String toString() |
| 146 |
|
{ |
| 147 |
0 |
return isWuss() ? "WUSS[" + wuss + "]" |
| 148 |
|
: "Compact" + compacts.toString(); |
| 149 |
|
} |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
|
| 153 |
|
|
| 154 |
|
|
| |
|
| 64.3% |
Uncovered Elements: 10 (28) |
Complexity: 3 |
Complexity Density: 0.12 |
|
| 155 |
|
public static class Record |
| 156 |
|
{ |
| 157 |
|
public String title; |
| 158 |
|
|
| 159 |
|
public List<Chain> chains = new ArrayList<>(); |
| 160 |
|
|
| 161 |
|
|
| 162 |
|
public List<String> sequences = new ArrayList<>(); |
| 163 |
|
|
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
public Map<String, List<BpSpec>> basePairs = new LinkedHashMap<>(); |
| 168 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 169 |
0 |
@Override... |
| 170 |
|
public String toString() |
| 171 |
|
{ |
| 172 |
0 |
StringBuilder sb = new StringBuilder(); |
| 173 |
0 |
sb.append("Title: ").append(title).append("\n"); |
| 174 |
0 |
sb.append("Chains: ").append(chains).append("\n"); |
| 175 |
0 |
sb.append("Sequences: ").append(sequences).append("\n"); |
| 176 |
0 |
sb.append("Base Pairs:\n"); |
| 177 |
0 |
for (Map.Entry<String, List<BpSpec>> entry : basePairs.entrySet()) |
| 178 |
|
{ |
| 179 |
0 |
sb.append(" ").append(entry.getKey()).append(" -> ") |
| 180 |
|
.append(entry.getValue()).append("\n"); |
| 181 |
|
} |
| 182 |
0 |
return sb.toString(); |
| 183 |
|
} |
| 184 |
|
|
| |
|
| 94.4% |
Uncovered Elements: 1 (18) |
Complexity: 2 |
Complexity Density: 0.12 |
|
| 185 |
4 |
public void generateJalviewSequences(LayeredDBNParser layeredDBNParser)... |
| 186 |
|
{ |
| 187 |
4 |
int ch_index = 0; |
| 188 |
4 |
for (Chain chain : chains) |
| 189 |
|
{ |
| 190 |
8 |
String chcode = chains.get(ch_index).code,symid=chains.get(ch_index).identifier; |
| 191 |
8 |
SequenceI seq = new Sequence( |
| 192 |
|
title + "|" + chcode |
| 193 |
8 |
+ (symid==null ?"":"["+chains.get(ch_index).identifier+"]"), |
| 194 |
|
sequences.get(ch_index)); |
| 195 |
|
|
| 196 |
8 |
seq.setStart(chains.get(ch_index).start); |
| 197 |
8 |
seq.setEnd(chains.get(ch_index).end); |
| 198 |
|
|
| 199 |
8 |
boolean first = true; |
| 200 |
8 |
layeredDBNParser.addSequence(seq); |
| 201 |
8 |
for (String bpType : basePairs.keySet()) |
| 202 |
|
{ |
| 203 |
48 |
BpSpec dbn = basePairs.get(bpType).get(ch_index); |
| 204 |
48 |
AlignmentAnnotation ssa = StockholmFile.parseAnnotationRow( |
| 205 |
|
layeredDBNParser.annotations, "secondary structure", |
| 206 |
|
dbn.getWuss()); |
| 207 |
48 |
ssa.label = "bp:" + bpType; |
| 208 |
48 |
seq.addAlignmentAnnotation(ssa); |
| 209 |
48 |
ssa.height = 40; |
| 210 |
|
|
| 211 |
48 |
first = false; |
| 212 |
|
} |
| 213 |
8 |
ch_index++; |
| 214 |
|
} |
| 215 |
|
} |
| 216 |
|
} |
| 217 |
|
|
| 218 |
|
|
| 219 |
|
|
| 220 |
|
private static final Pattern CHAIN_PATTERN = Pattern.compile( |
| 221 |
|
"(?:chain[s]?\\s+)?([A-Za-z0-9_]+)(?:\\[([^\\]]+)\\])?\\((\\d+)-(\\d+)\\)"); |
| 222 |
|
|
| 223 |
|
|
| 224 |
|
|
| 225 |
|
private static final Pattern COMPACT_LIST_PATTERN = Pattern |
| 226 |
|
.compile("^(\\s*,?\\s*\\(\\s*\\d+\\s*,\\s*[^\\s]\\s*\\)\\s*)+$"); |
| 227 |
|
|
| 228 |
|
|
| 229 |
|
|
| 230 |
|
private static final Pattern COMPACT_BP_PATTERN = Pattern |
| 231 |
|
.compile("\\(\\s*(\\d+)\\s*,\\s*([^\\s])\\s*\\)"); |
| 232 |
|
|
| 233 |
|
|
| 234 |
|
|
| 235 |
|
|
| 236 |
|
|
| 237 |
|
@throws |
| 238 |
|
|
| 239 |
|
|
| |
|
| 71.9% |
Uncovered Elements: 16 (57) |
Complexity: 10 |
Complexity Density: 0.26 |
|
| 240 |
4 |
@Override... |
| 241 |
|
public void parse() throws IOException |
| 242 |
|
{ |
| 243 |
4 |
parsedRecord = new Record(); |
| 244 |
|
|
| 245 |
4 |
String line; |
| 246 |
? |
while ((line = nextLine()) != null) |
| 247 |
|
{ |
| 248 |
32 |
line = line.trim(); |
| 249 |
32 |
if (line.isEmpty()) |
| 250 |
0 |
continue; |
| 251 |
|
|
| 252 |
|
|
| 253 |
32 |
if (line.startsWith(">")) |
| 254 |
|
{ |
| 255 |
|
|
| 256 |
4 |
int colonIndex = line.indexOf(':'); |
| 257 |
4 |
if (colonIndex != -1) |
| 258 |
|
{ |
| 259 |
4 |
parsedRecord.title = line.substring(1, colonIndex).trim(); |
| 260 |
4 |
String chainInfo = line.substring(colonIndex + 1); |
| 261 |
|
|
| 262 |
|
|
| 263 |
4 |
Matcher matcher = CHAIN_PATTERN.matcher(chainInfo); |
| 264 |
12 |
while (matcher.find()) |
| 265 |
|
{ |
| 266 |
8 |
String code = matcher.group(1); |
| 267 |
8 |
String identifier = matcher.group(2); |
| 268 |
8 |
int start = Integer.parseInt(matcher.group(3)); |
| 269 |
8 |
int end = Integer.parseInt(matcher.group(4)); |
| 270 |
8 |
parsedRecord.chains |
| 271 |
|
.add(new Chain(code, identifier, start, end)); |
| 272 |
|
} |
| 273 |
|
} |
| 274 |
|
} |
| 275 |
|
|
| 276 |
|
else |
| 277 |
|
{ |
| 278 |
28 |
int colonIndex = line.indexOf(':'); |
| 279 |
28 |
if (colonIndex != -1) |
| 280 |
|
{ |
| 281 |
28 |
String key = line.substring(0, colonIndex).trim(); |
| 282 |
|
|
| 283 |
|
|
| 284 |
28 |
String value = line.substring(colonIndex + 1).trim(); |
| 285 |
|
|
| 286 |
|
|
| 287 |
28 |
List<String> segments = Arrays.asList(value.split("&")); |
| 288 |
|
|
| 289 |
28 |
if ("seq".equalsIgnoreCase(key)) |
| 290 |
|
{ |
| 291 |
4 |
parsedRecord.sequences.addAll(segments); |
| 292 |
|
} |
| 293 |
|
else |
| 294 |
|
{ |
| 295 |
24 |
List<BpSpec> bpSpecs = new ArrayList<>(); |
| 296 |
24 |
for (String segment : segments) |
| 297 |
|
{ |
| 298 |
48 |
segment = segment.trim(); |
| 299 |
|
|
| 300 |
48 |
if (COMPACT_LIST_PATTERN.matcher(segment).matches()) |
| 301 |
|
{ |
| 302 |
0 |
List<CompactBp> compactList = new ArrayList<>(); |
| 303 |
0 |
Matcher matcher = COMPACT_BP_PATTERN.matcher(segment); |
| 304 |
0 |
while (matcher.find()) |
| 305 |
|
{ |
| 306 |
0 |
int pos = Integer.parseInt(matcher.group(1)); |
| 307 |
0 |
char bracket = matcher.group(2).charAt(0); |
| 308 |
0 |
compactList.add(new CompactBp(pos, bracket)); |
| 309 |
|
} |
| 310 |
0 |
bpSpecs.add(new BpSpec(compactList)); |
| 311 |
|
} |
| 312 |
|
else |
| 313 |
|
{ |
| 314 |
48 |
bpSpecs.add(new BpSpec(segment)); |
| 315 |
|
} |
| 316 |
|
} |
| 317 |
24 |
parsedRecord.basePairs.put(key, bpSpecs); |
| 318 |
|
} |
| 319 |
|
} |
| 320 |
|
} |
| 321 |
|
} |
| 322 |
|
|
| 323 |
4 |
parsedRecord.generateJalviewSequences(this); |
| 324 |
|
|
| 325 |
|
} |
| 326 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 327 |
1 |
public Record getRecord()... |
| 328 |
|
{ |
| 329 |
1 |
return parsedRecord; |
| 330 |
|
} |
| 331 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 332 |
0 |
@Override... |
| 333 |
|
public String print(SequenceI[] seqs, boolean jvsuffix) |
| 334 |
|
{ |
| 335 |
|
|
| 336 |
0 |
return null; |
| 337 |
|
} |
| 338 |
|
} |