*/
package jalview.ws.dbsources;
+import jalview.bin.Cache;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.xdb.uniprot.UniprotEntry;
import jalview.datamodel.xdb.uniprot.UniprotFeature;
import jalview.datamodel.xdb.uniprot.UniprotFile;
+import jalview.schemes.ResidueProperties;
+import jalview.util.StringUtils;
import jalview.ws.seqfetcher.DbSourceProxyImpl;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
+import java.util.List;
import java.util.Vector;
import org.exolab.castor.mapping.Mapping;
*/
public class Uniprot extends DbSourceProxyImpl
{
+ private static final String DEFAULT_UNIPROT_DOMAIN = "https://www.uniprot.org";
+
private static final String BAR_DELIMITER = "|";
/*
super();
}
+ private String getDomain()
+ {
+ return Cache.getDefault("UNIPROT_DOMAIN", DEFAULT_UNIPROT_DOMAIN);
+ }
+
/*
* (non-Javadoc)
*
"(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", "");
AlignmentI al = null;
- String downloadstring = "http://www.uniprot.org/uniprot/" + queries
+ String downloadstring = getDomain() + "/uniprot/" + queries
+ ".xml";
URL url = null;
URLConnection urlconn = null;
sequence.setDescription(getUniprotEntryDescription(entry));
final String dbVersion = getDbVersion();
- ArrayList<DBRefEntry> dbRefs = new ArrayList<DBRefEntry>();
+ ArrayList<DBRefEntry> dbRefs = new ArrayList<>();
for (String accessionId : entry.getAccession())
{
DBRefEntry dbRef = new DBRefEntry(DBRefSource.UNIPROT, dbVersion,
dbRefs.add(dbRef);
}
- Vector<PDBEntry> onlyPdbEntries = new Vector<PDBEntry>();
+ Vector<PDBEntry> onlyPdbEntries = new Vector<>();
for (PDBEntry pdb : entry.getDbReference())
{
DBRefEntry dbr = new DBRefEntry();
for (UniprotFeature uf : entry.getFeature())
{
SequenceFeature copy = new SequenceFeature(uf.getType(),
- uf.getDescription(), uf.getBegin(), uf.getEnd(), "Uniprot");
+ getDescription(uf), uf.getBegin(), uf.getEnd(), "Uniprot");
copy.setStatus(uf.getStatus());
sequence.addSequenceFeature(copy);
}
}
/**
+ * Constructs a feature description from the description and (optionally)
+ * original and variant fields of the Uniprot XML feature
+ *
+ * @param uf
+ * @return
+ */
+ protected static String getDescription(UniprotFeature uf)
+ {
+ String orig = uf.getOriginal();
+ List<String> variants = uf.getVariation();
+ StringBuilder sb = new StringBuilder();
+
+ /*
+ * append variant in standard format if present
+ * e.g. p.Arg59Lys
+ * multiple variants are split over lines using <br>
+ */
+ boolean asHtml = false;
+ if (orig != null && !orig.isEmpty() && variants != null
+ && !variants.isEmpty())
+ {
+ int p = 0;
+ for (String var : variants)
+ {
+ // TODO proper HGVS nomenclature for delins structural variations
+ // http://varnomen.hgvs.org/recommendations/protein/variant/delins/
+ // for now we are pragmatic - any orig/variant sequence longer than
+ // three characters is shown with single-character notation rather than
+ // three-letter notation
+ sb.append("p.");
+ if (orig.length() < 4)
+ {
+ for (int c = 0, clen = orig.length(); c < clen; c++)
+ {
+ char origchar = orig.charAt(c);
+ String orig3 = ResidueProperties.aa2Triplet.get("" + origchar);
+ sb.append(orig3 == null ? origchar
+ : StringUtils.toSentenceCase(orig3));
+ }
+ }
+ else
+ {
+ sb.append(orig);
+ }
+
+ sb.append(Integer.toString(uf.getPosition()));
+
+ if (var.length() < 4)
+ {
+ for (int c = 0, clen = var.length(); c < clen; c++)
+ {
+ char varchar = var.charAt(c);
+ String var3 = ResidueProperties.aa2Triplet.get("" + varchar);
+
+ sb.append(var3 != null ? StringUtils.toSentenceCase(var3)
+ : "" + varchar);
+ }
+ }
+ else
+ {
+ sb.append(var);
+ }
+ if (++p != variants.size())
+ {
+ sb.append("<br/> ");
+ asHtml = true;
+ }
+ else
+ {
+ sb.append(" ");
+ }
+ }
+ }
+ String description = uf.getDescription();
+ if (description != null)
+ {
+ sb.append(description);
+ }
+ if (asHtml)
+ {
+ sb.insert(0, "<html>");
+ sb.append("</html>");
+ }
+
+ return sb.toString();
+ }
+
+ /**
*
* @param entry
* UniportEntry
/**
*
* @param entry
- * UniportEntry
+ * UniprotEntry
* @return The accession id(s) and name(s) delimited by '|'.
*/
public static String getUniprotEntryId(UniprotEntry entry)
{
StringBuilder name = new StringBuilder(32);
- // name.append("UniProt/Swiss-Prot");
- // use 'canonicalised' name for optimal id matching
- name.append(DBRefSource.UNIPROT);
- for (String accessionId : entry.getAccession())
- {
- name.append(BAR_DELIMITER);
- name.append(accessionId);
- }
for (String n : entry.getName())
{
- name.append(BAR_DELIMITER);
+ if (name.length() > 0)
+ {
+ name.append(BAR_DELIMITER);
+ }
name.append(n);
}
return name.toString();