- Hashtable features;
- // Get an object with all the content for an annotation
- if (ann.containsKey("features"))
- {
- // logger.debug("Found features for " + acc);
- features = (Hashtable) ann.get("features");
- }
- else
- {
- // logger.debug("Creating new features holder for " + acc);
- features = new Hashtable();
- ann.put("features", features);
- }
-
- Hashtable content;
- if (features.containsKey(this.id2type(type)))
- {
- // logger.debug("Found content for " + this.id2type(type));
- content = (Hashtable) features.get(this.id2type(type));
- }
- else
- {
- // logger.debug("Creating new content holder for " +
- // this.id2type(type));
- content = new Hashtable();
- features.put(this.id2type(type), content);
- }
- String ns = (String) content.get(description);
- if (ns == null)
- {
- ns = "";
- }
- ns += seq;
- content.put(description, ns);
- Hashtable strucAnn;
- if (seqAnn.containsKey(acc))
- {
- strucAnn = (Hashtable) seqAnn.get(acc);
- }
- else
- {
- strucAnn = new Hashtable();
- }
-
- Vector newStruc = new Vector();
- parseAnnotationRow(newStruc, type, ns);
- strucAnn.put(type, newStruc);
- seqAnn.put(acc, strucAnn);
- }
- else
- {
- System.err
- .println("Warning - couldn't parse sequence annotation row line:\n"
- + line);
- // throw new IOException("Error parsing " + line);
- }
- }
- else
- {
- throw new IOException("Unknown annotation detected: " + annType
- + " " + annContent);
- }
- }
- }
- if (treeString.length() > 0)
- {
- if (treeName == null)
- {
- treeName = "Tree " + (1 + getTreeCount());
- }
- addNewickTree(treeName, treeString.toString());
- }
- }
-
- /**
- * Demangle an accession string and guess the originating sequence database for a given sequence
- * @param seqO sequence to be annotated
- * @param dbr Accession string for sequence
- * @param dbsource source database for alignment (PFAM or RFAM)
- */
- private void guessDatabaseFor(Sequence seqO, String dbr, String dbsource)
- {
- DBRefEntry dbrf=null;
- List<DBRefEntry> dbrs=new ArrayList<DBRefEntry>();
- String seqdb="Unknown",sdbac=""+dbr;
- int st=-1,en=-1,p;
- if ((st=sdbac.indexOf("/"))>-1)
- {
- String num,range=sdbac.substring(st+1);
- sdbac = sdbac.substring(0,st);
- if ((p=range.indexOf("-"))>-1)
- {
- p++;
- if (p<range.length())
- {
- num = range.substring(p).trim();
- try {
- en = Integer.parseInt(num);
- } catch (NumberFormatException x)
- {
- // could warn here that index is invalid
- en = -1;
- }
- }
- } else {
- p=range.length();
- }
- num=range.substring(0,p).trim();
- try {
- st = Integer.parseInt(num);
- } catch (NumberFormatException x)
- {
- // could warn here that index is invalid
- st = -1;
- }
- }
- if (dbsource.equals("PFAM")) {
- seqdb = "UNIPROT";
- if (sdbac.indexOf(".")>-1)
- {
- // strip of last subdomain
- sdbac = sdbac.substring(0,sdbac.indexOf("."));
- dbrf = jalview.util.DBRefUtils.parseToDbRef(seqO, seqdb, dbsource, sdbac);
- if (dbrf!=null)
- {
- dbrs.add(dbrf);
- }
- }
- dbrf = jalview.util.DBRefUtils.parseToDbRef(seqO, dbsource, dbsource, dbr);
- if (dbr!=null)
- {
- dbrs.add(dbrf);
- }
- } else {
- seqdb = "EMBL"; // total guess - could be ENA, or something else these days
- if (sdbac.indexOf(".")>-1)
- {
- // strip off last subdomain
- sdbac = sdbac.substring(0,sdbac.indexOf("."));
- dbrf = jalview.util.DBRefUtils.parseToDbRef(seqO, seqdb, dbsource, sdbac);
- if (dbrf!=null)
- {
- dbrs.add(dbrf);
- }
- }
-
- dbrf = jalview.util.DBRefUtils.parseToDbRef(seqO, dbsource, dbsource, dbr);
- if (dbrf!=null)
- {
- dbrs.add(dbrf);
- }
- }
- if (st!=-1 && en!=-1)
- {
- for (DBRefEntry d:dbrs)
- {
- jalview.util.MapList mp = new jalview.util.MapList(new int[] { seqO.getStart(),seqO.getEnd()},new int[] { st,en},1,1);
- jalview.datamodel.Mapping mping = new Mapping(mp);
- d.setMap(mping);
- }
- }
- }
-
- protected static AlignmentAnnotation parseAnnotationRow(
- Vector annotation, String label, String annots)
- {
- String convert1, convert2 = null;
-
- // Convert all bracket types to parentheses
- Regex openparen = new Regex("(<|\\[)", "(");
- Regex closeparen = new Regex("(>|\\])", ")");
-
- // Detect if file is RNA by looking for bracket types
- Regex detectbrackets = new Regex("(<|>|\\[|\\]|\\(|\\))");
-
- convert1 = openparen.replaceAll(annots);
- convert2 = closeparen.replaceAll(convert1);
- annots = convert2;
-
- String type = label;
- if (label.contains("_cons"))
- {
- type = (label.indexOf("_cons") == label.length() - 5) ? label
- .substring(0, label.length() - 5) : label;
- }
- boolean ss = false;
- type = id2type(type);
- if (type.equals("secondary structure"))
- {
- ss = true;
- }
- // decide on secondary structure or not.
- Annotation[] els = new Annotation[annots.length()];
- for (int i = 0; i < annots.length(); i++)
- {
- String pos = annots.substring(i, i + 1);
- Annotation ann;
- ann = new Annotation(pos, "", ' ', 0f); // 0f is 'valid' null - will not
- // be written out
- if (ss)
- {
- if (detectbrackets.search(pos))
- {
- ann.secondaryStructure = jalview.schemes.ResidueProperties
- .getRNASecStrucState(pos).charAt(0);
- }
- else
- {
- ann.secondaryStructure = jalview.schemes.ResidueProperties
- .getDssp3state(pos).charAt(0);
- }
-
- if (ann.secondaryStructure == pos.charAt(0) || pos.charAt(0) == 'C')
- {
- ann.displayCharacter = ""; // null; // " ";
- }
- else
- {
- ann.displayCharacter = " " + ann.displayCharacter;
- }
- }
-
- els[i] = ann;
- }
- AlignmentAnnotation annot = null;
- Enumeration e = annotation.elements();
- while (e.hasMoreElements())
- {
- annot = (AlignmentAnnotation) e.nextElement();
- if (annot.label.equals(type))
- break;
- annot = null;
- }
- if (annot == null)
- {
- annot = new AlignmentAnnotation(type, type, els);
- annotation.addElement(annot);
- }
- else
- {
- Annotation[] anns = new Annotation[annot.annotations.length
- + els.length];
- System.arraycopy(annot.annotations, 0, anns, 0,
- annot.annotations.length);
- System.arraycopy(els, 0, anns, annot.annotations.length, els.length);
- annot.annotations = anns;
- // System.out.println("else: ");
- }
- return annot;
- }
-
+ Hashtable features;\r
+ // Get an object with all the content for an annotation\r
+ if (ann.containsKey("features"))\r
+ {\r
+ // logger.debug("Found features for " + acc);\r
+ features = (Hashtable) ann.get("features");\r
+ }\r
+ else\r
+ {\r
+ // logger.debug("Creating new features holder for " + acc);\r
+ features = new Hashtable();\r
+ ann.put("features", features);\r
+ }\r
+ \r
+ Hashtable content;\r
+ if (features.containsKey(this.id2type(type)))\r
+ {\r
+ // logger.debug("Found content for " + this.id2type(type));\r
+ content = (Hashtable) features.get(this.id2type(type));\r
+ }\r
+ else\r
+ {\r
+ // logger.debug("Creating new content holder for " +\r
+ // this.id2type(type));\r
+ content = new Hashtable();\r
+ features.put(this.id2type(type), content);\r
+ }\r
+ String ns = (String) content.get(description);\r
+ if (ns == null)\r
+ {\r
+ ns = "";\r
+ }\r
+ ns += seq;\r
+ content.put(description, ns);\r
+
+// if(type.equals("SS")){\r
+ Hashtable strucAnn;\r
+ if (seqAnn.containsKey(acc))\r
+ {\r
+ strucAnn = (Hashtable) seqAnn.get(acc);\r
+ }\r
+ else\r
+ {\r
+ strucAnn = new Hashtable();\r
+ }\r
+ \r
+ Vector newStruc=new Vector();\r
+ parseAnnotationRow(newStruc, type,ns);\r
+ \r
+ strucAnn.put(type, newStruc);\r
+ seqAnn.put(acc, strucAnn);\r
+ }\r
+// }\r
+ else\r
+ {\r
+ System.err\r
+ .println("Warning - couldn't parse sequence annotation row line:\n"\r
+ + line);\r
+ // throw new IOException("Error parsing " + line);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ throw new IOException("Unknown annotation detected: " + annType\r
+ + " " + annContent);\r
+ }\r
+ }\r
+ }\r
+ if (treeString.length() > 0)\r
+ {\r
+ if (treeName == null)\r
+ {\r
+ treeName = "Tree " + (1 + getTreeCount());\r
+ }\r
+ addNewickTree(treeName, treeString.toString());\r
+ }\r
+ }\r
+\r
+/**\r
+ * Demangle an accession string and guess the originating sequence database for a given sequence\r
+ * @param seqO sequence to be annotated\r
+ * @param dbr Accession string for sequence\r
+ * @param dbsource source database for alignment (PFAM or RFAM)\r
+ */\r
+ private void guessDatabaseFor(Sequence seqO, String dbr, String dbsource)\r
+ {\r
+ DBRefEntry dbrf=null;\r
+ List<DBRefEntry> dbrs=new ArrayList<DBRefEntry>();\r
+ String seqdb="Unknown",sdbac=""+dbr;\r
+ int st=-1,en=-1,p;\r
+ if ((st=sdbac.indexOf("/"))>-1)\r
+ {\r
+ String num,range=sdbac.substring(st+1);\r
+ sdbac = sdbac.substring(0,st);\r
+ if ((p=range.indexOf("-"))>-1)\r
+ {\r
+ p++;\r
+ if (p<range.length())\r
+ {\r
+ num = range.substring(p).trim();\r
+ try {\r
+ en = Integer.parseInt(num);\r
+ } catch (NumberFormatException x)\r
+ {\r
+ // could warn here that index is invalid\r
+ en = -1;\r
+ }\r
+ }\r
+ } else {\r
+ p=range.length();\r
+ }\r
+ num=range.substring(0,p).trim();\r
+ try {\r
+ st = Integer.parseInt(num);\r
+ } catch (NumberFormatException x)\r
+ {\r
+ // could warn here that index is invalid\r
+ st = -1;\r
+ }\r
+ }\r
+ if (dbsource.equals("PFAM")) {\r
+ seqdb = "UNIPROT";\r
+ if (sdbac.indexOf(".")>-1)\r
+ {\r
+ // strip of last subdomain\r
+ sdbac = sdbac.substring(0,sdbac.indexOf("."));\r
+ dbrf = jalview.util.DBRefUtils.parseToDbRef(seqO, seqdb, dbsource, sdbac);\r
+ if (dbrf!=null)\r
+ {\r
+ dbrs.add(dbrf);\r
+ }\r
+ }\r
+ dbrf = jalview.util.DBRefUtils.parseToDbRef(seqO, dbsource, dbsource, dbr);\r
+ if (dbr!=null)\r
+ {\r
+ dbrs.add(dbrf);\r
+ }\r
+ } else {\r
+ seqdb = "EMBL"; // total guess - could be ENA, or something else these days\r
+ if (sdbac.indexOf(".")>-1)\r
+ {\r
+ // strip off last subdomain\r
+ sdbac = sdbac.substring(0,sdbac.indexOf("."));\r
+ dbrf = jalview.util.DBRefUtils.parseToDbRef(seqO, seqdb, dbsource, sdbac);\r
+ if (dbrf!=null)\r
+ {\r
+ dbrs.add(dbrf);\r
+ }\r
+ }\r
+ \r
+ dbrf = jalview.util.DBRefUtils.parseToDbRef(seqO, dbsource, dbsource, dbr);\r
+ if (dbrf!=null)\r
+ {\r
+ dbrs.add(dbrf);\r
+ }\r
+ }\r
+ if (st!=-1 && en!=-1)\r
+ {\r
+ for (DBRefEntry d:dbrs)\r
+ {\r
+ jalview.util.MapList mp = new jalview.util.MapList(new int[] { seqO.getStart(),seqO.getEnd()},new int[] { st,en},1,1);\r
+ jalview.datamodel.Mapping mping = new Mapping(mp);\r
+ d.setMap(mping);\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * Parse a file in Stockholm format into Jalview's data model using VARNA\r
+ * \r
+ * @throws IOException\r
+ * If there is an error with the input file\r
+ */\r
+ public void parse_with_VARNA() throws IOException\r
+ {\r
+ FileReader fr = null;\r
+ fr = new FileReader(inFile);\r
+\r
+ BufferedReader r = new BufferedReader(fr);\r
+ result = null;\r
+ try\r
+ {\r
+ result = RNAFactory.loadSecStrStockholm(r);\r
+ } catch (ExceptionUnmatchedClosingParentheses umcp)\r
+ {\r
+ errormessage = "Unmatched parentheses in annotation. Aborting ("\r
+ + umcp.getMessage() + ")";\r
+ throw new IOException(umcp);\r
+ }\r
+ // DEBUG System.out.println("this is the secondary scructure:"\r
+ // +result.size());\r
+ SequenceI[] seqs = new SequenceI[result.size()];\r
+ String id=null;\r
+ for (int i = 0; i < result.size(); i++)\r
+ {\r
+ // DEBUG System.err.println("Processing i'th sequence in Stockholm file")\r
+ RNA current = result.get(i);\r
+\r
+ String seq = current.getSeq();\r
+ String rna = current.getStructDBN(true);\r
+ // DEBUG System.out.println(seq);\r
+ // DEBUG System.err.println(rna);\r
+ int begin = 0;\r
+ int end = seq.length() - 1;\r
+ id = safeName(getDataName());\r
+ seqs[i] = new Sequence(id, seq, begin, end);\r
+ String[] annot = new String[rna.length()];\r
+ Annotation[] ann = new Annotation[rna.length()];\r
+ for (int j = 0; j < rna.length(); j++)\r
+ {\r
+ annot[j] = rna.substring(j, j + 1);\r
+\r
+ }\r
+\r
+ for (int k = 0; k < rna.length(); k++)\r
+ {\r
+ ann[k] = new Annotation(annot[k], "",\r
+ jalview.schemes.ResidueProperties.getRNASecStrucState(\r
+ annot[k]).charAt(0), 0f);\r
+\r
+ }\r
+ AlignmentAnnotation align = new AlignmentAnnotation("Sec. str.",\r
+ current.getID(), ann);\r
+\r
+ seqs[i].addAlignmentAnnotation(align);\r
+ seqs[i].setRNA(result.get(i));\r
+ this.annotations.addElement(align);\r
+ }\r
+ this.setSeqs(seqs);\r
+\r
+ }\r
+\r
+ protected static AlignmentAnnotation parseAnnotationRow(\r
+ Vector annotation, String label, String annots)\r
+ {\r
+ String convert1, convert2 = null;\r
+\r
+ // Convert all bracket types to parentheses\r
+ Regex openparen = new Regex("(<|\\[)", "(");\r
+ Regex closeparen = new Regex("(>|\\])", ")");\r
+\r
+ // Detect if file is RNA by looking for bracket types\r
+ Regex detectbrackets = new Regex("(<|>|\\[|\\]|\\(|\\))");\r
+\r
+ convert1 = openparen.replaceAll(annots);\r
+ convert2 = closeparen.replaceAll(convert1);\r
+ annots = convert2;\r
+\r
+ String type = label;\r
+ if (label.contains("_cons"))\r
+ {\r
+ type = (label.indexOf("_cons") == label.length() - 5) ? label\r
+ .substring(0, label.length() - 5) : label;\r
+ }\r
+ boolean ss = false;\r
+ type = id2type(type);\r
+ if (type.equals("secondary structure"))\r
+ {\r
+ ss = true;\r
+ }\r
+ // decide on secondary structure or not.\r
+ Annotation[] els = new Annotation[annots.length()];\r
+ for (int i = 0; i < annots.length(); i++)\r
+ {\r
+ String pos = annots.substring(i, i + 1);\r
+ Annotation ann;\r
+ ann = new Annotation(pos, "", ' ', 0f); // 0f is 'valid' null - will not\r
+ // be written out\r
+ if (ss)\r
+ {\r
+ if (detectbrackets.search(pos))\r
+ {\r
+ ann.secondaryStructure = jalview.schemes.ResidueProperties\r
+ .getRNASecStrucState(pos).charAt(0);\r
+ }\r
+ else\r
+ {\r
+ ann.secondaryStructure = jalview.schemes.ResidueProperties\r
+ .getDssp3state(pos).charAt(0);\r
+ }\r
+\r
+ if (ann.secondaryStructure == pos.charAt(0) || pos.charAt(0) == 'C')\r
+ {\r
+ ann.displayCharacter = ""; // null; // " ";\r
+ }\r
+ else\r
+ {\r
+ ann.displayCharacter = " " + ann.displayCharacter;\r
+ }\r
+ }\r
+\r
+ els[i] = ann;\r
+ }\r
+ AlignmentAnnotation annot = null;\r
+ Enumeration e = annotation.elements();\r
+ while (e.hasMoreElements())\r
+ {\r
+ annot = (AlignmentAnnotation) e.nextElement();\r
+ if (annot.label.equals(type))\r
+ break;\r
+ annot = null;\r
+ }\r
+ if (annot == null)\r
+ {\r
+ annot = new AlignmentAnnotation(type, type, els);\r
+ annotation.addElement(annot);\r
+ }\r
+ else\r
+ {\r
+ Annotation[] anns = new Annotation[annot.annotations.length\r
+ + els.length];\r
+ System.arraycopy(annot.annotations, 0, anns, 0,\r
+ annot.annotations.length);\r
+ System.arraycopy(els, 0, anns, annot.annotations.length, els.length);\r
+ annot.annotations = anns;\r
+ // System.out.println("else: ");\r
+ }\r
+ return annot;\r
+ }\r
+\r