From 1d4bc65204bdb63740d3692f13633c463d5c08fd Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 18 Jan 2012 11:14:06 +0000 Subject: [PATCH] (JAL-972) jdas source retrieval and use of jdas structures for local sources --- src/jalview/gui/DasSourceBrowser.java | 287 ++++++++++++++----------- src/jalview/ws/DasSequenceFeatureFetcher.java | 38 +--- 2 files changed, 178 insertions(+), 147 deletions(-) diff --git a/src/jalview/gui/DasSourceBrowser.java b/src/jalview/gui/DasSourceBrowser.java index 2f257af..faf4712 100755 --- a/src/jalview/gui/DasSourceBrowser.java +++ b/src/jalview/gui/DasSourceBrowser.java @@ -17,7 +17,6 @@ */ package jalview.gui; -import java.security.interfaces.DSAKey; import java.text.ParseException; import java.util.*; import java.util.List; @@ -29,7 +28,9 @@ import javax.swing.event.*; import javax.swing.table.*; import org.biodas.jdas.dassources.Capabilities; +import org.biodas.jdas.dassources.utils.DasCoordinateSystemCollector; import org.biodas.jdas.dassources.utils.DasTimeFormat; +import org.biodas.jdas.schema.registrycoordinates.DASCOORDINATESYSTEM; import org.biodas.jdas.schema.sources.CAPABILITY; import org.biodas.jdas.schema.sources.COORDINATES; import org.biodas.jdas.schema.sources.MAINTAINER; @@ -46,7 +47,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements { static org.biodas.jdas.schema.sources.SOURCE[] dasSources = null; - Hashtable localSources = null; + Hashtable localSources = null; Vector selectedSources; @@ -200,8 +201,8 @@ public class DasSourceBrowser extends GDasSourceBrowser implements + dasSources[i].getUri() + "
"); text.append("Nickname: " + dasSources[i].getTitle() + "
"); - text.append("URL: " - + latest.getUri() + "
"); + text.append("URL: " + latest.getUri() + + "
"); text.append("Admin Email: "); // TODO: Identify last successful test date -// text.append("Last successful test: " -// + latest.dasSources[i].getLeaseDate() + "
"); + // text.append("Last successful test: " + // + latest.dasSources[i].getLeaseDate() + "
"); text.append("Labels: "); - for (int s = 0; s < latest.getPROP().length; s++) + boolean b = false; + for (PROP labl : latest.getPROP()) { - text.append(dasSources[i].getLabels()[s]); - if (s < dasSources[i].getLabels().length - 1) + if (labl.getName().equalsIgnoreCase("LABEL")) { - text.append(","); + if (!b) + { + text.append(","); + } + text.append(" "); + + text.append(labl.getValue()); + b = true; } - text.append(" "); + ; } text.append("
"); @@ -240,39 +248,40 @@ public class DasSourceBrowser extends GDasSourceBrowser implements text.append("
"); text.append("Coordinates: "); - DasCoordinateSystem[] dcs = ds.getCoordinateSystem(); - for (int j = 0; j < dcs.length; j++) + for (COORDINATES dcs : latest.getCOORDINATES()) { - text.append("(" + dcs[j].getUniqueId() + ") " - + dcs[j].getCategory() + ", " + dcs[j].getName()); - if (dcs[j].getNCBITaxId() != 0) + text.append("(" + dcs.getUri() + ") " + + + dcs.getSource() + ", " + dcs.getAuthority()); + if (dcs.getTaxid() != null && dcs.getTaxid().trim().length() > 0) { - text.append(", " + dcs[j].getNCBITaxId()); + text.append(", " + dcs.getTaxid()); } - if (dcs[j].getOrganismName().length() > 0) + if (dcs.getVersion().trim().length() > 0) { - text.append(", " + dcs[j].getOrganismName()); - } + { + text.append(", " + dcs.getVersion()); + } - text.append("
"); - } + text.append("
"); + } - text.append("Description: " - + dasSources[i].getDescription() + "
"); + text.append("Description: " + + dasSources[i].getDescription() + "
"); - if (dasSources[i].getHelperurl() != null - && dasSources[i].getHelperurl().length() > 0) - { - text.append("
Go to site"); - } + if (dasSources[i].getDocHref() != null + && dasSources[i].getDocHref().length() > 0) + { + text.append("Go to site"); + } - text.append(""); + text.append(""); - break; + break; + } } - fullDetails.setText(text.toString()); javax.swing.SwingUtilities.invokeLater(new Runnable() { @@ -346,8 +355,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements { for (int i = 0; i < dasSources.length; i++) { - if (dasSources[i].getTitle() - .equals(selectedSources.elementAt(r))) + if (dasSources[i].getTitle().equals(selectedSources.elementAt(r))) { selected.addElement(dasSources[i]); break; @@ -384,65 +392,72 @@ public class DasSourceBrowser extends GDasSourceBrowser implements private boolean isLaterThan(String ref, String newer) { - Date refdate=null,newdate=null; - try { - refdate=DasTimeFormat.fromDASString(ref); - - } - catch (ParseException x) + Date refdate = null, newdate = null; + try + { + refdate = DasTimeFormat.fromDASString(ref); + + } catch (ParseException x) { return false; } - try { + try + { newdate = DasTimeFormat.fromDASString(newer); - } - catch (ParseException e) { + } catch (ParseException e) + { // TODO: handle exception } - if (refdate!=null) + if (refdate != null) { - if (newdate!=null) + if (newdate != null) { return refdate.before(newdate); } return false; } - if (newdate!=null) + if (newdate != null) { return true; } - // assume first instance of source is newest in list. - TODO: check if natural ordering of source versions is newest first or oldest first + // assume first instance of source is newest in list. - TODO: check if + // natural ordering of source versions is newest first or oldest first return false; } + private VERSION getVersionFor(SOURCE ds) { - VERSION latest=null; - for (VERSION v:ds.getVERSION()) { - if (latest==null || isLaterThan(latest.getCreated(),v.getCreated())) + VERSION latest = null; + for (VERSION v : ds.getVERSION()) + { + if (latest == null + || isLaterThan(latest.getCreated(), v.getCreated())) { - // TODO: das 1.6 - should just get the first version - ignore other versions since not specified how to construct URL from version's URI + source URI - latest=v; + // TODO: das 1.6 - should just get the first version - ignore other + // versions since not specified how to construct URL from version's URI + // + source URI + latest = v; } } return latest; } + private void setCapabilities(SOURCE[] sources) { Vector authority = new Vector(); Vector type = new Vector(); Vector label = new Vector(); - Vector taxIds=new Vector(); + Vector taxIds = new Vector(); authority.add("Any"); type.add("Any"); label.add("Any"); - for (int i = 0; i < sources.length; i++) { SOURCE ds = sources[i]; - VERSION latest=getVersionFor(ds); - - for (COORDINATES cs: latest.getCOORDINATES()) + VERSION latest = getVersionFor(ds); + + for (COORDINATES cs : latest.getCOORDINATES()) { if (!type.contains(cs.getSource())) { @@ -455,9 +470,10 @@ public class DasSourceBrowser extends GDasSourceBrowser implements } } - for (PROP slabel:latest.getPROP()) + for (PROP slabel : latest.getPROP()) { - if (slabel.getName().equalsIgnoreCase("LABEL") && !label.contains(slabel.getValue())) + if (slabel.getName().equalsIgnoreCase("LABEL") + && !label.contains(slabel.getValue())) { label.add(slabel.getValue()); } @@ -490,7 +506,8 @@ public class DasSourceBrowser extends GDasSourceBrowser implements int selectedRow = table.getSelectionModel().getMinSelectionIndex(); nickname = table.getValueAt(selectedRow, 0).toString(); url = ((SOURCE) localSources.get(nickname)).getUri(); - seqsrc = ((SOURCE) localSources.get(nickname)).getVERSION().get(0).getCAPABILITY().contains(Capabilities.SEQUENCE); + seqsrc = ((SOURCE) localSources.get(nickname)).getVERSION().get(0) + .getCAPABILITY().contains(Capabilities.SEQUENCE); } JTextField nametf = new JTextField(nickname, 40); @@ -522,40 +539,8 @@ public class DasSourceBrowser extends GDasSourceBrowser implements urltf.setText(urltf.getText() + "/"); } - // build using pattern from test: sourcesclientImplTest - { - SOURCE source = new SOURCE(); - String uri = "http://das.sanger.ac.uk/das/dummysource"; - source.setUri("http://das.sanger.ac.uk/das/dummysource"); - source.setDescription("Dummy Test Source, should not be in a working registry sources doc"); - VERSION version = new VERSION(); - version.setUri(uri); - COORDINATES coord = new COORDINATES(); - coord.setAuthority("NCBI"); - coord.setSource("Chromosome"); - coord.setTaxid("9606"); - coord.setVersion("35"); - version.getCOORDINATES().add(coord); - CAPABILITY cap = new CAPABILITY(); - cap.setQueryUri(uri + "features"); - cap.setType("das1:" + Capabilities.FEATURES.getName()); - version.getCAPABILITY().add(cap); - source.getVERSION().add(version); - MAINTAINER m = new MAINTAINER(); - m.setEmail("jw12@sanger.ac.uk"); - source.setMAINTAINER(m); - source.setTitle("dummy title"); - - } - SOURCE local = new Das1Source(); - - local.setUrl(urltf.getText()); - local.setNickname(nametf.getText()); - if (seqs.isSelected()) - { - local.setCapabilities(new String[] - { "features", "sequence" }); - } + SOURCE local = createLocalSource(urltf.getText(), nametf.getText(), seqs.isSelected(), true); + if (localSources == null) { localSources = new Hashtable(); @@ -576,8 +561,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements { if (!newSource && dasSources[i].getTitle().equals(nickname)) { - ((DasSource) dasSources[i]).setNickname(local.getTitle()); - ((DasSource) dasSources[i]).setUrl(local.getUrl()); + dasSources[i] = local; data[i][0] = local.getTitle(); data[i][1] = new Boolean(true); } @@ -596,7 +580,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements selectedSources.add(local.getTitle()); } - DasSource[] tmp = new DasSource[size + adjust]; + SOURCE[] tmp = new SOURCE[size + adjust]; System.arraycopy(dasSources, 0, tmp, 0, size); @@ -621,6 +605,42 @@ public class DasSourceBrowser extends GDasSourceBrowser implements displayFullDetails(local.getTitle()); } + private SOURCE createLocalSource(String url, String name, + boolean sequence, boolean features) + { + SOURCE local = new SOURCE(); + + local.setUri(url); + local.setTitle(name); + local.setVERSION(new ArrayList()); + VERSION v = new VERSION(); + List cp = new ArrayList(); + if (sequence) + { +/* Could try and synthesize a coordinate system for the source if needbe + * COORDINATES coord = new COORDINATES(); + coord.setAuthority("NCBI"); + coord.setSource("Chromosome"); + coord.setTaxid("9606"); + coord.setVersion("35"); + version.getCOORDINATES().add(coord);*/ + CAPABILITY cap=new CAPABILITY(); + cap.setType("das1:"+Capabilities.SEQUENCE.getName()); + cp.add(cap); + } + if (features) + { + CAPABILITY cap = new CAPABILITY(); + cap.setType("das1:"+Capabilities.FEATURES.getName()); + cp.add(cap); + } + + v.getCAPABILITY().addAll(cp); + local.getVERSION().add(v); + + return local; + } + public void editRemoveLocalSource(MouseEvent evt) { int selectedRow = table.getSelectionModel().getMinSelectionIndex(); @@ -657,7 +677,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements localSources.remove(nickname); selectedSources.remove(nickname); Object[][] data = new Object[dasSources.length - 1][2]; - DasSource[] tmp = new DasSource[dasSources.length - 1]; + SOURCE[] tmp = new SOURCE[dasSources.length - 1]; int index = 0; for (int i = 0; i < dasSources.length; i++) { @@ -708,7 +728,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements .getTitle())); } - DasSource[] tmp = new DasSource[size + lsize]; + SOURCE[] tmp = new SOURCE[size + lsize]; if (dasSources != null) { System.arraycopy(dasSources, 0, tmp, 0, size); @@ -721,9 +741,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements String key = en.nextElement().toString(); data[index][0] = key; data[index][1] = new Boolean(false); - tmp[index] = new Das1Source(); - tmp[index].setNickname(key); - tmp[index].setUrl(((DasSource) localSources.get(key)).getUrl()); + tmp[index] = createLocalSource(localSources.get(key).getUri(), key, false, true); index++; } @@ -748,7 +766,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements ArrayList names = new ArrayList(); ArrayList selected = new ArrayList(); - DasSource ds; + SOURCE ds; // The features filter is not visible, but we must still // filter the das source list here. @@ -759,9 +777,9 @@ public class DasSourceBrowser extends GDasSourceBrowser implements for (int i = 0; i < dSize; i++) { ds = dasSources[i]; - DasCoordinateSystem[] dcs = ds.getCoordinateSystem(); - - if (dcs.length == 0 && ds.getCapabilities().length == 0 + VERSION v=getVersionFor(ds); + List coords = v.getCOORDINATES(); + if ((coords==null || coords.size()==0) && filter1.getSelectedIndex() == 0 && filter2.getSelectedIndex() == 0 && filter3.getSelectedIndex() == 0) @@ -774,23 +792,22 @@ public class DasSourceBrowser extends GDasSourceBrowser implements continue; } - if (!selectedInList(dummyFeatureList, ds.getCapabilities()) + if (!selectedInList(dummyFeatureList, getCapabilityKeys(v)) || !selectedInList(filter3.getSelectedValues(), - ds.getLabels())) + getLabelsFor(v))) { continue; } - for (int j = 0; j < dcs.length; j++) + for (int j = 0; j labels=new ArrayList(); + for (PROP p: v.getPROP()) + { + if (p.getName().equalsIgnoreCase("LABEL")) + { + labels.add(p.getValue()); + } + } + return labels.toArray(new String[0]); + } + + private String[] getCapabilityKeys(VERSION v) + { + + ArrayList labels=new ArrayList(); + for (CAPABILITY p: v.getCAPABILITY()) + { + // TODO: work out what to do with namespace prefix + // does SEQUENCE == das1:SEQUENCE and das2:SEQUENCE ? + // for moment, just show all capabilities... + if (p.getType().startsWith("das1:")) + { + labels.add(p.getType()); + } + } + return labels.toArray(new String[0]); + } + boolean selectedInList(Object[] selection, String[] items) { for (int i = 0; i < selection.length; i++) @@ -844,12 +891,12 @@ public class DasSourceBrowser extends GDasSourceBrowser implements { if (localSources == null) { - localSources = new Hashtable(); + localSources = new Hashtable(); } Enumeration sources = _localSources.elements(); while (sources.hasMoreElements()) { - Das1Source source = (Das1Source) sources.nextElement(); + SOURCE source = (SOURCE) sources.nextElement(); localSources.put(source.getTitle(), source); } } @@ -898,9 +945,9 @@ public class DasSourceBrowser extends GDasSourceBrowser implements String token = en.nextElement().toString(); sb.append(token + "|" - + (((DasSource) localSources.get(token)) - .hasCapability("sequence") ? "sequence:" : "") - + ((DasSource) localSources.get(token)).getUrl() + "\t"); + + (selectedInList(getCapabilityKeys(getVersionFor(localSources.get(token))), + new String[] { "das1:"+Capabilities.SEQUENCE.getName()}) ? "sequence:" : "") + + getVersionFor(localSources.get(token)).getUri() + "\t"); } properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, diff --git a/src/jalview/ws/DasSequenceFeatureFetcher.java b/src/jalview/ws/DasSequenceFeatureFetcher.java index bf200ce..30fe725 100644 --- a/src/jalview/ws/DasSequenceFeatureFetcher.java +++ b/src/jalview/ws/DasSequenceFeatureFetcher.java @@ -22,6 +22,9 @@ import java.util.*; import javax.swing.*; +import org.biodas.jdas.client.SourcesClient; +import org.biodas.jdas.schema.sources.SOURCE; +import org.biodas.jdas.schema.sources.SOURCES; import org.biojava.dasobert.das.*; import org.biojava.dasobert.das2.*; import org.biojava.dasobert.das2.io.*; @@ -840,7 +843,7 @@ public class DasSequenceFeatureFetcher * * @return list of sources */ - public static DasSource[] getDASSources() + public static SOURCE[] getDASSources() { String registryURL = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL", @@ -854,38 +857,19 @@ public class DasSequenceFeatureFetcher * @param registryURL * return sources from registryURL */ - public static DasSource[] getDASSources(String registryURL) + public static SOURCE[] getDASSources(String registryURL) { - DasSourceReaderImpl reader = new DasSourceReaderImpl(); - + try { URL url = new URL(registryURL); + org.biodas.jdas.client.SourcesClientInterface client = new SourcesClient(); + + SOURCES sources = client.fetchData(registryURL); - DasSource[] sources = reader.readDasSource(url); - - List das1sources = new ArrayList(); - for (int i = 0; i < sources.length; i++) - { - DasSource ds = sources[i]; - if (ds instanceof Das2Source) - { - Das2Source d2s = (Das2Source) ds; - if (d2s.hasDas1Capabilities()) - { - Das1Source d1s = DasSourceConverter.toDas1Source(d2s); - das1sources.add(d1s); - } - - } - else if (ds instanceof Das1Source) - { - das1sources.add((Das1Source) ds); - } - } + List dassources = sources.getSOURCE(); - return (Das1Source[]) das1sources.toArray(new Das1Source[das1sources - .size()]); + return dassources.toArray(new SOURCE[dassources.size()]); } catch (Exception ex) { System.err.println("Failed to contact DAS1 registry at " -- 1.7.10.2