From 70cb8184fe397a90f60ecc06d419ff2f7fbbb433 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 30 Apr 2007 13:23:14 +0000 Subject: [PATCH] parse alignment properties and add annotation rows for general alignment position annotation. --- src/jalview/io/StockholmFile.java | 106 ++++++++++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 6 deletions(-) diff --git a/src/jalview/io/StockholmFile.java b/src/jalview/io/StockholmFile.java index 10ddf53..9104a5f 100644 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@ -62,12 +62,13 @@ public class StockholmFile public void parse() throws IOException { + StringBuffer treeString=new StringBuffer(); + String treeName = null; // --------------- Variable Definitions ------------------- String line; String version; // String id; - Hashtable alAnn = new Hashtable(); // Alignment wide annotations - Hashtable seqAnn = new Hashtable(); // Sequence related annotations + Hashtable seqAnn = new Hashtable(); // Sequence related annotations Hashtable seqs = new Hashtable(); Regex p, r, rend, s, x; @@ -122,6 +123,14 @@ public class StockholmFile int start = 1; int end = -1; String sid = acc; + // Retrieve hash of annotations for this accession + Hashtable accAnnotations = null; + + if (seqAnn!=null && seqAnn.containsKey(acc)) + { + accAnnotations = (Hashtable) seqAnn.get(acc); + } + // Split accession in id and from/to if (p.search(acc)) { @@ -132,11 +141,29 @@ public class StockholmFile //logger.debug(sid + ", " + start + ", " + end); Sequence seqO = new Sequence(sid, seq, start, end); + // Add Description (if any) + if (accAnnotations!=null && accAnnotations.containsKey("DE")) + { + String desc = (String) accAnnotations.get("DE"); + seqO.setDescription((desc==null)?"" : desc); + } + // Add DB References (if any) + if (accAnnotations!=null && accAnnotations.containsKey("DR")) + { + String dbr = (String) accAnnotations.get("DR"); + if (dbr!=null && dbr.indexOf(";")>-1) + { + 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); + } + } Hashtable features = null; // We need to adjust the positions of all features to account for gaps try { - features = (Hashtable) ( (Hashtable) seqAnn.get(acc)).get( + features = (Hashtable) accAnnotations.get( "features"); } catch (java.lang.NullPointerException e) @@ -150,6 +177,9 @@ public class StockholmFile Enumeration i = features.keys(); while (i.hasMoreElements()) { + // TODO: parse out secondary structure annotation as annotation row + // 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); @@ -258,7 +288,23 @@ public class StockholmFile Regex an = new Regex("(\\w+)\\s*(.*)"); if (an.search(annContent)) { - alAnn.put(an.stringMatched(1), an.stringMatched(2)); + if (an.stringMatched(1).equals("NH")) + { + treeString.append(an.stringMatched(2)); + } else + if (an.stringMatched(1).equals("TN")) { + if (treeString.length()>0) + { + if (treeName==null) + { + treeName = "Tree "+(getTreeCount()+1); + } + addNewickTree(treeName, treeString.toString()); + } + treeName = an.stringMatched(2); + treeString = new StringBuffer(); + } + setAlignmentProperty(an.stringMatched(1), an.stringMatched(2)); } } else if (annType.equals("GS")) @@ -279,7 +325,8 @@ public class StockholmFile String acc = s.stringMatched(1); String type = s.stringMatched(2); String content = s.stringMatched(3); - + // TODO: store DR in a vector. + // TODO: store AC according to generic file db annotation. Hashtable ann; if (seqAnn.containsKey(acc)) { @@ -299,8 +346,14 @@ public class StockholmFile } else if (annType.equals("GC")) { - System.out.println(annContent); // Generic per-Column annotation, exactly 1 char per column + // always need a label. + if (x.search(annContent)) + { + // parse out and create alignment annotation directly. + AlignmentAnnotation annotation = parseAnnotationRow(x.stringMatched(1), x.stringMatched(2)); + annotations.addElement(annotation); + } } else if (annType.equals("GR")) { @@ -393,8 +446,49 @@ public class StockholmFile } } } + if (treeString.length()>0) + { + if (treeName==null) + { + treeName = "Tree "+(1+getTreeCount()); + } + addNewickTree(treeName, treeString.toString()); + } } + private AlignmentAnnotation parseAnnotationRow(String label, String annots) + { + String 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