X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FStockholmFile.java;h=1625241b4b3eb26527edb5483feb6e482d673605;hb=a45774ee31d9f35d4eff46d54d7deab719afb092;hp=d0d84f5c8870d12e71e0da9c6c525f169018c89b;hpb=254b1114ed1ba787fea2d1afdb44cc2957b36efe;p=jalview.git diff --git a/src/jalview/io/StockholmFile.java b/src/jalview/io/StockholmFile.java index d0d84f5..1625241 100644 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@ -1,20 +1,19 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . */ /* * This extension was written by Benjamin Schuster-Boeckler at sanger.ac.uk @@ -30,10 +29,16 @@ import jalview.datamodel.*; // import org.apache.log4j.*; /** - * This class is supposed to parse a Stockholm format file into Jalview + * 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 { @@ -48,6 +53,11 @@ public class StockholmFile extends AlignFile super(inFile, type); } + public StockholmFile(FileParse source) throws IOException + { + super(source); + } + public void initData() { super.initData(); @@ -88,10 +98,10 @@ public class StockholmFile extends AlignFile } // We define some Regexes here that will be used regularily later - rend = new Regex("\\/\\/"); // Find the end of an alignment + rend = new Regex("^\\s*\\/\\/"); // 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 + // id/from/to + 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 +128,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 +141,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 +168,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 +186,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 +195,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 +205,15 @@ 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); @@ -210,10 +225,13 @@ 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)) { @@ -345,8 +363,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")) @@ -365,14 +383,20 @@ 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 @@ -423,11 +447,14 @@ public class StockholmFile extends AlignFile ns = ""; } ns += seq; - content.put(description, seq); + content.put(description, ns); } 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 +491,19 @@ 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; } }