X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FStockholmFile.java;h=ccbe8180477364cb52db5158b88de89af00df4c2;hb=f683f4d6c8af43be0ffeb96513b52572619efed5;hp=dedbd440d9ac5c31d17f25f3ff06f5665a0acc2a;hpb=0812da43d6b8d673aa25d2d7a7c5f65aab1b1642;p=jalview.git diff --git a/src/jalview/io/StockholmFile.java b/src/jalview/io/StockholmFile.java index dedbd44..ccbe818 100644 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@ -31,9 +31,15 @@ import jalview.datamodel.*; /** * This class is supposed to parse a Stockholm format file into Jalview - * + * There are TODOs in this class: we do not know what the database source and + * version is for the file when parsing the #GS= AC tag which associates accessions + * with sequences. + * Database references are also not parsed correctly: a separate reference string + * parser must be added to parse the database reference form into Jalview's local + * representation. * @author bsb at sanger.ac.uk - * @version 0.3 + * @version 0.3 + jalview mods + * */ public class StockholmFile extends AlignFile { @@ -47,7 +53,10 @@ public class StockholmFile extends AlignFile { super(inFile, type); } - + public StockholmFile(FileParse source) throws IOException + { + super(source); + } public void initData() { super.initData(); @@ -91,7 +100,7 @@ public class StockholmFile extends AlignFile rend = new Regex("\\/\\/"); // Find the end of an alignment p = new Regex("(\\S+)\\/(\\d+)\\-(\\d+)"); // split sequence id in // id/from/to - s = new Regex("(\\S+)\\s+(\\w{2})\\s+(.*)"); // Parses annotation subtype + s = new Regex("(\\S+)\\s+(\\S*)\\s+(.*)"); // Parses annotation subtype r = new Regex("#=(G[FSRC]?)\\s+(.*)"); // Finds any annotation line x = new Regex("(\\S+)\\s+(\\S+)"); // split id from sequence @@ -118,7 +127,7 @@ public class StockholmFile extends AlignFile { String acc = (String) accs.nextElement(); // logger.debug("Processing sequence " + acc); - String seq = (String) seqs.get(acc); + String seq = (String) seqs.remove(acc); if (maxLength < seq.length()) { maxLength = seq.length(); @@ -131,7 +140,7 @@ public class StockholmFile extends AlignFile if (seqAnn != null && seqAnn.containsKey(acc)) { - accAnnotations = (Hashtable) seqAnn.get(acc); + accAnnotations = (Hashtable) seqAnn.remove(acc); } // Split accession in id and from/to @@ -158,16 +167,15 @@ public class StockholmFile extends AlignFile { String src = dbr.substring(0, dbr.indexOf(";")); String acn = dbr.substring(dbr.indexOf(";") + 1); - DBRefEntry dbref = new DBRefEntry(jalview.util.DBRefUtils - .getCanonicalName(src), acn, ""); - seqO.addDBRef(dbref); + jalview.util.DBRefUtils.parseToDbRef(seqO, src, "0", acn); + //seqO.addDBRef(dbref); } } Hashtable features = null; // We need to adjust the positions of all features to account for gaps try { - features = (Hashtable) accAnnotations.get("features"); + features = (Hashtable) accAnnotations.remove("features"); } catch (java.lang.NullPointerException e) { // loggerwarn("Getting Features for " + acc + ": " + @@ -177,6 +185,7 @@ public class StockholmFile extends AlignFile // if we have features if (features != null) { + int posmap[] = seqO.findPositionMap(); Enumeration i = features.keys(); while (i.hasMoreElements()) { @@ -185,8 +194,7 @@ public class StockholmFile extends AlignFile // TODO: parse out scores as annotation row // TODO: map coding region to core jalview feature types String type = i.nextElement().toString(); - Hashtable content = (Hashtable) features.get(type); - + Hashtable content = (Hashtable) features.remove(type); Enumeration j = content.keys(); while (j.hasMoreElements()) { @@ -196,9 +204,9 @@ public class StockholmFile extends AlignFile for (int k = 0; k < byChar.length; k++) { char c = byChar[k]; - if (!(c == ' ' || c == '_' || c == '-')) + if (!(c == ' ' || c == '_' || c == '-' || c == '.')) // PFAM uses '.' for feature background { - int new_pos = seqO.findPosition(k); + int new_pos = posmap[k]; // look up nearest seqeunce position to this column SequenceFeature feat = new SequenceFeature(type, desc, new_pos, new_pos, 0f, null); @@ -208,12 +216,15 @@ public class StockholmFile extends AlignFile } } - + } + // garbage collect + // logger.debug("Adding seq " + acc + " from " + start + " to " + end // + ": " + seq); this.seqs.addElement(seqO); } + return; // finished parsing this segment of source } else if (!r.search(line)) { @@ -365,14 +376,18 @@ public class StockholmFile extends AlignFile { String acc = s.stringMatched(1); String type = s.stringMatched(2); - String seq = s.stringMatched(3); - String description = new String(); - + String seq = new String(s.stringMatched(3)); + String description = null; // Check for additional information about the current annotation - if (x.search(seq)) + // We use a simple string tokenizer here for speed + StringTokenizer sep = new StringTokenizer(seq," \t"); + description = sep.nextToken(); + if (sep.hasMoreTokens()) { - description = x.stringMatched(1); - seq = x.stringMatched(2); + seq = sep.nextToken(); + } else { + seq = description; + description = new String(); } // sequence id with from-to fields @@ -427,7 +442,8 @@ public class StockholmFile extends AlignFile } else { - throw new IOException("Error parsing " + line); + System.err.println("Warning - couldn't parse sequence annotation row line:\n"+line); + // throw new IOException("Error parsing " + line); } } else @@ -464,18 +480,18 @@ public class StockholmFile extends AlignFile { String pos = annots.substring(i, i + 1); Annotation ann; - ann = new Annotation(pos, "", ' ', Float.NaN); + ann = new Annotation(pos, "", ' ', 0f); // 0f is 'valid' null - will not be written out if (ss) { ann.secondaryStructure = jalview.schemes.ResidueProperties .getDssp3state(pos).charAt(0); if (ann.secondaryStructure == pos.charAt(0) || pos.charAt(0) == 'C') { - ann.displayCharacter = ""; + ann.displayCharacter = ""; // null; // " "; } else { - ann.displayCharacter += " "; + ann.displayCharacter = " "+ann.displayCharacter; } } @@ -493,7 +509,7 @@ public class StockholmFile extends AlignFile if (annot == null) { annot = new AlignmentAnnotation(type, type, els); - annotation.add(annot); + annotation.addElement(annot); } else {