X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fdbsources%2FUniprot.java;h=3a6fed26a5058b2f01db4d40cb4985704a363fd9;hb=d043ce47fc710d3eb2629ba926a8a7417bd67d8c;hp=077587009be133e9c84b928121a47184a1e26110;hpb=49db0dff1da16c3355b43a41498c1fc93ef47e91;p=jalview.git diff --git a/src/jalview/ws/dbsources/Uniprot.java b/src/jalview/ws/dbsources/Uniprot.java index 0775870..3a6fed2 100644 --- a/src/jalview/ws/dbsources/Uniprot.java +++ b/src/jalview/ws/dbsources/Uniprot.java @@ -31,6 +31,7 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.schemes.ResidueProperties; +import jalview.util.Platform; import jalview.util.StringUtils; import jalview.ws.seqfetcher.DbSourceProxyImpl; import jalview.xml.binding.uniprot.DbReferenceType; @@ -149,27 +150,31 @@ public class Uniprot extends DbSourceProxyImpl "(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", ""); AlignmentI al = null; - String downloadstring = getDomain() + "/uniprot/" + queries - + ".xml"; + String downloadstring = getDomain() + "/uniprot/" + queries + ".xml"; URL url = new URL(downloadstring); - HttpURLConnection urlconn = (HttpURLConnection)url.openConnection(); + HttpURLConnection urlconn = (HttpURLConnection) url.openConnection(); // anything other than 200 means we don't have data - // TODO: JAL-3882 reuse the EnsemblRestClient's fair + // TODO: JAL-3882 reuse the EnsemblRestClient's fair // use/backoff logic to retry when the server tells us to go away if (urlconn.getResponseCode() == 200) { - List seqs = new ArrayList<>(); - for (Entry entry : entries) + InputStream istr = urlconn.getInputStream(); + List entries = getUniprotEntries(istr); + if (entries != null) { - seqs.add(uniprotEntryToSequence(entry)); + List seqs = new ArrayList<>(); + for (Entry entry : entries) + { + seqs.add(uniprotEntryToSequence(entry)); + } + al = new Alignment(seqs.toArray(new SequenceI[seqs.size()])); } - al = new Alignment(seqs.toArray(new SequenceI[seqs.size()])); } stopQuery(); return al; - + } catch (Exception e) { throw (e); @@ -194,8 +199,7 @@ public class Uniprot extends DbSourceProxyImpl String seqString = entry.getSequence().getValue().replaceAll("\\s*", ""); - SequenceI sequence = new Sequence(id, - seqString); + SequenceI sequence = new Sequence(id, seqString); sequence.setDescription(getUniprotEntryDescription(entry)); /* @@ -203,12 +207,12 @@ public class Uniprot extends DbSourceProxyImpl */ final String dbVersion = getDbVersion(); List dbRefs = new ArrayList<>(); - boolean canonical=true; + boolean canonical = true; for (String accessionId : entry.getAccession()) { DBRefEntry dbRef = new DBRefEntry(DBRefSource.UNIPROT, dbVersion, - accessionId,null,canonical); - canonical=false; + accessionId, null, canonical); + canonical = false; dbRefs.add(dbRef); } @@ -250,8 +254,16 @@ public class Uniprot extends DbSourceProxyImpl dbRefs.add(dbr); } } - if ("Ensembl".equals(type)) + // from 2.11.2.6 - probably see a conflict here + if (type != null + && type.toLowerCase(Locale.ROOT).startsWith("ensembl")) { + // remove version + String[] vrs = dbref.getId().split("\\."); + String version = vrs.length > 1 ? vrs[1] + : DBRefSource.UNIPROT + ":" + dbVersion; + dbr.setAccessionId(vrs[0]); + dbr.setVersion(version); /* * e.g. Uniprot accession Q9BXM7 has * @@ -264,8 +276,12 @@ public class Uniprot extends DbSourceProxyImpl "protein sequence ID"); if (cdsId != null && cdsId.trim().length() > 0) { + // remove version + String[] cdsVrs = cdsId.split("\\."); + String cdsVersion = cdsVrs.length > 1 ? cdsVrs[1] + : DBRefSource.UNIPROT + ":" + dbVersion; dbr = new DBRefEntry(DBRefSource.ENSEMBL, - DBRefSource.UNIPROT + ":" + dbVersion, cdsId.trim()); + DBRefSource.UNIPROT + ":" + cdsVersion, cdsVrs[0]); dbRefs.add(dbr); } } @@ -513,10 +529,12 @@ public class Uniprot extends DbSourceProxyImpl XMLStreamReader streamReader = XMLInputFactory.newInstance() .createXMLStreamReader(is); javax.xml.bind.Unmarshaller um = jc.createUnmarshaller(); - JAXBElement uniprotElement = - um.unmarshal(streamReader, jalview.xml.binding.uniprot.Uniprot.class); - jalview.xml.binding.uniprot.Uniprot uniprot = uniprotElement.getValue(); - + JAXBElement uniprotElement = um + .unmarshal(streamReader, + jalview.xml.binding.uniprot.Uniprot.class); + jalview.xml.binding.uniprot.Uniprot uniprot = uniprotElement + .getValue(); + if (uniprot != null && !uniprot.getEntry().isEmpty()) { entries = uniprot.getEntry(); @@ -524,7 +542,10 @@ public class Uniprot extends DbSourceProxyImpl } catch (JAXBException | XMLStreamException | FactoryConfigurationError e) { - if (e instanceof javax.xml.bind.UnmarshalException && e.getCause()!=null && e.getCause() instanceof XMLStreamException && e.getCause().getMessage().contains("[row,col]:[1,1]")) + if (e instanceof javax.xml.bind.UnmarshalException + && e.getCause() != null + && e.getCause() instanceof XMLStreamException + && e.getCause().getMessage().contains("[row,col]:[1,1]")) { // trying to parse an empty stream return null;