X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FModellerDescription.java;h=1ab95451a2be99a890c622dce470cfe0dfc0789b;hb=6684899d56d5bfb61faf814560010d7cb7b8bd95;hp=e4483a5fd8b64888b79885947df6996cdcadafa3;hpb=506d60f0e188723ddc91c26824b41ac7034df3fe;p=jalview.git diff --git a/src/jalview/io/ModellerDescription.java b/src/jalview/io/ModellerDescription.java index e4483a5..1ab9545 100755 --- a/src/jalview/io/ModellerDescription.java +++ b/src/jalview/io/ModellerDescription.java @@ -1,24 +1,26 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * - * 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 file is part of Jalview. * - * 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. + * 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.io; -import jalview.datamodel.*; +import jalview.datamodel.SequenceI; public class ModellerDescription { @@ -27,13 +29,12 @@ public class ModellerDescription * single line, and sequence start/end and other properties. See PIRFile IO * for its use. */ - final String[] seqTypes = - { "sequence", "structure", "structureX", "structureN" }; + final String[] seqTypes = { "sequence", "structure", "structureX", + "structureN" }; - final String[] Fields = - { "objectType", "objectId", "startField", "startCode", "endField", - "endCode", "description1", "description2", "resolutionField", - "tailField" }; + final String[] Fields = { "objectType", "objectId", "startField", + "startCode", "endField", "endCode", "description1", "description2", + "resolutionField", "tailField" }; final int TYPE = 0; @@ -58,11 +59,9 @@ public class ModellerDescription /** * 0 is free text or empty 1 is something that parses to an integer, or \@ */ - final int Types[] = - { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0 }; + final int Types[] = { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0 }; - final char Padding[] = - { ' ', ' ', ' ', '.', ' ', '.', '.', '.', '.', '.' }; + final char Padding[] = { ' ', ' ', ' ', '.', ' ', '.', '.', '.', '.', '.' }; java.util.Hashtable fields = new java.util.Hashtable(); @@ -120,7 +119,9 @@ public class ModellerDescription private java.util.Hashtable parseDescription(String desc) { java.util.Hashtable fields = new java.util.Hashtable(); - java.util.StringTokenizer st = new java.util.StringTokenizer(desc, ":"); + java.util.StringTokenizer st = new java.util.StringTokenizer(desc, ":", + true); + String field; int type = -1; if (st.countTokens() > 0) @@ -138,6 +139,7 @@ public class ModellerDescription if (i < seqTypes.length) { + st.nextToken(); // skip ':' // valid seqType for modeller type = i; i = 1; // continue parsing fields @@ -145,24 +147,35 @@ public class ModellerDescription { if ((field = st.nextToken(":")) != null) { - // validate residue field value - if (Types[i] == 1) + if (!field.equals(":")) { - resCode val = validResidueCode(field); - if (val != null) + // validate residue field value + if (Types[i] == 1) { - fields.put(new String(Fields[i] + "num"), val); + resCode val = validResidueCode(field); + if (val != null) + { + fields.put(new String(Fields[i] + "num"), val); + } + else + { + // jalview.bin.Cache.log.debug( + // "Ignoring non-Modeller description: invalid integer-like + // field '" + field + "'"); + type = -1; /* invalid field! - throw the FieldSet away */ + } + ; } - else + fields.put(Fields[i++], field); + if (st.hasMoreTokens()) { - // jalview.bin.Cache.log.debug( - // "Ignoring non-Modeller description: invalid integer-like - // field '" + field + "'"); - type = -1; /* invalid field! - throw the FieldSet away */ + st.nextToken(); // skip token sep. } - ; } - fields.put(Fields[i++], field); + else + { + i++; + } } } if (i == TAIL) @@ -170,7 +183,8 @@ public class ModellerDescription // slurp remaining fields while (st.hasMoreTokens()) { - field += ":" + st.nextToken(":"); + String tl = st.nextToken(":"); + field += tl.equals(":") ? tl : (":" + tl); } fields.put(Fields[TAIL], field); } @@ -216,7 +230,7 @@ public class ModellerDescription * make a possibly updated modeller field line for the sequence object * * @param seq - * SequenceI + * SequenceI */ ModellerDescription(SequenceI seq) { @@ -230,12 +244,15 @@ public class ModellerDescription { // Set start and end before we update the type (in the case of a // synthesized field set) - if (getStartNum() != seq.getStart() && getStartCode().val != null) + if (getStartCode() == null + || (getStartNum() != seq.getStart() && getStartCode().val != null)) { + // unset or user updated sequence start position setStartCode(seq.getStart()); } - if (getEndNum() != seq.getEnd() && getStartCode().val != null) + if (getEndCode() == null + || (getEndNum() != seq.getEnd() && getStartCode() != null && getStartCode().val != null)) { setEndCode(seq.getEnd()); } @@ -246,15 +263,15 @@ public class ModellerDescription setStartCode(seq.getStart()); setEndCode(seq.getEnd()); fields.put(Fields[LOCALID], seq.getName()); // this may be overwritten - // below... + // below... // type - decide based on evidence of PDB database references - this also // sets the local reference field int t = 0; // sequence if (seq.getDatasetSequence() != null - && seq.getDatasetSequence().getDBRef() != null) + && seq.getDatasetSequence().getDBRefs() != null) { jalview.datamodel.DBRefEntry[] dbr = seq.getDatasetSequence() - .getDBRef(); + .getDBRefs(); int i, j; for (i = 0, j = dbr.length; i < j; i++) { @@ -338,7 +355,7 @@ public class ModellerDescription { int start = 0; resCode val = getStartCode(); - if (val.val != null) + if (val != null && val.val != null) { return val.val.intValue(); } @@ -367,7 +384,7 @@ public class ModellerDescription { int end = 0; resCode val = getEndCode(); - if (val.val != null) + if (val != null && val.val != null) { return val.val.intValue(); } @@ -378,14 +395,15 @@ public class ModellerDescription * returns true if sequence object was modifed with a valid modellerField set * * @param newSeq - * SequenceI + * SequenceI * @return boolean */ boolean updateSequenceI(SequenceI newSeq) { if (isModellerFieldset()) { - if (getStartCode().val != null) + resCode rc = getStartCode(); + if (rc != null && rc.val != null) { newSeq.setStart(getStartNum()); } @@ -393,7 +411,8 @@ public class ModellerDescription { newSeq.setStart(1); } - if (getEndCode().val != null) + rc = getEndCode(); + if (rc != null && rc.val != null) { newSeq.setEnd(getEndNum()); }