X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fdatamodel%2Fxdb%2Fembl%2FEmblFile.java;h=1dd854a4bd2906ace8441e04724adf322182ffd9;hb=c55e1fa5d2782cc46e515c11a91cf502f37386ab;hp=bc8cbbef230ace38615113e6bbebcdcecf6bc483;hpb=0879ca19b6df4983f82521a479b848526b2d14d4;p=jalview.git
diff --git a/src/jalview/datamodel/xdb/embl/EmblFile.java b/src/jalview/datamodel/xdb/embl/EmblFile.java
index bc8cbbe..1dd854a 100644
--- a/src/jalview/datamodel/xdb/embl/EmblFile.java
+++ b/src/jalview/datamodel/xdb/embl/EmblFile.java
@@ -1,90 +1,202 @@
-package jalview.datamodel.xdb.embl;
-
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.Reader;
-import java.util.Vector;
-
-import org.exolab.castor.mapping.Mapping;
-import org.exolab.castor.xml.Unmarshaller;
-
-public class EmblFile {
- Vector entries;
- Vector errors;
- /**
- * @return the entries
- */
- public Vector getEntries() {
- return entries;
- }
- /**
- * @param entries the entries to set
- */
- public void setEntries(Vector entries) {
- this.entries = entries;
- }
- /**
- * @return the errors
- */
- public Vector getErrors() {
- return errors;
- }
- /**
- * @param errors the errors to set
- */
- public void setErrors(Vector errors) {
- this.errors = errors;
- }
- /**
- * Parse an EmblXML file into an EmblFile object
- * @param file
- * @return parsed EmblXML or null if exceptions were raised
- */
- public static EmblFile getEmblFile(File file)
- {
- if (file==null)
- return null;
- try {
- return EmblFile.getEmblFile(new FileReader(file));
- }
- catch (Exception e) {
- System.err.println("Exception whilst reading EMBLfile from "+file);
- e.printStackTrace(System.err);
- }
- return null;
- }
- public static EmblFile getEmblFile(Reader file) {
- EmblFile record = new EmblFile();
- try
- {
- // 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);
-
- // 2. Unmarshal the data
- Unmarshaller unmar = new Unmarshaller(record);
- try {
- // uncomment to DEBUG EMBLFile reading unmar.setDebug(jalview.bin.Cache.log.isDebugEnabled());
- } catch (Exception e) {};
- unmar.setIgnoreExtraElements(true);
- unmar.setMapping(map);
-
- record = (EmblFile) unmar.unmarshal(file);
- }
- catch (Exception e)
- {
- e.printStackTrace(System.err);
- record=null;
- }
-
-
- return record;
- }
- public static void main(String args[]) {
- EmblFile myfile = EmblFile.getEmblFile(new File("C:\\Documents and Settings\\JimP\\workspace-3.2\\Jalview Release\\schemas\\embleRecord.xml"));
- if (myfile!=null && myfile.entries!=null && myfile.entries.size()>0)
- System.out.println(myfile.entries.size()+" Records read.");
- }
-}
+/*
+ * 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.
+ *
+ * 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 .
+ * 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 errors;
+
+ String text;
+
+ /**
+ * @return the entries
+ */
+ public Vector getEntries()
+ {
+ return entries;
+ }
+
+ /**
+ * @param entries
+ * the entries to set
+ */
+ public void setEntries(Vector entries)
+ {
+ this.entries = entries;
+ }
+
+ /**
+ * @return the errors
+ */
+ public Vector getErrors()
+ {
+ return errors;
+ }
+
+ /**
+ * @param errors
+ * the errors to set
+ */
+ public void setErrors(Vector errors)
+ {
+ this.errors = errors;
+ }
+
+ /**
+ * Parse an EmblXML file into an EmblFile object
+ *
+ * @param file
+ * @return parsed EmblXML or null if exceptions were raised
+ */
+ public static EmblFile getEmblFile(File file)
+ {
+ if (file == null)
+ {
+ return null;
+ }
+ try
+ {
+ return EmblFile.getEmblFile(new FileReader(file));
+ } catch (Exception e)
+ {
+ System.err.println("Exception whilst reading EMBLfile from " + file);
+ e.printStackTrace(System.err);
+ }
+ return null;
+ }
+
+ public static EmblFile getEmblFile(Reader file)
+ {
+ EmblFile record = new EmblFile();
+ try
+ {
+ // 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);
+
+ // 2. Unmarshal the data
+ Unmarshaller unmar = new Unmarshaller(record);
+ try
+ {
+ // uncomment to DEBUG EMBLFile reading
+ 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);
+ record = null;
+ }
+
+ return record;
+ }
+
+ /**
+ * 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)
+ {
+ if (record.getEntries() == null)
+ {
+ return;
+ }
+ for (EmblEntry entry : record.getEntries())
+ {
+ 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");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public String getText()
+ {
+ return text;
+ }
+
+ public void setText(String text)
+ {
+ this.text = text;
+ }
+}