1 package jalview.datamodel.xdb.embl;
3 import jalview.datamodel.DBRefEntry;
4 import jalview.datamodel.DBRefSource;
5 import jalview.datamodel.FeatureProperties;
6 import jalview.datamodel.Sequence;
7 import jalview.datamodel.SequenceFeature;
8 import jalview.datamodel.SequenceI;
10 import java.util.Enumeration;
11 import java.util.Hashtable;
12 import java.util.Iterator;
13 import java.util.Vector;
15 public class EmblEntry
39 EmblSequence sequence;
42 * @return the accession
44 public String getAccession()
51 * the accession to set
53 public void setAccession(String accession)
55 this.accession = accession;
61 public Vector getDbRefs()
70 public void setDbRefs(Vector dbRefs)
78 public String getDesc()
87 public void setDesc(String desc)
93 * @return the features
95 public Vector getFeatures()
102 * the features to set
104 public void setFeatures(Vector features)
106 this.features = features;
110 * @return the keywords
112 public Vector getKeywords()
119 * the keywords to set
121 public void setKeywords(Vector keywords)
123 this.keywords = keywords;
127 * @return the lastUpdated
129 public String getLastUpdated()
136 * the lastUpdated to set
138 public void setLastUpdated(String lastUpdated)
140 this.lastUpdated = lastUpdated;
146 public Vector getRefs()
155 public void setRefs(Vector refs)
161 * @return the releaseCreated
163 public String getRCreated()
169 * @param releaseCreated
170 * the releaseCreated to set
172 public void setRcreated(String releaseCreated)
174 this.rCreated = releaseCreated;
178 * @return the releaseLastUpdated
180 public String getRLastUpdated()
186 * @param releaseLastUpdated
187 * the releaseLastUpdated to set
189 public void setRLastUpdated(String releaseLastUpdated)
191 this.rLastUpdated = releaseLastUpdated;
195 * @return the sequence
197 public EmblSequence getSequence()
204 * the sequence to set
206 public void setSequence(EmblSequence sequence)
208 this.sequence = sequence;
212 * @return the taxDivision
214 public String getTaxDivision()
221 * the taxDivision to set
223 public void setTaxDivision(String taxDivision)
225 this.taxDivision = taxDivision;
229 * @return the version
231 public String getVersion()
240 public void setVersion(String version)
242 this.version = version;
246 * EMBL Feature support is limited. The text below is included for the benefit
247 * of any developer working on improving EMBL feature import in Jalview.
248 * Extract from EMBL feature specification see
249 * http://www.embl-ebi.ac.uk/embl/Documentation/FT_definitions/feature_table.html
250 * 3.5 Location 3.5.1 Purpose
252 * The location indicates the region of the presented sequence which
253 * corresponds to a feature.
255 * 3.5.2 Format and conventions The location contains at least one sequence
256 * location descriptor and may contain one or more operators with one or more
257 * sequence location descriptors. Base numbers refer to the numbering in the
258 * entry. This numbering designates the first base (5' end) of the presented
259 * sequence as base 1. Base locations beyond the range of the presented
260 * sequence may not be used in location descriptors, the only exception being
261 * location in a remote entry (see 3.5.2.1, e).
263 * Location operators and descriptors are discussed in more detail below.
265 * 3.5.2.1 Location descriptors
267 * The location descriptor can be one of the following: (a) a single base
268 * number (b) a site between two indicated adjoining bases (c) a single base
269 * chosen from within a specified range of bases (not allowed for new entries)
270 * (d) the base numbers delimiting a sequence span (e) a remote entry
271 * identifier followed by a local location descriptor (i.e., a-d)
273 * A site between two adjoining nucleotides, such as endonucleolytic cleavage
274 * site, is indicated by listing the two points separated by a carat (^). The
275 * permitted formats for this descriptor are n^n+1 (for example 55^56), or,
276 * for circular molecules, n^1, where "n" is the full length of the molecule,
277 * ie 1000^1 for circular molecule with length 1000.
279 * A single base chosen from a range of bases is indicated by the first base
280 * number and the last base number of the range separated by a single period
281 * (e.g., '12.21' indicates a single base taken from between the indicated
282 * points). From October 2006 the usage of this descriptor is restricted : it
283 * is illegal to use "a single base from a range" (c) either on its own or in
284 * combination with the "sequence span" (d) descriptor for newly created
285 * entries. The existing entries where such descriptors exist are going to be
288 * Sequence spans are indicated by the starting base number and the ending
289 * base number separated by two periods (e.g., '34..456'). The '<' and '>'
290 * symbols may be used with the starting and ending base numbers to indicate
291 * that an end point is beyond the specified base number. The starting and
292 * ending base positions can be represented as distinct base numbers
293 * ('34..456') or a site between two indicated adjoining bases.
295 * A location in a remote entry (not the entry to which the feature table
296 * belongs) can be specified by giving the accession-number and sequence
297 * version of the remote entry, followed by a colon ":", followed by a
298 * location descriptor which applies to that entry's sequence (i.e.
299 * J12345.1:1..15, see also examples below)
303 * The location operator is a prefix that specifies what must be done to the
304 * indicated sequence to find or construct the location corresponding to the
305 * feature. A list of operators is given below with their definitions and most
308 * complement(location) Find the complement of the presented sequence in the
309 * span specified by " location" (i.e., read the complement of the presented
310 * strand in its 5'-to-3' direction)
312 * join(location,location, ... location) The indicated elements should be
313 * joined (placed end-to-end) to form one contiguous sequence
315 * order(location,location, ... location) The elements can be found in the
316 * specified order (5' to 3' direction), but nothing is implied about the
317 * reasonableness about joining them
319 * Note : location operator "complement" can be used in combination with
320 * either " join" or "order" within the same location; combinations of "join"
321 * and "order" within the same location (nested operators) are illegal.
325 * 3.5.3 Location examples
327 * The following is a list of common location descriptors with their meanings:
329 * Location Description
331 * 467 Points to a single base in the presented sequence
333 * 340..565 Points to a continuous range of bases bounded by and including the
334 * starting and ending bases
336 * <345..500 Indicates that the exact lower boundary point of a feature is
337 * unknown. The location begins at some base previous to the first base
338 * specified (which need not be contained in the presented sequence) and
339 * continues to and includes the ending base
341 * <1..888 The feature starts before the first sequenced base and continues to
342 * and includes base 888
344 * 1..>888 The feature starts at the first sequenced base and continues beyond
347 * 102.110 Indicates that the exact location is unknown but that it is one of
348 * the bases between bases 102 and 110, inclusive
350 * 123^124 Points to a site between bases 123 and 124
352 * join(12..78,134..202) Regions 12 to 78 and 134 to 202 should be joined to
353 * form one contiguous sequence
356 * complement(34..126) Start at the base complementary to 126 and finish at
357 * the base complementary to base 34 (the feature is on the strand
358 * complementary to the presented strand)
361 * complement(join(2691..4571,4918..5163)) Joins regions 2691 to 4571 and 4918
362 * to 5163, then complements the joined segments (the feature is on the strand
363 * complementary to the presented strand)
365 * join(complement(4918..5163),complement(2691..4571)) Complements regions
366 * 4918 to 5163 and 2691 to 4571, then joins the complemented segments (the
367 * feature is on the strand complementary to the presented strand)
369 * J00194.1:100..202 Points to bases 100 to 202, inclusive, in the entry (in
370 * this database) with primary accession number 'J00194'
372 * join(1..100,J00194.1:100..202) Joins region 1..100 of the existing entry
373 * with the region 100..202 of remote entry J00194
377 * Recover annotated sequences from EMBL file
380 * don't return nucleic acid sequences
384 * don't return any translated protein sequences marked in features
385 * @return dataset sequences with DBRefs and features - DNA always comes first
387 public jalview.datamodel.SequenceI[] getSequences(boolean noNa,
388 boolean noPeptide, String sourceDb)
390 Vector seqs = new Vector();
394 dna = new Sequence(sourceDb + "|" + accession, sequence.getSequence());
395 dna.setDescription(desc);
396 dna.addDBRef(new DBRefEntry(sourceDb, version, accession));
397 // TODO: add mapping for parentAccession attribute
398 // TODO: transform EMBL Database refs to canonical form
400 for (Iterator i = dbRefs.iterator(); i.hasNext(); dna
401 .addDBRef((DBRefEntry) i.next()))
406 for (Iterator i = features.iterator(); i.hasNext();)
408 boolean nextFeature=false;
409 EmblFeature feature = (EmblFeature) i.next();
412 if (feature.dbRefs != null && feature.dbRefs.size() > 0)
414 for (Iterator dbr = feature.dbRefs.iterator(); dbr.hasNext(); dna
415 .addDBRef((DBRefEntry) dbr.next()))
419 if (FeatureProperties.isCodingFeature(DBRefSource.EMBL, "CDS"))
421 // extract coding region(s)
422 jalview.datamodel.Mapping map = null;
424 if (feature.locations != null && feature.locations.size() > 0)
426 for (Enumeration locs = feature.locations.elements(); locs
429 EmblFeatureLocations loc = (EmblFeatureLocations) locs
431 int[] se = loc.getElementRanges(accession);
438 int[] t = new int[exon.length + se.length];
439 System.arraycopy(exon, 0, t, 0, exon.length);
440 System.arraycopy(se, 0, t, exon.length, se.length);
446 String prname = new String();
448 Hashtable vals = new Hashtable();
451 if (feature.getQualifiers() != null
452 && feature.getQualifiers().size() > 0)
454 for (Iterator quals = feature.getQualifiers().iterator(); quals
457 Qualifier q = (Qualifier) quals.next();
458 if (q.getName().equals("translation"))
460 prseq = q.getValues()[0];
462 else if (q.getName().equals("protein_id"))
464 prid = q.getValues()[0];
466 else if (q.getName().equals("codon_start"))
468 prstart = Integer.parseInt(q.getValues()[0]);
470 else if (q.getName().equals("product"))
472 prname = q.getValues()[0];
476 // throw anything else into the additional properties hash
477 vals.put(q.getName(), q.getValues().toString());
481 Sequence product = null;
482 if (prseq != null && prname != null && prid != null)
487 product = new Sequence(sourceDb + "|" + "EMBLCDS|" + prid
488 + "|" + prname, prseq, prstart, prstart
489 + prseq.length() - 1);
490 product.setDescription("Protein Product from " + sourceDb);
493 // we have everything - create the mapping and perhaps the protein
495 map = new jalview.datamodel.Mapping(product, exon, new int[]
496 { prstart, prstart + prseq.length() - 1 }, 3, 1);
497 // add cds feature to dna seq - this may include the stop codon
498 for (int xint = 0; xint < exon.length; xint += 2)
500 SequenceFeature sf = new SequenceFeature();
501 sf.setBegin(exon[xint]);
502 sf.setEnd(exon[xint + 1]);
503 sf.setType(feature.getName());
504 sf.setFeatureGroup(jalview.datamodel.DBRefSource.EMBL);
505 sf.setDescription("Exon " + (1 + xint) + " for protein '"
506 + prname + "' EMBLCDS:" + prid);
507 sf.setValue(FeatureProperties.EXONPOS, new Integer(1+xint));
508 sf.setValue(FeatureProperties.EXONPRODUCT, prname);
509 if (vals != null && vals.size() > 0)
511 Enumeration kv = vals.elements();
512 while (kv.hasMoreElements())
514 Object key = kv.nextElement();
516 sf.setValue(key.toString(), vals.get(key));
519 dna.addSequenceFeature(sf);
522 // add dbRefs to sequence
523 if (feature.dbRefs != null && feature.dbRefs.size() > 0)
525 for (Iterator dbr = feature.dbRefs.iterator(); dbr.hasNext();)
527 DBRefEntry ref = (DBRefEntry) dbr.next();
528 ref.setSource(jalview.util.DBRefUtils.getCanonicalName(ref
530 // Hard code the kind of protein product accessions that EMBL cite
531 if (ref.getSource().equals(
532 jalview.datamodel.DBRefSource.UNIPROT))
538 DBRefEntry pref = new DBRefEntry(ref.getSource(), ref
539 .getVersion(), ref.getAccessionId());
540 pref.setMap(null); // reference is direct
549 // General feature type.
552 if (feature.dbRefs != null && feature.dbRefs.size() > 0)
554 for (Iterator dbr = feature.dbRefs.iterator(); dbr.hasNext(); dna
555 .addDBRef((DBRefEntry) dbr.next()))
561 } catch (Exception e)
563 System.err.println("EMBL Record Features parsing error!");
564 System.err.println("Please report the following to help@jalview.org :");
565 System.err.println("EMBL Record "+accession);
566 System.err.println("Resulted in exception: "+e.getMessage());
567 e.printStackTrace(System.err);
569 if (!noNa && dna!=null)
573 SequenceI[] sqs = new SequenceI[seqs.size()];
574 for (int i = 0, j = seqs.size(); i < j; i++)
576 sqs[i] = (SequenceI) seqs.elementAt(i);