X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FStockholmFile.java;h=6b60cd528e264978d6970521fea9b525e93a2695;hb=b78f02f944e0cf69ba6cfe14a165d6ad210e45dd;hp=b407463480ad135d3435552b0f765ae8b3a78c92;hpb=d46053ba40ebbaf5a8b8867cdc770673228b4721;p=jalview.git diff --git a/src/jalview/io/StockholmFile.java b/src/jalview/io/StockholmFile.java index b407463..6b60cd5 100644 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) - * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle * * This file is part of Jalview. * @@ -25,6 +25,7 @@ import java.util.*; import com.stevesoft.pat.*; import jalview.datamodel.*; +import jalview.analysis.Rna; // import org.apache.log4j.*; @@ -82,6 +83,9 @@ public class StockholmFile extends AlignFile Hashtable seqs = new Hashtable(); Regex p, r, rend, s, x; + // Temporary line for processing RNA annotation + // String RNAannot = ""; + // ------------------ Parsing File ---------------------- // First, we have to check that this file has STOCKHOLM format, i.e. the // first line must match @@ -105,11 +109,20 @@ public class StockholmFile extends AlignFile r = new Regex("#=(G[FSRC]?)\\s+(.*)"); // Finds any annotation line x = new Regex("(\\S+)\\s+(\\S+)"); // split id from sequence + // Convert all bracket types to parentheses (necessary for passing to VARNA) + Regex openparen = new Regex("(<|\\[)", "("); + Regex closeparen = new Regex("(>|\\])", ")"); + + // Detect if file is RNA by looking for bracket types + Regex detectbrackets = new Regex("(<|>|\\[|\\]|\\(|\\))"); + rend.optimize(); p.optimize(); s.optimize(); r.optimize(); x.optimize(); + openparen.optimize(); + closeparen.optimize(); while ((line = nextLine()) != null) { @@ -136,12 +149,16 @@ public class StockholmFile extends AlignFile int start = 1; int end = -1; String sid = acc; - // Retrieve hash of annotations for this accession + /* + * Retrieve hash of annotations for this accession + * Associate Annotation with accession + */ Hashtable accAnnotations = null; if (seqAnn != null && seqAnn.containsKey(acc)) { accAnnotations = (Hashtable) seqAnn.remove(acc); + //TODO: add structures to sequence } // Split accession in id and from/to @@ -171,7 +188,19 @@ public class StockholmFile extends AlignFile jalview.util.DBRefUtils.parseToDbRef(seqO, src, "0", acn); // seqO.addDBRef(dbref); } + } + if (accAnnotations != null && accAnnotations.containsKey("SS")) + { + Vector v = (Vector) accAnnotations.get("SS"); + + for (int i = 0; i < v.size(); i++) + { + AlignmentAnnotation an = (AlignmentAnnotation) v.elementAt(i); + seqO.addAlignmentAnnotation(an); + //annotations.add(an); + } } + Hashtable features = null; // We need to adjust the positions of all features to account for gaps try @@ -363,8 +392,8 @@ public class StockholmFile extends AlignFile if (x.search(annContent)) { // parse out and create alignment annotation directly. - parseAnnotationRow(annotations, x.stringMatched(1), x - .stringMatched(2)); + parseAnnotationRow(annotations, x.stringMatched(1), + x.stringMatched(2)); } } else if (annType.equals("GR")) @@ -413,7 +442,7 @@ public class StockholmFile extends AlignFile ann = new Hashtable(); seqAnn.put(acc, ann); } - + //TODO test structure, call parseAnnotationRow with vector from hashtable for specific sequence Hashtable features; // Get an object with all the content for an annotation if (ann.containsKey("features")) @@ -447,7 +476,25 @@ public class StockholmFile extends AlignFile ns = ""; } ns += seq; - content.put(description, seq); + content.put(description, ns); + + if(type.equals("SS")){ + 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 { @@ -474,9 +521,22 @@ public class StockholmFile extends AlignFile } } - private AlignmentAnnotation parseAnnotationRow(Vector annotation, + 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.indexOf("_cons") == label.length() - 5) ? label .substring(0, label.length() - 5) : label; boolean ss = false; @@ -495,8 +555,17 @@ public class StockholmFile extends AlignFile // be written out if (ss) { - ann.secondaryStructure = jalview.schemes.ResidueProperties - .getDssp3state(pos).charAt(0); + 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; // " "; @@ -531,6 +600,7 @@ public class StockholmFile extends AlignFile annot.annotations.length); System.arraycopy(els, 0, anns, annot.annotations.length, els.length); annot.annotations = anns; + //System.out.println("else: "); } return annot; } @@ -570,7 +640,7 @@ public class StockholmFile extends AlignFile } } - private String id2type(String id) + protected static String id2type(String id) { if (typeIds.containsKey(id)) { @@ -580,4 +650,38 @@ public class StockholmFile extends AlignFile + id); return id; } + /** + * //ssline is complete secondary structure line private AlignmentAnnotation + * addHelices(Vector annotation, String label, String ssline) { + * + * // decide on secondary structure or not. Annotation[] els = new + * Annotation[ssline.length()]; for (int i = 0; i < ssline.length(); i++) { + * String pos = ssline.substring(i, i + 1); Annotation ann; ann = new + * Annotation(pos, "", ' ', 0f); // 0f is 'valid' null - will not + * + * ann.secondaryStructure = + * jalview.schemes.ResidueProperties.getRNAssState(pos).charAt(0); + * + * ann.displayCharacter = "x" + ann.displayCharacter; + * + * System.out.println(ann.displayCharacter); + * + * els[i] = ann; } AlignmentAnnotation helicesAnnot = null; Enumeration e = + * annotation.elements(); while (e.hasMoreElements()) { helicesAnnot = + * (AlignmentAnnotation) e.nextElement(); if (helicesAnnot.label.equals(type)) + * break; helicesAnnot = null; } if (helicesAnnot == null) { helicesAnnot = + * new AlignmentAnnotation(type, type, els); + * annotation.addElement(helicesAnnot); } else { Annotation[] anns = new + * Annotation[helicesAnnot.annotations.length + els.length]; + * System.arraycopy(helicesAnnot.annotations, 0, anns, 0, + * helicesAnnot.annotations.length); System.arraycopy(els, 0, anns, + * helicesAnnot.annotations.length, els.length); helicesAnnot.annotations = + * anns; } + * + * helicesAnnot.features = Rna.GetBasePairs(ssline); + * Rna.HelixMap(helicesAnnot.features); + * + * + * return helicesAnnot; } + */ }