public void parse()\r
throws IOException\r
{\r
+ StringBuffer treeString=new StringBuffer();\r
+ String treeName = null;\r
// --------------- Variable Definitions -------------------\r
String line;\r
String version;\r
// String id;\r
- Hashtable alAnn = new Hashtable(); // Alignment wide annotations\r
- Hashtable seqAnn = new Hashtable(); // Sequence related annotations\r
+ Hashtable seqAnn = new Hashtable(); // Sequence related annotations\r
Hashtable seqs = new Hashtable();\r
Regex p, r, rend, s, x;\r
\r
int start = 1;\r
int end = -1;\r
String sid = acc;\r
+ // Retrieve hash of annotations for this accession\r
+ Hashtable accAnnotations = null;\r
+ \r
+ if (seqAnn!=null && seqAnn.containsKey(acc))\r
+ {\r
+ accAnnotations = (Hashtable) seqAnn.get(acc);\r
+ }\r
+ \r
// Split accession in id and from/to\r
if (p.search(acc))\r
{\r
//logger.debug(sid + ", " + start + ", " + end);\r
\r
Sequence seqO = new Sequence(sid, seq, start, end);\r
+ // Add Description (if any)\r
+ if (accAnnotations!=null && accAnnotations.containsKey("DE"))\r
+ {\r
+ String desc = (String) accAnnotations.get("DE");\r
+ seqO.setDescription((desc==null)?"" : desc);\r
+ }\r
+ // Add DB References (if any)\r
+ if (accAnnotations!=null && accAnnotations.containsKey("DR"))\r
+ {\r
+ String dbr = (String) accAnnotations.get("DR");\r
+ if (dbr!=null && dbr.indexOf(";")>-1)\r
+ {\r
+ String src = dbr.substring(0, dbr.indexOf(";"));\r
+ String acn = dbr.substring(dbr.indexOf(";")+1);\r
+ DBRefEntry dbref = new DBRefEntry(jalview.util.DBRefUtils.getCanonicalName(src), acn, "");\r
+ seqO.addDBRef(dbref);\r
+ }\r
+ }\r
Hashtable features = null;\r
// We need to adjust the positions of all features to account for gaps\r
try\r
{\r
- features = (Hashtable) ( (Hashtable) seqAnn.get(acc)).get(\r
+ features = (Hashtable) accAnnotations.get(\r
"features");\r
}\r
catch (java.lang.NullPointerException e)\r
Enumeration i = features.keys();\r
while (i.hasMoreElements())\r
{\r
+ // TODO: parse out secondary structure annotation as annotation row\r
+ // TODO: parse out scores as annotation row\r
+ // TODO: map coding region to core jalview feature types\r
String type = i.nextElement().toString();\r
Hashtable content = (Hashtable) features.get(type);\r
\r
Regex an = new Regex("(\\w+)\\s*(.*)");\r
if (an.search(annContent))\r
{\r
- alAnn.put(an.stringMatched(1), an.stringMatched(2));\r
+ if (an.stringMatched(1).equals("NH"))\r
+ {\r
+ treeString.append(an.stringMatched(2));\r
+ } else \r
+ if (an.stringMatched(1).equals("TN")) {\r
+ if (treeString.length()>0)\r
+ {\r
+ if (treeName==null)\r
+ {\r
+ treeName = "Tree "+(getTreeCount()+1);\r
+ }\r
+ addNewickTree(treeName, treeString.toString());\r
+ }\r
+ treeName = an.stringMatched(2);\r
+ treeString = new StringBuffer();\r
+ }\r
+ setAlignmentProperty(an.stringMatched(1), an.stringMatched(2));\r
}\r
}\r
else if (annType.equals("GS"))\r
String acc = s.stringMatched(1);\r
String type = s.stringMatched(2);\r
String content = s.stringMatched(3);\r
-\r
+ // TODO: store DR in a vector.\r
+ // TODO: store AC according to generic file db annotation.\r
Hashtable ann;\r
if (seqAnn.containsKey(acc))\r
{\r
}\r
else if (annType.equals("GC"))\r
{\r
- System.out.println(annContent);\r
// Generic per-Column annotation, exactly 1 char per column\r
+ // always need a label.\r
+ if (x.search(annContent))\r
+ {\r
+ // parse out and create alignment annotation directly.\r
+ AlignmentAnnotation annotation = parseAnnotationRow(x.stringMatched(1), x.stringMatched(2));\r
+ annotations.addElement(annotation);\r
+ }\r
}\r
else if (annType.equals("GR"))\r
{\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
+ private AlignmentAnnotation parseAnnotationRow(String label, String annots)\r
+ {\r
+ String type = (label.indexOf("_cons")==label.length()-5) ? label.substring(0, label.length()-5)\r
+ : label;\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, "", ' ', Float.NaN);\r
+ if (ss)\r
+ {\r
+ ann.secondaryStructure = jalview.schemes.ResidueProperties.getDssp3state(pos).charAt(0);\r
+ if (ann.secondaryStructure == pos.charAt(0) || pos.charAt(0)=='C')\r
+ {\r
+ ann.displayCharacter = "";\r
+ } else {\r
+ ann.displayCharacter += " ";\r
+ }\r
+ }\r
+ \r
+ els[i] = ann;\r
+ }\r
+ return new AlignmentAnnotation(label, label, els);\r
+ }\r
+ \r
public static String print(SequenceI[] s)\r
{\r
return "not yet implemented";\r