X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Fxdb%2Fembl%2FEmblEntry.java;h=9c9447ef660c6ae1870440aba1279a6488d90cbd;hb=fddf3084802b37e5cee17829e32692a4aac3e60d;hp=3f890ba7293f7eabd9a11872e2d830d39c54c103;hpb=d62b90cb6effb7b380e5f7d590691dd884b024cf;p=jalview.git diff --git a/src/jalview/datamodel/xdb/embl/EmblEntry.java b/src/jalview/datamodel/xdb/embl/EmblEntry.java index 3f890ba..9c9447e 100644 --- a/src/jalview/datamodel/xdb/embl/EmblEntry.java +++ b/src/jalview/datamodel/xdb/embl/EmblEntry.java @@ -20,11 +20,6 @@ */ package jalview.datamodel.xdb.embl; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Vector; - import jalview.datamodel.DBRefEntry; import jalview.datamodel.DBRefSource; import jalview.datamodel.FeatureProperties; @@ -33,6 +28,10 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; +import java.util.Hashtable; +import java.util.Map.Entry; +import java.util.Vector; + /** * Data model for one entry returned from an EMBL query, as marshalled by a * Castor binding file @@ -397,7 +396,7 @@ public class EmblEntry boolean noPeptide, String sourceDb) { // TODO: ensure emblEntry.getSequences behaves correctly for returning all // cases of noNa and noPeptide - Vector seqs = new Vector(); + Vector seqs = new Vector(); Sequence dna = null; if (!noNa) { @@ -415,26 +414,23 @@ public class EmblEntry // TODO: transform EMBL Database refs to canonical form if (dbRefs != null) { - for (Iterator i = dbRefs.iterator(); i.hasNext(); dna - .addDBRef((DBRefEntry) i.next())) + for (DBRefEntry dbref : dbRefs) { - ; + dna.addDBRef(dbref); } } } try { - for (Iterator i = features.iterator(); i.hasNext();) + for (EmblFeature feature: features) { - EmblFeature feature = (EmblFeature) i.next(); if (!noNa) { - if (feature.dbRefs != null && feature.dbRefs.size() > 0) + if (feature.dbRefs != null) { - for (Iterator dbr = feature.dbRefs.iterator(); dbr.hasNext(); dna - .addDBRef((DBRefEntry) dbr.next())) + for (DBRefEntry dbref : feature.dbRefs) { - ; + dna.addDBRef(dbref); } } } @@ -445,14 +441,14 @@ public class EmblEntry else { // General feature type. + // TODO this is just duplicated code ?? if (!noNa) { - if (feature.dbRefs != null && feature.dbRefs.size() > 0) + if (feature.dbRefs != null) { - for (Iterator dbr = feature.dbRefs.iterator(); dbr.hasNext(); dna - .addDBRef((DBRefEntry) dbr.next())) + for (DBRefEntry dbref : feature.dbRefs) { - ; + dna.addDBRef(dbref); } } } @@ -474,7 +470,7 @@ public class EmblEntry SequenceI[] sqs = new SequenceI[seqs.size()]; for (int i = 0, j = seqs.size(); i < j; i++) { - sqs[i] = (SequenceI) seqs.elementAt(i); + sqs[i] = seqs.elementAt(i); seqs.set(i, null); } return sqs; @@ -496,19 +492,16 @@ public class EmblEntry * flag for generation of Peptide sequence objects */ private void parseCodingFeature(EmblFeature feature, String sourceDb, - Vector seqs, Sequence dna, boolean noPeptide) + Vector seqs, Sequence dna, boolean noPeptide) { boolean isEmblCdna = sourceDb.equals(DBRefSource.EMBLCDS); // extract coding region(s) jalview.datamodel.Mapping map = null; int[] exon = null; - if (feature.locations != null && feature.locations.size() > 0) + if (feature.locations != null) { - for (Enumeration locs = feature.locations.elements(); locs - .hasMoreElements();) + for (EmblFeatureLocations loc : feature.locations) { - EmblFeatureLocations loc = (EmblFeatureLocations) locs - .nextElement(); int[] se = loc.getElementRanges(accession); if (exon == null) { @@ -526,19 +519,17 @@ public class EmblEntry String prseq = null; String prname = new String(); String prid = null; - Hashtable vals = new Hashtable(); + Hashtable vals = new Hashtable(); int prstart = 1; // get qualifiers - if (feature.getQualifiers() != null - && feature.getQualifiers().size() > 0) + if (feature.getQualifiers() != null) { - for (Iterator quals = feature.getQualifiers().iterator(); quals - .hasNext();) + for (Qualifier q : feature.getQualifiers()) { - Qualifier q = (Qualifier) quals.next(); - if (q.getName().equals("translation")) + String qname = q.getName(); + if (qname.equals("translation")) { - StringBuffer prsq = new StringBuffer(q.getValues()[0]); + StringBuilder prsq = new StringBuilder(q.getValues()[0]); int p = prsq.indexOf(" "); while (p > -1) { @@ -549,15 +540,15 @@ public class EmblEntry prsq = null; } - else if (q.getName().equals("protein_id")) + else if (qname.equals("protein_id")) { prid = q.getValues()[0]; } - else if (q.getName().equals("codon_start")) + else if (qname.equals("codon_start")) { prstart = Integer.parseInt(q.getValues()[0]); } - else if (q.getName().equals("product")) + else if (qname.equals("product")) { prname = q.getValues()[0]; } @@ -565,7 +556,7 @@ public class EmblEntry { // throw anything else into the additional properties hash String[] s = q.getValues(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (s != null) { for (int i = 0; i < s.length; i++) @@ -574,15 +565,15 @@ public class EmblEntry sb.append("\n"); } } - vals.put(q.getName(), sb.toString()); + vals.put(qname, sb.toString()); } } } Sequence product = null; DBRefEntry protEMBLCDS = null; exon = adjustForPrStart(prstart, exon); - boolean noProteinDbref=true; - + boolean noProteinDbref = true; + if (prseq != null && prname != null && prid != null) { // extract proteins. @@ -663,9 +654,9 @@ public class EmblEntry protEMBLCDS = new DBRefEntry(pcdnaref); protEMBLCDS.setSource(DBRefSource.EMBLCDSProduct); product.addDBRef(protEMBLCDS); - - } - + + } + } } // add cds feature to dna seq - this may include the stop codon @@ -676,31 +667,25 @@ public class EmblEntry sf.setEnd(exon[xint + 1]); sf.setType(feature.getName()); sf.setFeatureGroup(sourceDb); - sf.setDescription("Exon " + (1 + xint / 2) - + " for protein '" + prname + "' EMBLCDS:" + prid); + sf.setDescription("Exon " + (1 + xint / 2) + " for protein '" + + prname + "' EMBLCDS:" + prid); sf.setValue(FeatureProperties.EXONPOS, new Integer(1 + xint)); sf.setValue(FeatureProperties.EXONPRODUCT, prname); - if (vals != null && vals.size() > 0) + if (vals != null) { - Enumeration kv = vals.keys(); - while (kv.hasMoreElements()) + for (Entry val : vals.entrySet()) { - Object key = kv.nextElement(); - if (key != null) - { - sf.setValue(key.toString(), vals.get(key)); - } + sf.setValue(val.getKey(), val.getValue()); } } dna.addSequenceFeature(sf); } } // add dbRefs to sequence - if (feature.dbRefs != null && feature.dbRefs.size() > 0) + if (feature.dbRefs != null) { - for (Iterator dbr = feature.dbRefs.iterator(); dbr.hasNext();) + for (DBRefEntry ref : feature.dbRefs) { - DBRefEntry ref = (DBRefEntry) dbr.next(); ref.setSource(jalview.util.DBRefUtils.getCanonicalName(ref .getSource())); // Hard code the kind of protein product accessions that EMBL cite @@ -755,7 +740,7 @@ public class EmblEntry .setMap(new Mapping(product, map.getMap().getInverse())); } product.addDBRef(protEMBLCDS); - + // Add converse mapping reference if (map != null) {