X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Fxdb%2Fembl%2FEmblFile.java;h=69870b693e97811322bdfd7cb1b4d31d05f6f21f;hb=02d6aa2077a261d41db77a0158f2b4b779a36398;hp=277423da9516e00dfbd2d2ecb81e7b879474fcd5;hpb=a45774ee31d9f35d4eff46d54d7deab719afb092;p=jalview.git
diff --git a/src/jalview/datamodel/xdb/embl/EmblFile.java b/src/jalview/datamodel/xdb/embl/EmblFile.java
index 277423d..69870b6 100644
--- a/src/jalview/datamodel/xdb/embl/EmblFile.java
+++ b/src/jalview/datamodel/xdb/embl/EmblFile.java
@@ -1,40 +1,55 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
- * Copyright (C) 2011 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.datamodel.xdb.embl;
+import jalview.datamodel.DBRefEntry;
+import jalview.ws.dbsources.Uniprot;
+
import java.io.File;
import java.io.FileReader;
+import java.io.PrintWriter;
import java.io.Reader;
import java.util.Vector;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.xml.Unmarshaller;
+/**
+ * Data model for entries returned from an EMBL query, as marshalled by a Castor
+ * binding file
+ *
+ * For example: http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/embl/x53828/emblxml
+ *
+ * @see embl_mapping.xml
+ */
public class EmblFile
{
- Vector entries;
+ Vector entries;
- Vector errors;
+ Vector errors;
/**
* @return the entries
*/
- public Vector getEntries()
+ public Vector getEntries()
{
return entries;
}
@@ -43,7 +58,7 @@ public class EmblFile
* @param entries
* the entries to set
*/
- public void setEntries(Vector entries)
+ public void setEntries(Vector entries)
{
this.entries = entries;
}
@@ -51,7 +66,7 @@ public class EmblFile
/**
* @return the errors
*/
- public Vector getErrors()
+ public Vector getErrors()
{
return errors;
}
@@ -60,7 +75,7 @@ public class EmblFile
* @param errors
* the errors to set
*/
- public void setErrors(Vector errors)
+ public void setErrors(Vector errors)
{
this.errors = errors;
}
@@ -74,7 +89,9 @@ public class EmblFile
public static EmblFile getEmblFile(File file)
{
if (file == null)
+ {
return null;
+ }
try
{
return EmblFile.getEmblFile(new FileReader(file));
@@ -93,6 +110,7 @@ public class EmblFile
{
// 1. Load the mapping information from the file
Mapping map = new Mapping(record.getClass().getClassLoader());
+
java.net.URL url = record.getClass().getResource("/embl_mapping.xml");
map.loadMapping(url);
@@ -101,18 +119,21 @@ public class EmblFile
try
{
// uncomment to DEBUG EMBLFile reading
- if (((String) jalview.bin.Cache.getDefault(
- jalview.bin.Cache.CASTORLOGLEVEL, "debug"))
- .equalsIgnoreCase("DEBUG"))
+ if (jalview.bin.Cache.getDefault(jalview.bin.Cache.CASTORLOGLEVEL,
+ "debug").equalsIgnoreCase("DEBUG"))
+ {
unmar.setDebug(jalview.bin.Cache.log.isDebugEnabled());
+ }
} catch (Exception e)
{
}
- ;
unmar.setIgnoreExtraElements(true);
+ unmar.setIgnoreExtraAttributes(true);
unmar.setMapping(map);
-
+ unmar.setLogWriter(new PrintWriter(System.out));
record = (EmblFile) unmar.unmarshal(file);
+
+ canonicaliseDbRefs(record);
} catch (Exception e)
{
e.printStackTrace(System.err);
@@ -122,22 +143,44 @@ public class EmblFile
return record;
}
- public static void main(String args[])
+ /**
+ * Change blank version to "0" in any DBRefEntry, to ensure consistent
+ * comparison with other DBRefEntry in Jalview
+ *
+ * @param record
+ * @see Uniprot#getDbVersion
+ */
+ static void canonicaliseDbRefs(EmblFile record)
{
- File mf = null;
- if (args.length == 1)
- {
- mf = new File(args[0]);
- }
- if (!mf.exists())
+ for (EmblEntry entry : record.getEntries())
{
- mf = new File(
- "C:\\Documents and Settings\\JimP\\workspace-3.2\\Jalview Release\\schemas\\embleRecordV1.1.xml");
+ if (entry.getDbRefs() != null)
+ {
+ for (DBRefEntry dbref : entry.getDbRefs())
+ {
+ if ("".equals(dbref.getVersion()))
+ {
+ dbref.setVersion("0");
+ }
+ }
+ }
+
+ if (entry.getFeatures() != null)
+ {
+ for (EmblFeature feature : entry.getFeatures())
+ {
+ if (feature.getDbRefs() != null)
+ {
+ for (DBRefEntry dbref : feature.getDbRefs())
+ {
+ if ("".equals(dbref.getVersion()))
+ {
+ dbref.setVersion("0");
+ }
+ }
+ }
+ }
+ }
}
- EmblFile myfile = EmblFile.getEmblFile(mf);
- if (myfile != null && myfile.entries != null
- && myfile.entries.size() > 0)
- System.out.println(myfile.entries.size() + " Records read. (" + mf
- + ")");
}
}