git://source.jalview.org
/
jalview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
JAL-4034 change to jalview property name
[jalview.git]
/
src
/
jalview
/
ws
/
dbsources
/
Uniprot.java
diff --git
a/src/jalview/ws/dbsources/Uniprot.java
b/src/jalview/ws/dbsources/Uniprot.java
index
d1da9de
..
371eb50
100644
(file)
--- a/
src/jalview/ws/dbsources/Uniprot.java
+++ b/
src/jalview/ws/dbsources/Uniprot.java
@@
-20,6
+20,8
@@
*/
package jalview.ws.dbsources;
*/
package jalview.ws.dbsources;
+import java.util.Locale;
+
import jalview.bin.Cache;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.bin.Cache;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
@@
-32,7
+34,6
@@
import jalview.datamodel.SequenceI;
import jalview.schemes.ResidueProperties;
import jalview.util.StringUtils;
import jalview.ws.seqfetcher.DbSourceProxyImpl;
import jalview.schemes.ResidueProperties;
import jalview.util.StringUtils;
import jalview.ws.seqfetcher.DbSourceProxyImpl;
-import jalview.xml.binding.embl.ROOT;
import jalview.xml.binding.uniprot.DbReferenceType;
import jalview.xml.binding.uniprot.Entry;
import jalview.xml.binding.uniprot.FeatureType;
import jalview.xml.binding.uniprot.DbReferenceType;
import jalview.xml.binding.uniprot.Entry;
import jalview.xml.binding.uniprot.FeatureType;
@@
-41,8
+42,8
@@
import jalview.xml.binding.uniprot.PositionType;
import jalview.xml.binding.uniprot.PropertyType;
import java.io.InputStream;
import jalview.xml.binding.uniprot.PropertyType;
import java.io.InputStream;
+import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URL;
-import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
@@
-139,29
+140,34
@@
public class Uniprot extends DbSourceProxyImpl
startQuery();
try
{
startQuery();
try
{
- queries = queries.toUpperCase().replaceAll(
+ queries = queries.toUpperCase(Locale.ROOT).replaceAll(
"(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", "");
AlignmentI al = null;
"(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);
URL url = new URL(downloadstring);
- URLConnection urlconn = url.openConnection();
- InputStream istr = urlconn.getInputStream();
- List<Entry> entries = getUniprotEntries(istr);
- if (entries != null)
+ HttpURLConnection urlconn = (HttpURLConnection) url.openConnection();
+ // anything other than 200 means we don't have data
+ // 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<SequenceI> seqs = new ArrayList<>();
- for (Entry entry : entries)
+ InputStream istr = urlconn.getInputStream();
+ List<Entry> entries = getUniprotEntries(istr);
+ if (entries != null)
{
{
- seqs.add(uniprotEntryToSequence(entry));
+ List<SequenceI> 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;
stopQuery();
return al;
+
} catch (Exception e)
{
throw (e);
} catch (Exception e)
{
throw (e);
@@
-180,18
+186,13
@@
public class Uniprot extends DbSourceProxyImpl
SequenceI uniprotEntryToSequence(Entry entry)
{
String id = getUniprotEntryId(entry);
SequenceI uniprotEntryToSequence(Entry entry)
{
String id = getUniprotEntryId(entry);
- String seqString = entry.getSequence().getValue();
-
/*
/*
- * for backwards compatibility with Castor processing,
- * remove any internal spaces
+ * Sequence should not include any whitespace, but JAXB leaves these in
*/
*/
- if (seqString.indexOf(' ') > -1)
- {
- seqString = seqString.replace(" ", "");
- }
- SequenceI sequence = new Sequence(id,
- seqString);
+ String seqString = entry.getSequence().getValue().replaceAll("\\s*",
+ "");
+
+ SequenceI sequence = new Sequence(id, seqString);
sequence.setDescription(getUniprotEntryDescription(entry));
/*
sequence.setDescription(getUniprotEntryDescription(entry));
/*
@@
-199,10
+200,12
@@
public class Uniprot extends DbSourceProxyImpl
*/
final String dbVersion = getDbVersion();
List<DBRefEntry> dbRefs = new ArrayList<>();
*/
final String dbVersion = getDbVersion();
List<DBRefEntry> dbRefs = new ArrayList<>();
+ boolean canonical = true;
for (String accessionId : entry.getAccession())
{
DBRefEntry dbRef = new DBRefEntry(DBRefSource.UNIPROT, dbVersion,
for (String accessionId : entry.getAccession())
{
DBRefEntry dbRef = new DBRefEntry(DBRefSource.UNIPROT, dbVersion,
- accessionId);
+ accessionId, null, canonical);
+ canonical = false;
dbRefs.add(dbRef);
}
dbRefs.add(dbRef);
}
@@
-507,10
+510,12
@@
public class Uniprot extends DbSourceProxyImpl
XMLStreamReader streamReader = XMLInputFactory.newInstance()
.createXMLStreamReader(is);
javax.xml.bind.Unmarshaller um = jc.createUnmarshaller();
XMLStreamReader streamReader = XMLInputFactory.newInstance()
.createXMLStreamReader(is);
javax.xml.bind.Unmarshaller um = jc.createUnmarshaller();
- JAXBElement<jalview.xml.binding.uniprot.Uniprot> uniprotElement =
- um.unmarshal(streamReader, jalview.xml.binding.uniprot.Uniprot.class);
- jalview.xml.binding.uniprot.Uniprot uniprot = uniprotElement.getValue();
-
+ JAXBElement<jalview.xml.binding.uniprot.Uniprot> 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();
if (uniprot != null && !uniprot.getEntry().isEmpty())
{
entries = uniprot.getEntry();
@@
-518,6
+523,14
@@
public class Uniprot extends DbSourceProxyImpl
} catch (JAXBException | XMLStreamException
| FactoryConfigurationError e)
{
} 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]"))
+ {
+ // trying to parse an empty stream
+ return null;
+ }
e.printStackTrace();
}
return entries;
e.printStackTrace();
}
return entries;