X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FModellerDescription.java;h=e184d749b91f78e67f02dd9d61df3b4a8a8a59d3;hb=94ca0419cc7afa75b3c51917a8beaf46a7c05540;hp=b590a6db26ab4f275e5009fe9799500b6bd85686;hpb=153dd62dc91da13ae732600e6ea55ddbe15eab39;p=jalview.git
diff --git a/src/jalview/io/ModellerDescription.java b/src/jalview/io/ModellerDescription.java
index b590a6d..e184d74 100755
--- a/src/jalview/io/ModellerDescription.java
+++ b/src/jalview/io/ModellerDescription.java
@@ -1,23 +1,32 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* 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.
- *
+ * 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 .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.io;
-import jalview.datamodel.*;
+import jalview.bin.Cache;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.SequenceI;
+
+import java.util.List;
+
+import com.stevesoft.pat.Regex;
public class ModellerDescription
{
@@ -26,13 +35,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;
@@ -57,11 +65,10 @@ 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();
@@ -84,7 +91,7 @@ public class ModellerDescription
resCode(int v)
{
- val = new Integer(v);
+ val = Integer.valueOf(v);
field = val.toString();
}
};
@@ -92,8 +99,7 @@ public class ModellerDescription
private resCode validResidueCode(String field)
{
Integer val = null;
- com.stevesoft.pat.Regex r = new com.stevesoft.pat.Regex(
- "\\s*((([-0-9]+).?)|FIRST|LAST|@)");
+ Regex r = new Regex("\\s*((([-0-9]+).?)|FIRST|LAST|@)");
if (!r.search(field))
{
@@ -104,7 +110,7 @@ public class ModellerDescription
{
value = r.stringMatched(1);
}
- // jalview.bin.Cache.log.debug("from '" + field + "' matched '" + value +
+ // Cache.debug("from '" + field + "' matched '" + value +
// "'");
try
{
@@ -119,7 +125,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)
@@ -137,6 +145,7 @@ public class ModellerDescription
if (i < seqTypes.length)
{
+ st.nextToken(); // skip ':'
// valid seqType for modeller
type = i;
i = 1; // continue parsing fields
@@ -144,24 +153,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
+ {
+ // Cache.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)
@@ -169,7 +189,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);
}
@@ -229,12 +250,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());
}
@@ -250,23 +274,21 @@ public class ModellerDescription
// 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();
- int i, j;
- for (i = 0, j = dbr.length; i < j; i++)
+ List dbr = seq.getDatasetSequence().getDBRefs();
+ for (int i = 0, ni = dbr.size(); i < ni; i++)
{
- if (dbr[i] != null)
+ DBRefEntry dbri = dbr.get(i);
+ if (dbri != null)
{
// JBPNote PDB dbRefEntry needs properties to propagate onto
// ModellerField
// JBPNote Need to get info from the user about whether the sequence
// is the one being modelled, or if it is a template.
- if (dbr[i].getSource()
- .equals(jalview.datamodel.DBRefSource.PDB))
+ if (dbri.getSource().equals(jalview.datamodel.DBRefSource.PDB))
{
- fields.put(Fields[LOCALID], dbr[i].getAccessionId());
+ fields.put(Fields[LOCALID], dbri.getAccessionId());
t = 2;
break;
}
@@ -337,7 +359,7 @@ public class ModellerDescription
{
int start = 0;
resCode val = getStartCode();
- if (val.val != null)
+ if (val != null && val.val != null)
{
return val.val.intValue();
}
@@ -366,7 +388,7 @@ public class ModellerDescription
{
int end = 0;
resCode val = getEndCode();
- if (val.val != null)
+ if (val != null && val.val != null)
{
return val.val.intValue();
}
@@ -384,7 +406,8 @@ public class ModellerDescription
{
if (isModellerFieldset())
{
- if (getStartCode().val != null)
+ resCode rc = getStartCode();
+ if (rc != null && rc.val != null)
{
newSeq.setStart(getStartNum());
}
@@ -392,7 +415,8 @@ public class ModellerDescription
{
newSeq.setStart(1);
}
- if (getEndCode().val != null)
+ rc = getEndCode();
+ if (rc != null && rc.val != null)
{
newSeq.setEnd(getEndNum());
}