2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel.xdb.embl;
23 import jalview.bin.Cache;
24 import jalview.datamodel.DBRefEntry;
25 import jalview.ws.dbsources.Uniprot;
28 import java.io.FileReader;
29 import java.io.PrintWriter;
30 import java.io.Reader;
32 import java.util.Vector;
34 import org.exolab.castor.mapping.Mapping;
35 import org.exolab.castor.xml.Unmarshaller;
38 * Data model for entries returned from an EMBL query, as marshalled by a Castor
41 * For example: http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/embl/x53828/emblxml
43 * @see embl_mapping.xml
47 Vector<EmblEntry> entries;
49 Vector<EmblError> errors;
54 public Vector<EmblEntry> getEntries()
63 public void setEntries(Vector<EmblEntry> entries)
65 this.entries = entries;
71 public Vector<EmblError> getErrors()
80 public void setErrors(Vector<EmblError> errors)
86 * Parse an Embl XML file into an EmblEntry object
89 * @return parsed EmblXML or null if exceptions were raised
91 public static EmblEntry getEmblEntry(File file)
99 return EmblFile.getEntry(new FileReader(file));
100 } catch (Exception e)
102 System.err.println("Exception whilst reading EMBLfile from " + file);
103 e.printStackTrace(System.err);
109 * Reads the XML response from file and unmarshals into a Java object
114 public static EmblEntry getEntry(Reader fileReader)
116 EmblEntry record = new EmblEntry();
119 // 1. Load the mapping information from the file
120 Mapping map = new Mapping(record.getClass().getClassLoader());
122 URL url = record.getClass().getResource("/embl_mapping.xml");
123 map.loadMapping(url);
125 // 2. Unmarshal the data
126 Unmarshaller unmar = new Unmarshaller(record);
129 if (Cache.getDefault(Cache.CASTORLOGLEVEL,
130 "debug").equalsIgnoreCase("DEBUG"))
132 unmar.setDebug(Cache.log.isDebugEnabled());
133 // unmar.setDebug(true);// uncomment to debug unmarshalling
135 } catch (Exception e)
138 unmar.setIgnoreExtraElements(true);
139 unmar.setIgnoreExtraAttributes(true);
140 unmar.setMapping(map);
141 unmar.setLogWriter(new PrintWriter(System.out));
142 record = (EmblEntry) unmar.unmarshal(fileReader);
144 canonicaliseDbRefs(record);
145 } catch (Exception e)
147 e.printStackTrace(System.err);
155 * Change blank version to "0" in any DBRefEntry, to ensure consistent
156 * comparison with other DBRefEntry in Jalview
159 * @see Uniprot#getDbVersion
161 static void canonicaliseDbRefs(EmblEntry entry)
167 // for (EmblEntry entry : record.getEntries())
169 if (entry.getDbRefs() != null)
171 for (DBRefEntry dbref : entry.getDbRefs())
173 if ("".equals(dbref.getVersion()))
175 dbref.setVersion("0");
180 // if (entry.getFeatures() != null)
182 for (EmblFeature feature : entry.getFeatures())
184 if (feature.getDbRefs() != null)
186 for (DBRefEntry dbref : feature.getDbRefs())
188 if ("".equals(dbref.getVersion()))
190 dbref.setVersion("0");