<classpathentry kind="lib" path="lib/min-jaba-client-2.0.jar" sourcepath="/clustengine2"/>
<classpathentry kind="lib" path="lib/Jmol-12.2.4.jar"/>
<classpathentry kind="lib" path="appletlib/JmolApplet-12.2.4.jar"/>
+ <classpathentry kind="lib" path="lib/jdas-1.0.4.jar"/>
+ <classpathentry kind="lib" path="lib/spring-core-3.0.5.RELEASE.jar"/>
+ <classpathentry kind="lib" path="lib/spring-web-3.0.5.RELEASE.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/plugin.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/plugin.java"/>
<classpathentry kind="lib" path="/Users/jimp/git/jalview_clean/lib/VARNAv3-9-dev.jar"/>
</dictionary>
</arguments>
</buildCommand>
- <buildCommand>
- <name>org.codehaus.groovy.eclipse.groovyBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>de.tud.st.ispace.builder.ISpaceNature</nature>
<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
- <nature>org.codehaus.groovy.eclipse.groovyNature</nature>
</natures>
</projectDescription>
httpcore-4.0.1.jar
httpmime-4.0.3.jar
jaxrpc.jar
+jdas-1.0.4.jar : Apache License - built from http://code.google.com/p/jdas/ (29th Feb 2012)
jhall.jar
jswingreader-0.3.jar : Apache license - built from http://jswingreader.sourceforge.net/ svn/trunk v12
log4j-1.2.8.jar
min-jaba-client.jar
regex.jar
saaj.jar
+spring-core-3.0.5.RELEASE.jar : Apache License: jdas runtime dependencies retrieved via maven
+spring-web-3.0.5.RELEASE.jar : Apache License: jdas runtime dependencies retrieved via maven
vamsas-client.jar
wsdl4j.jar
xercesImpl.jar
*/
package jalview.bin;
+import jalview.ws.dbsources.das.api.DasSourceRegistryI;
+import jalview.ws.dbsources.das.datamodel.DasSourceRegistry;
+
import java.awt.Color;
import java.io.*;
import java.text.DateFormat;
import java.util.*;
import org.apache.log4j.*;
-import org.biojava.dasobert.dasregistry.Das1Source;
/**
* Stores and retrieves Jalview Application Properties Lists and fields within
}
/**
- * generate Das1Sources from the local das source list
- *
- * @return Vector of Das1Sources
- */
- public static Vector getLocalDasSources()
- {
- Vector localSources = new Vector();
- String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
- if (local != null)
- {
- StringTokenizer st = new StringTokenizer(local, "\t");
- while (st.hasMoreTokens())
- {
- String token = st.nextToken();
- int bar = token.indexOf("|");
- Das1Source source = new Das1Source();
- source.setUrl(token.substring(bar + 1));
- if (source.getUrl().startsWith("sequence:"))
- {
- source.setUrl(source.getUrl().substring(9));
- // this source also serves sequences as well as features
- source.setCapabilities(new String[]
- { "sequence", "features" });
- }
- else
- {
- // default is that all user added sources serve features
- source.setCapabilities(new String[]
- { "features" });
- }
-
- source.setNickname(token.substring(0, bar));
-
- localSources.addElement(source);
- }
- }
- return localSources;
- }
-
- /**
* GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
* enabled.
*/
}
return null;
}
+
+ private static DasSourceRegistryI sourceRegistry=null;
+ /**
+ * initialise and ..
+ * @return instance of the das source registry
+ */
+ public static DasSourceRegistryI getDasSourceRegistry()
+ {
+ if (sourceRegistry==null)
+ {
+ sourceRegistry = new DasSourceRegistry();
+ }
+ return sourceRegistry;
+ }
}
*/\r
package jalview.gui;\r
\r
-import java.util.*;\r
-\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-import javax.swing.*;\r
-import javax.swing.event.*;\r
-import javax.swing.table.*;\r
-\r
-import org.biojava.dasobert.dasregistry.*;\r
-import jalview.jbgui.*;\r
-import jalview.util.*;\r
+import jalview.jbgui.GDasSourceBrowser;\r
+import jalview.util.TableSorter;\r
+import jalview.ws.dbsources.das.api.DasSourceRegistryI;\r
+import jalview.ws.dbsources.das.api.jalviewSourceI;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.MouseAdapter;\r
+import java.awt.event.MouseEvent;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Properties;\r
+import java.util.StringTokenizer;\r
+import java.util.Vector;\r
+\r
+import javax.swing.JCheckBox;\r
+import javax.swing.JLabel;\r
+import javax.swing.JOptionPane;\r
+import javax.swing.JPanel;\r
+import javax.swing.JTextField;\r
+import javax.swing.ListSelectionModel;\r
+import javax.swing.SwingUtilities;\r
+import javax.swing.event.ListSelectionEvent;\r
+import javax.swing.event.ListSelectionListener;\r
+import javax.swing.table.AbstractTableModel;\r
+\r
+import org.biodas.jdas.schema.sources.CAPABILITY;\r
+import org.biodas.jdas.schema.sources.COORDINATES;\r
+import org.biodas.jdas.schema.sources.PROP;\r
+import org.biodas.jdas.schema.sources.VERSION;\r
\r
public class DasSourceBrowser extends GDasSourceBrowser implements\r
Runnable, ListSelectionListener\r
{\r
- static DasSource[] dasSources = null;\r
-\r
- Hashtable localSources = null;\r
-\r
- Vector selectedSources;\r
-\r
- public static String DEFAULT_REGISTRY = "http://www.dasregistry.org/das1/sources/";\r
-\r
- /**\r
- * true if thread is running and we are talking to DAS registry service\r
- */\r
- public boolean loadingDasSources = false;\r
+ DasSourceRegistryI sourceRegistry = null;\r
\r
- protected static String getDasRegistryURL()\r
- {\r
- String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",\r
- DEFAULT_REGISTRY);\r
-\r
- if (registry.indexOf("/registry/das1/sources/") > -1)\r
- {\r
- jalview.bin.Cache.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL,\r
- DEFAULT_REGISTRY);\r
- registry = DEFAULT_REGISTRY;\r
- }\r
- return registry;\r
- }\r
+ Vector<String> selectedSources;\r
\r
public DasSourceBrowser(FeatureSettings featureSettings)\r
{\r
fs = featureSettings;\r
- String registry = getDasRegistryURL();\r
+ // TODO DasSourceRegistryProvider API\r
+ sourceRegistry = jalview.bin.Cache.getDasSourceRegistry();\r
+ String registry = sourceRegistry.getDasRegistryURL();\r
\r
registryURL.setText(registry);\r
\r
}\r
});\r
\r
- if (dasSources != null)\r
+ if (sourceRegistry.getSources() != null)\r
{\r
init();\r
}\r
\r
FeatureSettings fs = null;\r
\r
+ private boolean loadingDasSources;\r
+\r
public DasSourceBrowser()\r
{\r
this(null);\r
\r
public void paintComponent(java.awt.Graphics g)\r
{\r
- if (dasSources == null && !loadingDasSources)\r
+ if (sourceRegistry == null)\r
{\r
Thread worker = new Thread(this);\r
worker.start();\r
\r
void init()\r
{\r
- int dSize = dasSources.length;\r
+ List<jalviewSourceI> sources = sourceRegistry.getSources();\r
+ int dSize = sources.size();\r
Object[][] data = new Object[dSize][2];\r
for (int i = 0; i < dSize; i++)\r
{\r
- data[i][0] = dasSources[i].getNickname();\r
- data[i][1] = new Boolean(selectedSources.contains(dasSources[i]\r
- .getNickname()));\r
+ data[i][0] = sources.get(i).getTitle(); // what's equivalent of nickname\r
+ data[i][1] = new Boolean(selectedSources.contains(sources.get(i).getTitle()));\r
}\r
\r
refreshTableData(data);\r
- setCapabilities(dasSources);\r
+ setCapabilities(sourceRegistry);\r
\r
javax.swing.SwingUtilities.invokeLater(new Runnable()\r
{\r
return;\r
}\r
\r
- int dSize = dasSources.length;\r
- for (int i = 0; i < dSize; i++)\r
+ int dSize = sourceRegistry.getSources().size();\r
+ for (jalviewSourceI ds : sourceRegistry.getSources())\r
{\r
- if (!dasSources[i].getNickname().equals(nickName))\r
+ if (!ds.getTitle().equals(nickName))\r
{\r
continue;\r
}\r
\r
- DasSource ds = dasSources[i];\r
-\r
- text.append("<font color=\"#0000FF\">Id:</font> "\r
- + dasSources[i].getId() + "<br>");\r
+ VERSION latest = ds.getVersion();\r
+ text.append("<font color=\"#0000FF\">Id:</font> " + ds.getUri()\r
+ + "<br>");\r
text.append("<font color=\"#0000FF\">Nickname:</font> "\r
- + dasSources[i].getNickname() + "<br>");\r
- text.append("<font color=\"#0000FF\">URL:</font> "\r
- + dasSources[i].getUrl() + "<br>");\r
-\r
+ + ds.getTitle() + "<br>");\r
+ \r
+ if (!ds.isLocal())\r
+ {\r
+ // TODO: IMMEDIATE verify that URI + ds.URI point to latest version for non-local sources.\r
+ if (ds.getDocHref()!=null) {\r
+ text.append("<font color=\"#0000FF\">URL:</font> " + ds.getDocHref()\r
+ + "<br>");\r
+ }\r
+ \r
text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"\r
- + dasSources[i].getAdminemail()\r
- + "\">"\r
- + dasSources[i].getAdminemail() + "</a>" + "<br>");\r
+ + ds.getEmail() + "\">" + ds.getEmail() + "</a>" + "<br>");\r
\r
text.append("<font color=\"#0000FF\">Registered at:</font> "\r
- + dasSources[i].getRegisterDate() + "<br>");\r
-\r
- text.append("<font color=\"#0000FF\">Last successful test:</font> "\r
- + dasSources[i].getLeaseDate() + "<br>");\r
+ + latest.getCreated() + "<br>");\r
\r
+ // TODO: Identify last successful test date\r
+ // text.append("<font color=\"#0000FF\">Last successful test:</font> "\r
+ // + latest.dasSources[i].getLeaseDate() + "<br>");\r
+ } else {\r
+ text.append("Source was added manually.<br/>");\r
+ }\r
text.append("<font color=\"#0000FF\">Labels:</font> ");\r
- for (int s = 0; s < dasSources[i].getLabels().length; s++)\r
+ boolean b = false;\r
+ for (PROP labl : latest.getPROP())\r
{\r
- text.append(dasSources[i].getLabels()[s]);\r
- if (s < dasSources[i].getLabels().length - 1)\r
+ if (labl.getName().equalsIgnoreCase("LABEL"))\r
{\r
- text.append(",");\r
+ if (!b)\r
+ {\r
+ text.append(",");\r
+ }\r
+ text.append(" ");\r
+\r
+ text.append(labl.getValue());\r
+ b = true;\r
}\r
- text.append(" ");\r
+ ;\r
}\r
text.append("<br>");\r
\r
text.append("<font color=\"#0000FF\">Capabilities:</font> ");\r
- String[] scap = dasSources[i].getCapabilities();\r
+ CAPABILITY[] scap = latest.getCAPABILITY().toArray(new CAPABILITY[0]);\r
for (int j = 0; j < scap.length; j++)\r
{\r
- text.append(scap[j]);\r
+ text.append(scap[j].getType());\r
if (j < scap.length - 1)\r
{\r
text.append(", ");\r
text.append("<br>");\r
\r
text.append("<font color=\"#0000FF\">Coordinates:</font> ");\r
- DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
- for (int j = 0; j < dcs.length; j++)\r
+ for (COORDINATES dcs : latest.getCOORDINATES())\r
{\r
- text.append("(" + dcs[j].getUniqueId() + ") "\r
- + dcs[j].getCategory() + ", " + dcs[j].getName());\r
- if (dcs[j].getNCBITaxId() != 0)\r
+ text.append("(" + dcs.getUri() + ") "\r
+\r
+ + dcs.getSource() + ", " + dcs.getAuthority());\r
+ if (dcs.getTaxid() != null && dcs.getTaxid().trim().length() > 0)\r
{\r
- text.append(", " + dcs[j].getNCBITaxId());\r
+ text.append(", " + dcs.getTaxid());\r
}\r
- if (dcs[j].getOrganismName().length() > 0)\r
+ if (dcs.getVersion()!=null && dcs.getVersion().trim().length() > 0)\r
{\r
- text.append(", " + dcs[j].getOrganismName());\r
- }\r
+ {\r
+ text.append(", " + dcs.getVersion());\r
+ }\r
\r
- text.append("<br>");\r
- }\r
+ text.append("<br>");\r
+ }\r
\r
- text.append("<font color=\"#0000FF\">Description:</font> "\r
- + dasSources[i].getDescription() + "<br>");\r
+ text.append("<font color=\"#0000FF\">Description:</font> "\r
+ + ds.getDescription() + "<br>");\r
\r
- if (dasSources[i].getHelperurl() != null\r
- && dasSources[i].getHelperurl().length() > 0)\r
- {\r
- text.append("<font color=\"#0000FF\"><a href=\""\r
- + dasSources[i].getHelperurl()\r
- + "\">Go to site</a></font<br>");\r
- }\r
+ if (ds.getDocHref() != null && ds.getDocHref().length() > 0)\r
+ {\r
+ text.append("<font color=\"#0000FF\"><a href=\""\r
+ + ds.getDocHref() + "\">Go to site</a></font<br>");\r
+ }\r
\r
- text.append("</font></html>");\r
+ text.append("</font></html>");\r
\r
- break;\r
+ break;\r
+ }\r
}\r
-\r
fullDetails.setText(text.toString());\r
javax.swing.SwingUtilities.invokeLater(new Runnable()\r
{\r
progressBar.setIndeterminate(true);\r
setParentGuiEnabled(false);\r
// Refresh the source list.\r
- dasSources = null;\r
- getDASSource();\r
+ sourceRegistry.refreshSources();\r
\r
init();\r
\r
}\r
}\r
\r
- public Vector getSelectedSources()\r
+ public Vector<jalviewSourceI> getSelectedSources()\r
{\r
// wait around if we're still loading.\r
- while (dasSources == null)\r
+ while (sourceRegistry == null)\r
{\r
if (!loadingDasSources)\r
{\r
}\r
}\r
\r
- Vector selected = new Vector();\r
- for (int r = 0; r < selectedSources.size(); r++)\r
+ Vector<jalviewSourceI> selected = new Vector<jalviewSourceI>();\r
+ for (String source : selectedSources)\r
{\r
- for (int i = 0; i < dasSources.length; i++)\r
+ jalviewSourceI srce = sourceRegistry.getSource(source);\r
+ if (srce != null)\r
{\r
- if (dasSources[i].getNickname()\r
- .equals(selectedSources.elementAt(r)))\r
- {\r
- selected.addElement(dasSources[i]);\r
- break;\r
- }\r
+ selected.addElement(srce);\r
}\r
}\r
-\r
return selected;\r
}\r
\r
- /**\r
- * retrieve das sources from registry and add local source list\r
- * \r
- * @return\r
- */\r
- public DasSource[] getDASSource()\r
- {\r
- if (dasSources == null)\r
- {\r
- dasSources = jalview.ws.DasSequenceFeatureFetcher.getDASSources();\r
- appendLocalSources();\r
- }\r
-\r
- return dasSources;\r
- }\r
-\r
public void refresh_actionPerformed(ActionEvent e)\r
{\r
saveProperties(jalview.bin.Cache.applicationProperties);\r
worker.start();\r
}\r
\r
- private void setCapabilities(DasSource[] sources)\r
+ private void setCapabilities(DasSourceRegistryI sourceRegistry2)\r
{\r
- Vector authority = new Vector();\r
- Vector type = new Vector();\r
- Vector label = new Vector();\r
-\r
- authority.addElement("Any");\r
- type.addElement("Any");\r
- label.addElement("Any");\r
+ Vector<String> authority = new Vector<String>();\r
+ Vector<String> type = new Vector<String>();\r
+ Vector<String> label = new Vector<String>();\r
+ Vector<String> taxIds = new Vector<String>();\r
+ authority.add("Any");\r
+ type.add("Any");\r
+ label.add("Any");\r
\r
- for (int i = 0; i < sources.length; i++)\r
+ for (jalviewSourceI ds : sourceRegistry2.getSources())\r
{\r
- DasSource ds = sources[i];\r
+ VERSION latest = ds.getVersion();\r
\r
- DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
-\r
- for (int j = 0; j < dcs.length; j++)\r
+ for (COORDINATES cs : latest.getCOORDINATES())\r
{\r
- if (!type.contains(dcs[j].getCategory()))\r
+ if (!type.contains(cs.getSource()))\r
{\r
- type.addElement(dcs[j].getCategory());\r
+ type.add(cs.getSource()); // source==category\r
}\r
\r
- if (!authority.contains(dcs[j].getName()))\r
+ if (!authority.contains(cs.getAuthority()))\r
{\r
- authority.addElement(dcs[j].getName());\r
+ authority.add(cs.getAuthority());\r
}\r
}\r
\r
- String[] slabels = ds.getLabels();\r
- for (int s = 0; s < slabels.length; s++)\r
+ for (PROP slabel : latest.getPROP())\r
{\r
- if (!label.contains(slabels[s]))\r
+ if (slabel.getName().equalsIgnoreCase("LABEL")\r
+ && !label.contains(slabel.getValue()))\r
{\r
- label.addElement(slabels[s]);\r
+ label.add(slabel.getValue());\r
}\r
}\r
\r
filter1.setListData(authority);\r
filter2.setListData(type);\r
filter3.setListData(label);\r
+ // filter4 taxIds\r
\r
javax.swing.SwingUtilities.invokeLater(new Runnable()\r
{\r
{\r
int selectedRow = table.getSelectionModel().getMinSelectionIndex();\r
nickname = table.getValueAt(selectedRow, 0).toString();\r
- url = ((DasSource) localSources.get(nickname)).getUrl();\r
- seqsrc = ((DasSource) localSources.get(nickname))\r
- .hasCapability("sequence");\r
+ jalviewSourceI source = sourceRegistry.getSource(nickname);\r
+ url = source.getUri();\r
+ seqsrc = source.isSequenceSource();\r
}\r
\r
JTextField nametf = new JTextField(nickname, 40);\r
urltf.setText(urltf.getText() + "/");\r
}\r
\r
- Das1Source local = new Das1Source();\r
+ jalviewSourceI local = sourceRegistry.createLocalSource(\r
+ urltf.getText(), nametf.getText(), seqs.isSelected(), true);\r
+ List sources = sourceRegistry.getSources();\r
+ int osize = sources.size();\r
+ int size = osize + (newSource ? 1 : 0);\r
\r
- local.setUrl(urltf.getText());\r
- local.setNickname(nametf.getText());\r
- if (seqs.isSelected())\r
+ Object[][] data = new Object[size][2];\r
+ DASTableModel dtm = (table != null) ? (DASTableModel)((TableSorter) table.getModel()).getTableModel()\r
+ : null;\r
+ for (int i = 0; i < osize; i++)\r
{\r
- local.setCapabilities(new String[]\r
- { "features", "sequence" });\r
- }\r
- if (localSources == null)\r
- {\r
- localSources = new Hashtable();\r
- }\r
-\r
- localSources.put(local.getNickname(), local);\r
-\r
- if (!newSource && !nickname.equals(nametf.getText()))\r
- {\r
- localSources.remove(nickname);\r
- }\r
-\r
- int size = dasSources.length;\r
- int adjust = newSource ? 1 : 0;\r
-\r
- Object[][] data = new Object[size + adjust][2];\r
- for (int i = 0; i < size; i++)\r
- {\r
- if (!newSource && dasSources[i].getNickname().equals(nickname))\r
+ String osrc = (dtm == null || i >= osize) ? null : (String) dtm\r
+ .getValueAt(i, 0);\r
+ if (!newSource && osrc != null\r
+ && dtm.getValueAt(i, 0).equals(nickname))\r
{\r
- ((DasSource) dasSources[i]).setNickname(local.getNickname());\r
- ((DasSource) dasSources[i]).setUrl(local.getUrl());\r
- data[i][0] = local.getNickname();\r
+ data[i][0] = local.getTitle();\r
data[i][1] = new Boolean(true);\r
}\r
else\r
{\r
- data[i][0] = dasSources[i].getNickname();\r
- data[i][1] = new Boolean(selectedSources.contains(dasSources[i]\r
- .getNickname()));\r
+ data[i][0] = osrc;\r
+ data[i][1] = new Boolean(selectedSources.contains(osrc));\r
}\r
}\r
-\r
+ // Always add a new source at the end\r
if (newSource)\r
{\r
- data[size][0] = local.getNickname();\r
- data[size][1] = new Boolean(true);\r
- selectedSources.add(local.getNickname());\r
+ data[osize][0] = local.getTitle();\r
+ data[osize][1] = new Boolean(true);\r
+ selectedSources.add(local.getTitle());\r
}\r
\r
- DasSource[] tmp = new DasSource[size + adjust];\r
-\r
- System.arraycopy(dasSources, 0, tmp, 0, size);\r
-\r
- if (newSource)\r
- {\r
- tmp[size] = local;\r
- }\r
-\r
- dasSources = tmp;\r
-\r
refreshTableData(data);\r
\r
SwingUtilities.invokeLater(new Runnable()\r
}\r
});\r
\r
- displayFullDetails(local.getNickname());\r
+ displayFullDetails(local.getTitle());\r
}\r
\r
public void editRemoveLocalSource(MouseEvent evt)\r
\r
String nickname = table.getValueAt(selectedRow, 0).toString();\r
\r
- if (!localSources.containsKey(nickname))\r
+ if (!sourceRegistry.getSource(nickname).isLocal())\r
{\r
JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
"You can only edit or remove local DAS Sources!",\r
amendLocal(false);\r
break;\r
case 1:\r
- localSources.remove(nickname);\r
+ sourceRegistry.removeLocalSource(sourceRegistry.getSource(nickname));\r
selectedSources.remove(nickname);\r
- Object[][] data = new Object[dasSources.length - 1][2];\r
- DasSource[] tmp = new DasSource[dasSources.length - 1];\r
- int index = 0;\r
- for (int i = 0; i < dasSources.length; i++)\r
+ Object[][] data = new Object[sourceRegistry.getSources().size()][2];\r
+ int index = 0,\r
+ l = table.getRowCount();\r
+\r
+ for (int i = 0; i < l; i++)\r
{\r
- if (dasSources[i].getNickname().equals(nickname))\r
+ String nm;\r
+ if ((nm = (String) table.getValueAt(i, 0)).equals(nickname))\r
{\r
continue;\r
}\r
else\r
{\r
- tmp[index] = dasSources[i];\r
- data[index][0] = dasSources[i].getNickname();\r
- data[index][1] = new Boolean(\r
- selectedSources.contains(dasSources[i].getNickname()));\r
+ data[index][0] = nm;\r
+ data[index][1] = new Boolean(selectedSources.contains(nm));\r
index++;\r
}\r
}\r
- dasSources = tmp;\r
refreshTableData(data);\r
SwingUtilities.invokeLater(new Runnable()\r
{\r
}\r
}\r
\r
- void appendLocalSources()\r
- {\r
- if (localSources == null)\r
- {\r
- return;\r
- }\r
- // note - we add all das sources to list so they can be filtered for the\r
- // standard fetchDbRefs function\r
- int size = dasSources != null ? dasSources.length : 0;\r
- int lsize = localSources.size();\r
-\r
- Object[][] data = new Object[size + lsize][2];\r
- for (int i = 0; i < size; i++)\r
- {\r
- data[i][0] = dasSources[i].getNickname();\r
- data[i][1] = new Boolean(selectedSources.contains(dasSources[i]\r
- .getNickname()));\r
- }\r
-\r
- DasSource[] tmp = new DasSource[size + lsize];\r
- if (dasSources != null)\r
- {\r
- System.arraycopy(dasSources, 0, tmp, 0, size);\r
- }\r
-\r
- Enumeration en = localSources.keys();\r
- int index = size;\r
- while (en.hasMoreElements())\r
- {\r
- String key = en.nextElement().toString();\r
- data[index][0] = key;\r
- data[index][1] = new Boolean(false);\r
- tmp[index] = new Das1Source();\r
- tmp[index].setNickname(key);\r
- tmp[index].setUrl(((DasSource) localSources.get(key)).getUrl());\r
-\r
- index++;\r
- }\r
-\r
- dasSources = tmp;\r
-\r
- refreshTableData(data);\r
- }\r
-\r
public void valueChanged(ListSelectionEvent evt)\r
{\r
// Called when the MainTable selection changes\r
displayFullDetails(null);\r
\r
// Filter the displayed data sources\r
- int dSize = dasSources.length;\r
\r
ArrayList names = new ArrayList();\r
ArrayList selected = new ArrayList();\r
- DasSource ds;\r
\r
// The features filter is not visible, but we must still\r
// filter the das source list here.\r
// July 2006 - only 6 sources fo not serve features\r
Object[] dummyFeatureList = new Object[]\r
{ "features" };\r
-\r
- for (int i = 0; i < dSize; i++)\r
+ List<jalviewSourceI> srcs=sourceRegistry.getSources();\r
+ for (jalviewSourceI ds : srcs)\r
{\r
- ds = dasSources[i];\r
- DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
\r
- if (dcs.length == 0 && ds.getCapabilities().length == 0\r
+ VERSION v = ds.getVersion();\r
+ List<COORDINATES> coords = v.getCOORDINATES();\r
+ if (ds.isLocal() || ((coords == null || coords.size() == 0)\r
&& filter1.getSelectedIndex() == 0\r
&& filter2.getSelectedIndex() == 0\r
- && filter3.getSelectedIndex() == 0)\r
+ && filter3.getSelectedIndex() == 0))\r
{\r
// THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT\r
// HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT\r
// IS ADDED FROM THE REGISTRY\r
- names.add(ds.getNickname());\r
- selected.add(new Boolean(selectedSources.contains(ds.getNickname())));\r
+ names.add(ds.getTitle());\r
+ selected.add(new Boolean(selectedSources.contains(ds.getTitle())));\r
continue;\r
}\r
\r
- if (!selectedInList(dummyFeatureList, ds.getCapabilities())\r
+ if (!selectedInList(dummyFeatureList, ds.getCapabilityList(v))\r
|| !selectedInList(filter3.getSelectedValues(),\r
- ds.getLabels()))\r
+ ds.getLabelsFor(v)))\r
{\r
continue;\r
}\r
\r
- for (int j = 0; j < dcs.length; j++)\r
+ for (int j = 0; j < coords.size(); j++)\r
{\r
if (selectedInList(filter1.getSelectedValues(), new String[]\r
- { dcs[j].getName() })\r
+ { coords.get(j).getAuthority() })\r
&& selectedInList(filter2.getSelectedValues(), new String[]\r
- { dcs[j].getCategory() }))\r
+ { coords.get(j).getSource() }))\r
{\r
- names.add(ds.getNickname());\r
- selected.add(new Boolean(selectedSources.contains(ds\r
- .getNickname())));\r
+ names.add(ds.getTitle());\r
+ selected.add(new Boolean(selectedSources.contains(ds.getTitle())));\r
break;\r
}\r
}\r
}\r
\r
- dSize = names.size();\r
+ int dSize = names.size();\r
Object[][] data = new Object[dSize][2];\r
for (int d = 0; d < dSize; d++)\r
{\r
refreshTableData(data);\r
}\r
\r
- boolean selectedInList(Object[] selection, String[] items)\r
+ private boolean selectedInList(Object[] selection, String[] items)\r
{\r
for (int i = 0; i < selection.length; i++)\r
{\r
{\r
return true;\r
}\r
-\r
+ if (items==null || items.length==0)\r
+ {\r
+ return false;\r
+ }\r
+ String sel=(items[0].startsWith("das1:") ? "das1:":"")+selection[i];\r
for (int j = 0; j < items.length; j++)\r
{\r
- if (selection[i].equals(items[j]))\r
+ if (sel.equals(items[j]))\r
{\r
return true;\r
}\r
{\r
selectedSources.addElement(st.nextToken());\r
}\r
-\r
- Vector _localSources = jalview.bin.Cache.getLocalDasSources();\r
- if (_localSources != null)\r
- {\r
- if (localSources == null)\r
- {\r
- localSources = new Hashtable();\r
- }\r
- Enumeration sources = _localSources.elements();\r
- while (sources.hasMoreElements())\r
- {\r
- Das1Source source = (Das1Source) sources.nextElement();\r
- localSources.put(source.getNickname(), source);\r
- }\r
- }\r
}\r
\r
public void reset_actionPerformed(ActionEvent e)\r
{\r
- registryURL.setText(DEFAULT_REGISTRY);\r
+ registryURL.setText(sourceRegistry.getDasRegistryURL());\r
}\r
\r
/**\r
properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE,\r
sb.toString());\r
\r
- if (localSources != null)\r
- {\r
- sb = new StringBuffer();\r
- Enumeration en = localSources.keys();\r
- while (en.hasMoreElements())\r
- {\r
- String token = en.nextElement().toString();\r
- sb.append(token\r
- + "|"\r
- + (((DasSource) localSources.get(token))\r
- .hasCapability("sequence") ? "sequence:" : "")\r
- + ((DasSource) localSources.get(token)).getUrl() + "\t");\r
- }\r
-\r
- properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE,\r
- sb.toString());\r
- }\r
-\r
+ String sourceprop = sourceRegistry.getLocalSourceString();\r
+ properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sourceprop);\r
}\r
\r
class DASTableModel extends AbstractTableModel\r
}\r
});\r
thr.start();\r
- while (loadingDasSources || dasSources == null)\r
+ while (loadingDasSources || sourceRegistry == null)\r
{\r
try\r
{\r
}\r
}\r
\r
- public Vector resolveSourceNicknames(Vector sources)\r
- {\r
-\r
- Vector resolved = new Vector();\r
- if (sources != null)\r
- {\r
- for (int i = 0; i < dasSources.length; i++)\r
- {\r
- if (sources.contains(dasSources[i].getNickname()))\r
- {\r
- if (!resolved.contains(dasSources[i]))\r
- {\r
- resolved.addElement(dasSources[i]);\r
- }\r
- }\r
- }\r
- }\r
- return resolved;\r
- }\r
-\r
/**\r
* disable or enable the buttons on the source browser\r
* \r
import java.io.*;
import java.util.*;
+import java.util.List;
import java.awt.*;
import java.awt.event.*;
-import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import jalview.io.*;
import jalview.schemes.AnnotationColourGradient;
import jalview.schemes.GraduatedColor;
+import jalview.ws.dbsources.das.api.jalviewSourceI;
public class FeatureSettings extends JPanel
{
* @param checkDbRefs
* @param promptFetchDbRefs
*/
- private void doDasFeatureFetch(Vector selectedSources,
+ private void doDasFeatureFetch(List<jalviewSourceI> selectedSources,
boolean checkDbRefs, boolean promptFetchDbRefs)
{
SequenceI[] dataset, seqs;
* Vector of Strings to resolve to DAS source nicknames.
* @return sources that are present in source list.
*/
- public Vector resolveSourceNicknames(Vector sources)
+ public List<jalviewSourceI> resolveSourceNicknames(Vector sources)
{
- return dassourceBrowser.resolveSourceNicknames(sources);
+ return dassourceBrowser.sourceRegistry.resolveSourceNicknames(sources);
}
/**
public void fetchDasFeatures(Vector sources, boolean block)
{
initDasSources();
- Vector resolved = resolveSourceNicknames(sources);
+ List<jalviewSourceI> resolved = dassourceBrowser.sourceRegistry.resolveSourceNicknames(sources);
if (resolved.size() == 0)
{
resolved = dassourceBrowser.getSelectedSources();
}
if (resolved.size() > 0)
{
- final Vector dassources = resolved;
+ final List<jalviewSourceI> dassources = resolved;
fetchDAS.setEnabled(false);
// cancelDAS.setEnabled(true); doDasFetch does this.
Runnable fetcher = new Runnable()
*/
package jalview.gui;
-import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
-import MCview.*;
import jalview.datamodel.*;
-import jalview.datamodel.xdb.embl.*;
-import java.io.File;
import jalview.io.*;
-import jalview.ws.DBRefFetcher;
-import jalview.ws.ebi.EBIFetchClient;
-import jalview.ws.seqfetcher.ASequenceFetcher;
+import jalview.ws.dbsources.das.api.DasSourceRegistryI;
import jalview.ws.seqfetcher.DbSourceProxy;
-import java.awt.Rectangle;
import java.awt.BorderLayout;
-import java.awt.Dimension;
public class SequenceFetcher extends JPanel implements Runnable
{
private static jalview.ws.SequenceFetcher sfetch = null;
- private static String dasRegistry = null;
+ private static DasSourceRegistryI dasRegistry = null;
private static boolean _initingFetcher = false;
}
}
if (sfetch == null
- || dasRegistry != DasSourceBrowser.getDasRegistryURL())
+ || dasRegistry != jalview.bin.Cache.getDasSourceRegistry())
{
_initingFetcher = true;
initingThread = Thread.currentThread();
guiWindow.setProgressBar("Initialising Sequence Database Fetchers",
Thread.currentThread().hashCode());
}
- dasRegistry = DasSourceBrowser.getDasRegistryURL();
+ dasRegistry = jalview.bin.Cache.getDasSourceRegistry();
+ dasRegistry.refreshSources();
+
jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
if (guiWindow != null)
{
import jalview.gui.Desktop;\r
import jalview.gui.IProgressIndicator;\r
import jalview.gui.OOMWarning;\r
+import jalview.ws.dbsources.das.api.jalviewSourceI;\r
\r
import java.lang.reflect.Array;\r
import java.util.Enumeration;\r
import java.util.StringTokenizer;\r
import java.util.Vector;\r
\r
-import org.biojava.dasobert.dasregistry.DasSource;\r
-\r
import uk.ac.ebi.picr.model.UPEntry;\r
\r
/**\r
{\r
// af.featureSettings_actionPerformed(null);\r
String[] defdb = null, otherdb = sfetcher\r
- .getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);\r
+ .getDbInstances(jalview.ws.dbsources.das.datamodel.DasSequenceSource.class);\r
Vector selsources = new Vector(), dasselsrc = (af.featureSettings != null) ? af.featureSettings\r
.getSelectedSources() : new jalview.gui.DasSourceBrowser()\r
.getSelectedSources();\r
Enumeration en = dasselsrc.elements();\r
while (en.hasMoreElements())\r
{\r
- DasSource src = (DasSource) en.nextElement();\r
- selsources.addElement(src.getNickname());\r
+ jalviewSourceI src = (jalviewSourceI) en.nextElement();\r
+ selsources.addElement(src.getTitle());\r
}\r
int osel = 0;\r
for (int o = 0; otherdb != null && o < otherdb.length; o++)\r
}\r
// append additional sources\r
String[] otherdb = sfetcher\r
- .getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);\r
+ .getDbInstances(jalview.ws.dbsources.das.datamodel.DasSequenceSource.class);\r
if (otherdb != null && otherdb.length > 0)\r
{\r
String[] newsrc = new String[dbSources.length + otherdb.length];\r
*/\r
package jalview.ws;\r
\r
-import java.net.*;\r
-import java.util.*;\r
-\r
-import javax.swing.*;\r
-\r
-import org.biojava.dasobert.das.*;\r
-import org.biojava.dasobert.das2.*;\r
-import org.biojava.dasobert.das2.io.*;\r
-import org.biojava.dasobert.dasregistry.*;\r
-import org.biojava.dasobert.eventmodel.*;\r
import jalview.bin.Cache;\r
-import jalview.datamodel.*;\r
-import jalview.gui.*;\r
+import jalview.datamodel.DBRefEntry;\r
+import jalview.datamodel.SequenceFeature;\r
+import jalview.datamodel.SequenceI;\r
+import jalview.gui.AlignFrame;\r
+import jalview.gui.Desktop;\r
+import jalview.gui.FeatureSettings;\r
import jalview.util.UrlLink;\r
+import jalview.ws.dbsources.das.api.DasSourceRegistryI;\r
+import jalview.ws.dbsources.das.api.jalviewSourceI;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Enumeration;\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+import java.util.StringTokenizer;\r
+import java.util.Vector;\r
+\r
+import javax.swing.JOptionPane;\r
+\r
+import org.biodas.jdas.client.adapters.features.DasGFFAdapter;\r
+import org.biodas.jdas.client.adapters.features.DasGFFAdapter.GFFAdapter;\r
+import org.biodas.jdas.client.threads.FeaturesClientMultipleSources;\r
+import org.biodas.jdas.schema.features.ERRORSEGMENT;\r
+import org.biodas.jdas.schema.features.FEATURE;\r
+import org.biodas.jdas.schema.features.LINK;\r
+import org.biodas.jdas.schema.features.SEGMENT;\r
+import org.biodas.jdas.schema.features.TYPE;\r
+import org.biodas.jdas.schema.features.UNKNOWNFEATURE;\r
+import org.biodas.jdas.schema.features.UNKNOWNSEGMENT;\r
+import org.biodas.jdas.schema.sources.COORDINATES;\r
\r
/**\r
* DOCUMENT ME!\r
\r
StringBuffer sbuffer = new StringBuffer();\r
\r
- Vector selectedSources;\r
+ List<jalviewSourceI> selectedSources;\r
\r
boolean cancelled = false;\r
\r
\r
long startTime;\r
\r
+ private DasSourceRegistryI sourceRegistry;\r
+\r
/**\r
* Creates a new SequenceFeatureFetcher object. Uses default\r
* \r
}\r
\r
public DasSequenceFeatureFetcher(SequenceI[] oursequences,\r
- FeatureSettings fsettings, Vector ourselectedSources,\r
+ FeatureSettings fsettings, List<jalviewSourceI> selectedSources2,\r
boolean checkDbrefs, boolean promptFetchDbrefs)\r
{\r
- this.selectedSources = new Vector();\r
- Enumeration sources = ourselectedSources.elements();\r
+ this.selectedSources = new ArrayList<jalviewSourceI>();\r
// filter both sequences and sources to eliminate duplicates\r
- while (sources.hasMoreElements())\r
+ for (jalviewSourceI src : selectedSources2)\r
{\r
- Object src = sources.nextElement();\r
if (!selectedSources.contains(src))\r
{\r
- selectedSources.addElement(src);\r
+ selectedSources.add(src);\r
}\r
;\r
}\r
af.setShowSeqFeatures(true);\r
}\r
int uniprotCount = 0;\r
- for (int i = 0; i < selectedSources.size(); i++)\r
+ for (jalviewSourceI source : selectedSources)\r
{\r
- DasSource source = (DasSource) selectedSources.elementAt(i);\r
- DasCoordinateSystem[] coords = source.getCoordinateSystem();\r
- for (int c = 0; c < coords.length; c++)\r
+ for (COORDINATES coords : source.getVersion().getCOORDINATES())\r
{\r
// TODO: match UniProt coord system canonically (?) - does\r
// UniProt==uniprot==UNIPROT ?\r
- if (coords[c].getName().indexOf("UniProt") > -1)\r
+ if (coords.getAuthority().toLowerCase().equals("uniprot"))\r
{\r
uniprotCount++;\r
break;\r
}\r
else\r
{\r
- startFetching();\r
+ _startFetching();\r
}\r
}\r
else\r
{\r
- startFetching();\r
+ _startFetching();\r
}\r
\r
}\r
-\r
+ private void _startFetching()\r
+ {\r
+ new Thread(new FetchSeqFeatures()).start();\r
+ }\r
+ class FetchSeqFeatures implements Runnable\r
+ {\r
+ public void run()\r
+ {\r
+ startFetching();\r
+ setGuiFetchComplete();\r
+ }\r
+ }\r
class FetchDBRefs implements Runnable\r
{\r
public void run()\r
{\r
new DBRefFetcher(sequences, af).fetchDBRefs(true);\r
startFetching();\r
+ setGuiFetchComplete();\r
}\r
}\r
\r
/**\r
- * Spawns a number of dasobert Fetcher threads to add features to sequences in\r
- * the dataset\r
+ * Spawns Fetcher threads to add features to sequences in the dataset\r
*/\r
void startFetching()\r
{\r
{\r
af.setProgressBar("Fetching DAS Sequence Features", startTime);\r
}\r
-\r
+ if (sourceRegistry == null)\r
+ {\r
+ sourceRegistry = Cache.getDasSourceRegistry();\r
+ }\r
if (selectedSources == null || selectedSources.size() == 0)\r
{\r
try\r
{\r
- DasSource[] sources = new jalview.gui.DasSourceBrowser()\r
- .getDASSource();\r
-\r
+ jalviewSourceI[] sources = sourceRegistry.getSources().toArray(\r
+ new jalviewSourceI[0]);\r
String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",\r
"uniprot");\r
StringTokenizer st = new StringTokenizer(active, "\t");\r
token = st.nextToken();\r
for (int i = 0; i < sources.length; i++)\r
{\r
- if (sources[i].getNickname().equals(token))\r
+ if (sources[i].getTitle().equals(token))\r
{\r
- selectedSources.addElement(sources[i]);\r
+ selectedSources.add(sources[i]);\r
break;\r
}\r
}\r
}\r
\r
sourcesRemaining = selectedSources.size();\r
+ FeaturesClientMultipleSources fc = new FeaturesClientMultipleSources();\r
+ fc.setConnProps(sourceRegistry.getSessionHandler());\r
// Now sending requests one at a time to each server\r
- for (int sourceIndex = 0; sourceIndex < selectedSources.size()\r
- && !cancelled; sourceIndex++)\r
+ ArrayList<jalviewSourceI> srcobj = new ArrayList<jalviewSourceI>();\r
+ ArrayList<String> src = new ArrayList<String>();\r
+ List<List<String>> ids = new ArrayList<List<String>>();\r
+ List<List<DBRefEntry>> idobj = new ArrayList<List<DBRefEntry>>();\r
+ List<Map<String, SequenceI>> sqset = new ArrayList<Map<String, SequenceI>>();\r
+ for (jalviewSourceI _sr : selectedSources)\r
+ {\r
+\r
+ Map<String, SequenceI> slist = new HashMap<String, SequenceI>();\r
+ List<DBRefEntry> idob = new ArrayList<DBRefEntry>();\r
+ List<String> qset = new ArrayList<String>();\r
+\r
+ for (SequenceI seq : sequences)\r
+ {\r
+ Object[] idset = nextSequence(_sr, seq);\r
+ if (idset != null)\r
+ {\r
+ List<DBRefEntry> _idob = (List<DBRefEntry>) idset[0];\r
+ List<String> _qset = (List<String>) idset[1];\r
+ if (_idob.size() > 0)\r
+ {\r
+ // add sequence's ref for each id derived from it\r
+ // (space inefficient, but most unambiguous)\r
+ // could replace with hash with _qset values as keys.\r
+ Iterator<DBRefEntry> dbobj = _idob.iterator();\r
+ for (String q : _qset)\r
+ {\r
+ SequenceI osq = slist.get(q);\r
+ DBRefEntry dr = dbobj.next();\r
+ if (osq != null && osq != seq)\r
+ {\r
+ // skip - non-canonical query\r
+ }\r
+ else\r
+ {\r
+ idob.add(dr);\r
+ qset.add(q);\r
+ slist.put(q, seq);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if (idob.size() > 0)\r
+ {\r
+ srcobj.add(_sr);\r
+ src.add(_sr.getSourceURL());\r
+ ids.add(qset);\r
+ idobj.add(idob);\r
+ sqset.add(slist);\r
+ }\r
+ }\r
+ Map<String, Map<List<String>, Exception>> errors = new HashMap<String, Map<List<String>, Exception>>();\r
+ Map<String, Map<List<String>, DasGFFAdapter>> results = new HashMap<String, Map<List<String>, DasGFFAdapter>>();\r
+ fc.fetchData(src, ids, false, results, errors);\r
+ fc.shutDown();\r
+ while (!fc.isTerminated())\r
+ {\r
+ try\r
+ {\r
+ Thread.sleep(200);\r
+ } catch (InterruptedException x)\r
+ {\r
+\r
+ }\r
+ }\r
+ Iterator<List<String>> idset = ids.iterator();\r
+ Iterator<List<DBRefEntry>> idobjset = idobj.iterator();\r
+ Iterator<Map<String, SequenceI>> seqset = sqset.iterator();\r
+ for (jalviewSourceI source : srcobj)\r
+ {\r
+ processResponse(seqset.next(), source, idset.next(), idobjset.next(),\r
+ results.get(source.getSourceURL()),\r
+ errors.get(source.getSourceURL()));\r
+ }\r
+ }\r
+\r
+ private void processResponse(Map<String, SequenceI> sequencemap,\r
+ jalviewSourceI jvsource, List<String> ids,\r
+ List<DBRefEntry> idobj, Map<List<String>, DasGFFAdapter> results,\r
+ Map<List<String>, Exception> errors)\r
+ {\r
+ Set<SequenceI> sequences = new HashSet<SequenceI>();\r
+ String source = jvsource.getSourceURL();\r
+ // process features\r
+ DasGFFAdapter result = (results == null) ? null : results.get(ids);\r
+ Exception error = (errors == null) ? null : errors.get(ids);\r
+ if (result == null)\r
+ {\r
+ debug("das source " + source + " could not be contacted. "\r
+ + (error == null ? "" : error.toString()));\r
+ }\r
+ else\r
{\r
- DasSource dasSource = (DasSource) selectedSources\r
- .elementAt(sourceIndex);\r
\r
- nextSequence(dasSource, sequences[0]);\r
+ GFFAdapter gff = result.getGFF();\r
+ List<SEGMENT> segments = gff.getSegments();\r
+ List<ERRORSEGMENT> errorsegs = gff.getErrorSegments();\r
+ List<UNKNOWNFEATURE> unkfeats = gff.getUnknownFeatures();\r
+ List<UNKNOWNSEGMENT> unksegs = gff.getUnknownSegments();\r
+ debug("das source " + source + " returned " + gff.getTotal()\r
+ + " responses. " + (errorsegs != null ? errorsegs.size() : 0)\r
+ + " were incorrect segment queries, "\r
+ + (unkfeats != null ? unkfeats.size() : 0)\r
+ + " were unknown features "\r
+ + (unksegs != null ? unksegs.size() : 0)\r
+ + " were unknown segments and "\r
+ + (segments != null ? segments.size() : 0)\r
+ + " were segment responses.");\r
+ Iterator<DBRefEntry> dbr = idobj.iterator();\r
+ if (segments != null)\r
+ {\r
+ for (SEGMENT seg : segments)\r
+ {\r
+ String id = seg.getId();\r
+ DBRefEntry dbref = idobj.get(ids.indexOf(id));\r
+ SequenceI sequence = sequencemap.get(id);\r
+ boolean added = false;\r
+ sequences.add(sequence);\r
+\r
+ for (FEATURE feat : seg.getFEATURE())\r
+ {\r
+ // standard DAS feature-> jalview sequence feature transformation\r
+ SequenceFeature f = newSequenceFeature(feat, jvsource.getTitle());\r
+ if (!parseSeqFeature(sequence, f, feat, jvsource))\r
+ {\r
+ if (dbref.getMap() != null && f.getBegin() > 0\r
+ && f.getEnd() > 0)\r
+ {\r
+ debug("mapping from " + f.getBegin() + " - " + f.getEnd());\r
+ SequenceFeature vf[] = null;\r
+\r
+ try\r
+ {\r
+ vf = dbref.getMap().locateFeature(f);\r
+ } catch (Exception ex)\r
+ {\r
+ Cache.log\r
+ .info("Error in 'experimental' mapping of features. Please try to reproduce and then report info to jalview-discuss@jalview.org.");\r
+ Cache.log.info("Mapping feature from " + f.getBegin()\r
+ + " to " + f.getEnd() + " in dbref "\r
+ + dbref.getAccessionId() + " in "\r
+ + dbref.getSource());\r
+ Cache.log.info("using das Source " + source);\r
+ Cache.log.info("Exception", ex);\r
+ }\r
+\r
+ if (vf != null)\r
+ {\r
+ for (int v = 0; v < vf.length; v++)\r
+ {\r
+ debug("mapping to " + v + ": " + vf[v].getBegin()\r
+ + " - " + vf[v].getEnd());\r
+ sequence.addSequenceFeature(vf[v]);\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ sequence.addSequenceFeature(f);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ featuresAdded(sequences);\r
+ }\r
+ else\r
+ {\r
+ // System.out.println("No features found for " + seq.getName()\r
+ // + " from: " + e.getDasSource().getNickname());\r
+ }\r
}\r
}\r
\r
\r
int sourcesRemaining = 0;\r
\r
- void responseComplete(DasSource dasSource, SequenceI seq)\r
- {\r
- if (seq != null)\r
- {\r
- for (int seqIndex = 0; seqIndex < sequences.length - 1 && !cancelled; seqIndex++)\r
- {\r
- if (sequences[seqIndex] == seq)\r
- {\r
- nextSequence(dasSource, sequences[++seqIndex]);\r
- return;\r
- }\r
- }\r
- }\r
-\r
- sourcesRemaining--;\r
-\r
- if (sourcesRemaining == 0)\r
- {\r
- System.err.println("Fetching Complete.");\r
- setGuiFetchComplete();\r
- }\r
-\r
- }\r
-\r
private void setGuiFetchComplete()\r
{\r
\r
}\r
}\r
\r
- void featuresAdded(SequenceI seq)\r
+ void featuresAdded(Set<SequenceI> seqs)\r
{\r
if (af == null)\r
{\r
int index;\r
for (index = start; index < end; index++)\r
{\r
- if (seq == af.getViewport().getAlignment().getSequenceAt(index)\r
- .getDatasetSequence())\r
+ for (SequenceI seq : seqs)\r
{\r
- af.alignPanel.paintAlignment(true);\r
- break;\r
+ if (seq == af.getViewport().getAlignment().getSequenceAt(index)\r
+ .getDatasetSequence())\r
+ {\r
+ af.alignPanel.paintAlignment(true);\r
+ index = end;\r
+ break;\r
+ }\r
}\r
}\r
}\r
\r
- void nextSequence(DasSource dasSource, SequenceI seq)\r
+ Object[] nextSequence(jalviewSourceI dasSource, SequenceI seq)\r
{\r
if (cancelled)\r
- return;\r
+ return null;\r
DBRefEntry[] uprefs = jalview.util.DBRefUtils.selectRefs(\r
seq.getDBRef(), new String[]\r
{\r
// TODO: minimal list of DAS queries to make by querying with untyped ID if\r
// distinct from any typed IDs\r
\r
+ List<DBRefEntry> ids = new ArrayList<DBRefEntry>();\r
+ List<String> qstring = new ArrayList<String>();\r
boolean dasCoordSysFound = false;\r
\r
if (uprefs != null)\r
// do any of these ids match the source's coordinate system ?\r
for (int j = 0; !dasCoordSysFound && j < uprefs.length; j++)\r
{\r
- DasCoordinateSystem cs[] = dasSource.getCoordinateSystem();\r
\r
- for (int csIndex = 0; csIndex < cs.length && !dasCoordSysFound; csIndex++)\r
+ for (COORDINATES csys : dasSource.getVersion().getCOORDINATES())\r
{\r
- if (cs.length > 0\r
- && jalview.util.DBRefUtils.isDasCoordinateSystem(\r
- cs[csIndex].getName(), uprefs[j]))\r
+ if (jalview.util.DBRefUtils.isDasCoordinateSystem(\r
+ csys.getAuthority(), uprefs[j]))\r
{\r
debug("Launched fetcher for coordinate system "\r
- + cs[0].getName());\r
+ + csys.getAuthority());\r
// Will have to pass any mapping information to the fetcher\r
// - the start/end for the DBRefEntry may not be the same as the\r
// sequence's start/end\r
\r
System.out.println(seq.getName() + " "\r
+ (seq.getDatasetSequence() == null) + " "\r
- + dasSource.getUrl());\r
+ + csys.getUri());\r
\r
dasCoordSysFound = true; // break's out of the loop\r
- createFeatureFetcher(seq, dasSource, uprefs[j]);\r
+ ids.add(uprefs[j]);\r
+ qstring.add(uprefs[j].getAccessionId());\r
}\r
else\r
- System.out.println("IGNORE " + cs[csIndex].getName());\r
+ System.out.println("IGNORE " + csys.getAuthority());\r
}\r
}\r
}\r
}\r
if (id != null)\r
{\r
+ DBRefEntry dbre = new DBRefEntry();\r
+ dbre.setAccessionId(id);\r
// Should try to call a general feature fetcher that\r
// queries many sources with name to discover applicable ID references\r
- createFeatureFetcher(seq, dasSource, id);\r
- }\r
- }\r
-\r
- }\r
-\r
- /**\r
- * fetch and add das features to a sequence using the given source URL and\r
- * compatible DbRef id. new features are mapped using the DbRef mapping to the\r
- * local coordinate system.\r
- * \r
- * @param seq\r
- * @param SourceUrl\r
- * @param dbref\r
- */\r
- protected void createFeatureFetcher(final SequenceI seq,\r
- final DasSource dasSource, final DBRefEntry dbref)\r
- {\r
-\r
- // ////////////\r
- // / fetch DAS features\r
- final Das1Source source = new Das1Source();\r
- source.setUrl(dasSource.getUrl());\r
- source.setNickname(dasSource.getNickname());\r
- if (dbref == null || dbref.getAccessionId() == null\r
- || dbref.getAccessionId().length() < 1)\r
- {\r
- responseComplete(dasSource, seq); // reduce thread count anyhow\r
- return;\r
- }\r
- debug("new Das Feature Fetcher for " + dbref.getSource() + ":"\r
- + dbref.getAccessionId() + " querying " + dasSource.getUrl());\r
- FeatureThread fetcher = new FeatureThread(dbref.getAccessionId()\r
- // + ":" + start + "," + end,\r
- , source);\r
-\r
- fetcher.addFeatureListener(new FeatureListener()\r
- {\r
- public void comeBackLater(FeatureEvent e)\r
- {\r
- responseComplete(dasSource, seq);\r
- debug("das source " + e.getSource().getNickname()\r
- + " asked us to come back in " + e.getComeBackLater()\r
- + " secs.");\r
- }\r
-\r
- public void newFeatures(FeatureEvent e)\r
- {\r
-\r
- Das1Source ds = e.getSource();\r
-\r
- Map[] features = e.getFeatures();\r
- // add features to sequence\r
- debug("das source " + ds.getUrl() + " returned " + features.length\r
- + " features");\r
-\r
- if (features.length > 0)\r
- {\r
- for (int i = 0; i < features.length; i++)\r
- {\r
- // standard DAS feature-> jalview sequence feature transformation\r
- SequenceFeature f = newSequenceFeature(features[i],\r
- source.getNickname());\r
- if (!parseSeqFeature(seq, f, features[i], source))\r
- {\r
- if (dbref.getMap() != null && f.getBegin() > 0\r
- && f.getEnd() > 0)\r
- {\r
- debug("mapping from " + f.getBegin() + " - " + f.getEnd());\r
- SequenceFeature vf[] = null;\r
-\r
- try\r
- {\r
- vf = dbref.getMap().locateFeature(f);\r
- } catch (Exception ex)\r
- {\r
- Cache.log\r
- .info("Error in 'experimental' mapping of features. Please try to reproduce and then report info to jalview-discuss@jalview.org.");\r
- Cache.log.info("Mapping feature from " + f.getBegin()\r
- + " to " + f.getEnd() + " in dbref "\r
- + dbref.getAccessionId() + " in "\r
- + dbref.getSource());\r
- Cache.log.info("using das Source " + ds.getUrl());\r
- Cache.log.info("Exception", ex);\r
- }\r
-\r
- if (vf != null)\r
- {\r
- for (int v = 0; v < vf.length; v++)\r
- {\r
- debug("mapping to " + v + ": " + vf[v].getBegin()\r
- + " - " + vf[v].getEnd());\r
- seq.addSequenceFeature(vf[v]);\r
- }\r
- }\r
- }\r
- else\r
- {\r
- seq.addSequenceFeature(f);\r
- }\r
- }\r
- }\r
- featuresAdded(seq);\r
- }\r
- else\r
- {\r
- // System.out.println("No features found for " + seq.getName()\r
- // + " from: " + e.getDasSource().getNickname());\r
- }\r
- responseComplete(dasSource, seq);\r
-\r
+ ids.add(dbre);\r
+ qstring.add(dbre.getAccessionId());\r
}\r
}\r
\r
- );\r
-\r
- fetcher.start();\r
- }\r
-\r
- protected void createFeatureFetcher(final SequenceI seq,\r
- final DasSource dasSource, String id)\r
- {\r
- // ////////////\r
- // / fetch DAS features\r
- final Das1Source source = new Das1Source();\r
- source.setUrl(dasSource.getUrl());\r
- source.setNickname(dasSource.getNickname());\r
-\r
- if (id != null)\r
- {\r
- id = id.trim();\r
- }\r
- if (id != null && id.length() > 0)\r
- {\r
- debug("new Das Feature Fetcher for " + id + " querying "\r
- + dasSource.getUrl());\r
- FeatureThread fetcher = new FeatureThread(id\r
- // + ":" + start + "," + end,\r
- , source);\r
-\r
- fetcher.addFeatureListener(new FeatureListener()\r
- {\r
- public void comeBackLater(FeatureEvent e)\r
- {\r
- responseComplete(dasSource, seq);\r
- debug("das source " + e.getSource().getNickname()\r
- + " asked us to come back in " + e.getComeBackLater()\r
- + " secs.");\r
- }\r
-\r
- public void newFeatures(FeatureEvent e)\r
- {\r
-\r
- Das1Source ds = e.getSource();\r
-\r
- Map[] features = e.getFeatures();\r
- // add features to sequence\r
- debug("das source " + ds.getUrl() + " returned "\r
- + features.length + " features");\r
-\r
- if (features.length > 0)\r
- {\r
- for (int i = 0; i < features.length; i++)\r
- {\r
- // standard DAS feature-> jalview sequence feature transformation\r
- SequenceFeature f = newSequenceFeature(features[i],\r
- source.getNickname());\r
- if (!parseSeqFeature(seq, f, features[i], source))\r
- {\r
- // just add as a simple sequence feature\r
- seq.addSequenceFeature(f);\r
- }\r
- }\r
-\r
- featuresAdded(seq);\r
- }\r
- else\r
- {\r
- // System.out.println("No features found for " + seq.getName()\r
- // + " from: " + e.getDasSource().getNickname());\r
- }\r
- responseComplete(dasSource, seq);\r
-\r
- }\r
- }\r
-\r
- );\r
-\r
- fetcher.start();\r
- }\r
- else\r
- {\r
- // invalid fetch - indicate it is finished.\r
- debug("Skipping empty ID for querying " + dasSource.getUrl());\r
- responseComplete(dasSource, seq);\r
- }\r
+ return new Object[]\r
+ { ids, qstring };\r
}\r
\r
/**\r
* @return true if feature was consumed as another kind of annotation.\r
*/\r
protected boolean parseSeqFeature(SequenceI seq, SequenceFeature f,\r
- Map map, Das1Source source)\r
+ FEATURE feature, jalviewSourceI source)\r
{\r
SequenceI mseq = seq;\r
while (seq.getDatasetSequence() != null)\r
// try to parse the accession out\r
\r
DBRefEntry dbr = new DBRefEntry();\r
- dbr.setVersion(source.getNickname());\r
+ dbr.setVersion(source.getTitle());\r
StringTokenizer st = new StringTokenizer(f.getDescription(), ":");\r
if (st.hasMoreTokens())\r
{\r
/**\r
* creates a jalview sequence feature from a das feature document\r
* \r
- * @param dasfeature\r
+ * @param feat\r
* @return sequence feature object created using dasfeature information\r
*/\r
- SequenceFeature newSequenceFeature(Map dasfeature, String nickname)\r
+ SequenceFeature newSequenceFeature(FEATURE feat, String nickname)\r
{\r
- if (dasfeature == null)\r
+ if (feat == null)\r
{\r
return null;\r
}\r
* qName.equals("SCORE")\r
*/\r
String desc = new String();\r
- if (dasfeature.containsKey("NOTE"))\r
+ if (feat.getNOTE() != null)\r
{\r
- desc += (String) dasfeature.get("NOTE");\r
+ for (String note : feat.getNOTE())\r
+ {\r
+ desc += (String) note;\r
+ }\r
}\r
\r
int start = 0, end = 0;\r
\r
try\r
{\r
- start = Integer.parseInt(dasfeature.get("START").toString());\r
+ start = Integer.parseInt(feat.getSTART().toString());\r
} catch (Exception ex)\r
{\r
}\r
try\r
{\r
- end = Integer.parseInt(dasfeature.get("END").toString());\r
+ end = Integer.parseInt(feat.getEND().toString());\r
} catch (Exception ex)\r
{\r
}\r
try\r
{\r
- Object scr = dasfeature.get("SCORE");\r
+ Object scr = feat.getSCORE();\r
if (scr != null)\r
{\r
score = (float) Double.parseDouble(scr.toString());\r
}\r
\r
SequenceFeature f = new SequenceFeature(\r
- (String) dasfeature.get("TYPE"), desc, start, end, score,\r
+ getTypeString(feat.getTYPE()), desc, start, end, score,\r
nickname);\r
\r
- if (dasfeature.containsKey("LINK"))\r
+ if (feat.getLINK() != null)\r
{\r
- // Do not put feature extent in link text for non-positional features\r
- if (f.begin == 0 && f.end == 0)\r
- {\r
- f.addLink(f.getType() + "|" + dasfeature.get("LINK"));\r
- }\r
- else\r
+ for (LINK link : feat.getLINK())\r
{\r
- f.addLink(f.getType() + " " + f.begin + "_" + f.end + "|"\r
- + dasfeature.get("LINK"));\r
+ // Do not put feature extent in link text for non-positional features\r
+ if (f.begin == 0 && f.end == 0)\r
+ {\r
+ f.addLink(f.getType() + " " + link.getContent() + "|"\r
+ + link.getHref());\r
+ }\r
+ else\r
+ {\r
+ f.addLink(f.getType() + " " + f.begin + "_" + f.end + " "\r
+ + link.getContent() + "|" + link.getHref());\r
+ }\r
}\r
}\r
\r
System.out.println("ERRR " + e);\r
e.printStackTrace();\r
System.out.println("############");\r
- debug("Failed to parse " + dasfeature.toString(), e);\r
+ debug("Failed to parse " + feat.toString(), e);\r
return null;\r
}\r
}\r
\r
- /**\r
- * query the default DAS Source Registry for sources. Uses value of jalview\r
- * property DAS_REGISTRY_URL and the DasSourceBrowser.DEFAULT_REGISTRY if that\r
- * doesn't exist.\r
- * \r
- * @return list of sources\r
- */\r
- public static DasSource[] getDASSources()\r
- {\r
-\r
- String registryURL = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",\r
- DasSourceBrowser.DEFAULT_REGISTRY);\r
- return getDASSources(registryURL);\r
- }\r
-\r
- /**\r
- * query the given URL for DasSources.\r
- * \r
- * @param registryURL\r
- * return sources from registryURL\r
- */\r
- public static DasSource[] getDASSources(String registryURL)\r
+ private String getTypeString(TYPE type)\r
{\r
- DasSourceReaderImpl reader = new DasSourceReaderImpl();\r
-\r
- try\r
- {\r
- URL url = new URL(registryURL);\r
-\r
- DasSource[] sources = reader.readDasSource(url);\r
-\r
- List das1sources = new ArrayList();\r
- for (int i = 0; i < sources.length; i++)\r
- {\r
- DasSource ds = sources[i];\r
- if (ds instanceof Das2Source)\r
- {\r
- Das2Source d2s = (Das2Source) ds;\r
- if (d2s.hasDas1Capabilities())\r
- {\r
- Das1Source d1s = DasSourceConverter.toDas1Source(d2s);\r
- das1sources.add(d1s);\r
- }\r
-\r
- }\r
- else if (ds instanceof Das1Source)\r
- {\r
- das1sources.add((Das1Source) ds);\r
- }\r
- }\r
-\r
- return (Das1Source[]) das1sources.toArray(new Das1Source[das1sources\r
- .size()]);\r
- } catch (Exception ex)\r
- {\r
- System.err.println("Failed to contact DAS1 registry at "\r
- + registryURL);\r
- ex.printStackTrace();\r
- return null;\r
- }\r
+ return type.getContent();\r
}\r
\r
}\r
*/\r
package jalview.ws;\r
\r
-import java.util.ArrayList;\r
-import java.util.Enumeration;\r
-import java.util.Vector;\r
-\r
-import org.biojava.dasobert.das2.Das2Source;\r
-import org.biojava.dasobert.dasregistry.Das1Source;\r
-import org.biojava.dasobert.dasregistry.DasCoordinateSystem;\r
-import org.biojava.dasobert.dasregistry.DasSource;\r
-\r
import jalview.datamodel.Alignment;\r
import jalview.datamodel.AlignmentI;\r
import jalview.datamodel.DBRefSource;\r
import jalview.datamodel.SequenceI;\r
-import jalview.ws.dbsources.DasSequenceSource;\r
+import jalview.ws.dbsources.das.api.jalviewSourceI;\r
import jalview.ws.seqfetcher.ASequenceFetcher;\r
import jalview.ws.seqfetcher.DbSourceProxy;\r
\r
+import java.util.ArrayList;\r
+import java.util.Enumeration;\r
+import java.util.List;\r
+import java.util.Vector;\r
+\r
/**\r
* This is the the concrete implementation of the sequence retrieval interface\r
* and abstract class in jalview.ws.seqfetcher. This implements the run-time\r
for (int i = 0; i < srcs.length; i++)\r
{\r
String nm = getSourceProxy(srcs[i]).getDbName();\r
- if (getSourceProxy(srcs[i]) instanceof jalview.ws.dbsources.DasSequenceSource)\r
+ if (getSourceProxy(srcs[i]) instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)\r
{\r
if (nm.startsWith("das:"))\r
{\r
*/\r
public void registerDasSequenceSources()\r
{\r
- DasSource[] sources = jalview.ws.DasSequenceFeatureFetcher\r
- .getDASSources();\r
- if (sources != null)\r
- {\r
- for (int s = 0; sources != null && s < sources.length; s++)\r
- {\r
- addDasSequenceSource(sources[s]);\r
- }\r
- }\r
-\r
- Vector localsources = jalview.bin.Cache.getLocalDasSources();\r
- if (localsources != null)\r
- {\r
- for (Enumeration ls = localsources.elements(); ls.hasMoreElements();)\r
- {\r
- addDasSequenceSource((DasSource) ls.nextElement());\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Try to create and add a DasSequenceSource to the list of sources.\r
- * \r
- * @param source\r
- * @return null if no source was added, or the new DasSequenceSource created\r
- */\r
- DasSequenceSource addDasSequenceSource(DasSource source)\r
- {\r
- DasSequenceSource ds = null;\r
- Das1Source d1s = null;\r
- if (source.hasCapability("sequence"))\r
- {\r
- if (source instanceof Das2Source)\r
- {\r
- if (((Das2Source) source).hasDas1Capabilities())\r
- {\r
- try\r
- {\r
- d1s = org.biojava.dasobert.das2.DasSourceConverter\r
- .toDas1Source((Das2Source) source);\r
- } catch (Exception e)\r
- {\r
- System.err.println("Ignoring DAS2 sequence source "\r
- + source.getNickname()\r
- + " - couldn't map to Das1Source.\n");\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
- else\r
- {\r
- if (source instanceof Das1Source)\r
- {\r
- d1s = (Das1Source) source;\r
- }\r
- }\r
- }\r
- if (d1s != null)\r
+ // TODO: define a context as a registry provider (either desktop,\r
+ // jalview.bin.cache, or something else).\r
+ for (jalviewSourceI source : jalview.bin.Cache.getDasSourceRegistry().getSources())\r
{\r
- DasCoordinateSystem[] css = d1s.getCoordinateSystem();\r
- if (css == null || css.length == 0)\r
+ if (source.isSequenceSource())\r
{\r
- // TODO: query das source directly to identify coordinate system... or\r
- // have to make up a coordinate system\r
- css = new DasCoordinateSystem[]\r
- { new DasCoordinateSystem() };\r
- css[0].setName(d1s.getNickname());\r
- css[0].setUniqueId(d1s.getNickname());\r
- }\r
- for (int c = 0; c < css.length; c++)\r
- {\r
- try\r
+ List<DbSourceProxy> dassources = source.getSequenceSourceProxies();\r
+ for (DbSourceProxy seqsrc : dassources)\r
{\r
- addDbRefSourceImpl(ds = new DasSequenceSource("das:"\r
- + d1s.getNickname() + " (" + css[c].getName() + ")",\r
- css[c].getName(), d1s, css[c]));\r
- } catch (Exception e)\r
- {\r
- System.err.println("Ignoring sequence coord system " + c + " ("\r
- + css[c].getName() + ") for source " + d1s.getNickname()\r
- + "- threw exception when constructing fetcher.\n");\r
- e.printStackTrace();\r
+ addDbRefSourceImpl(seqsrc);\r
}\r
}\r
}\r
- return ds;\r
}\r
}\r
+++ /dev/null
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)\r
- * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle\r
- * \r
- * This file is part of Jalview.\r
- * \r
- * Jalview is free software: you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License \r
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
- * \r
- * Jalview is distributed in the hope that it will be useful, but \r
- * WITHOUT ANY WARRANTY; without even the implied warranty \r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
- * PURPOSE. See the GNU General Public License for more details.\r
- * \r
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package jalview.ws.dbsources;\r
-\r
-import java.util.Hashtable;\r
-\r
-import org.biojava.dasobert.das.SequenceThread;\r
-import org.biojava.dasobert.das2.Das2Source;\r
-import org.biojava.dasobert.dasregistry.Das1Source;\r
-import org.biojava.dasobert.dasregistry.DasCoordinateSystem;\r
-import org.biojava.dasobert.dasregistry.DasSource;\r
-import org.biojava.dasobert.eventmodel.SequenceEvent;\r
-import org.biojava.dasobert.eventmodel.SequenceListener;\r
-\r
-import com.stevesoft.pat.Regex;\r
-\r
-import jalview.ws.dbsources.das.DasSequenceSourceListener;\r
-import jalview.ws.seqfetcher.*;\r
-import jalview.datamodel.AlignmentI;\r
-\r
-/**\r
- * an instance of this class is created for each unique DAS Sequence source (ie\r
- * one capable of handling the 'sequence' for a particular MapMaster)\r
- * \r
- * @author JimP\r
- * \r
- */\r
-public class DasSequenceSource extends DbSourceProxyImpl implements\r
- DbSourceProxy\r
-{\r
- protected Das1Source source = null;\r
-\r
- protected String dbname = "DASCS";\r
-\r
- protected String dbrefname = "das:source";\r
-\r
- protected DasCoordinateSystem coordsys = null;\r
-\r
- /**\r
- * create a new DbSource proxy for a DAS 1 source\r
- * \r
- * @param dbnbame\r
- * Human Readable Name to use when fetching from this source\r
- * @param dbrefname\r
- * DbRefName for DbRefs attached to sequences retrieved from this\r
- * source\r
- * @param source\r
- * Das1Source\r
- * @param coordsys\r
- * specific coordinate system to use for this source\r
- * @throws Exception\r
- * if source is not capable of the 'sequence' command\r
- */\r
- public DasSequenceSource(String dbname, String dbrefname,\r
- Das1Source source, DasCoordinateSystem coordsys) throws Exception\r
- {\r
- if (!source.hasCapability("sequence"))\r
- {\r
- throw new Exception("Source " + source.getNickname()\r
- + " does not support the sequence command.");\r
- }\r
- this.source = source;\r
- this.dbname = dbname;\r
- this.dbrefname = dbrefname;\r
- this.coordsys = coordsys;\r
- }\r
-\r
- public String getAccessionSeparator()\r
- {\r
- // cope with single sequences only\r
- return null;\r
- }\r
-\r
- public Regex getAccessionValidator()\r
- {\r
- /** ? * */\r
- return Regex.perlCode("\\S+");\r
- }\r
-\r
- public String getDbName()\r
- {\r
- // TODO: map to\r
- return dbname + " (DAS)";\r
- }\r
-\r
- public String getDbSource()\r
- {\r
- return dbrefname;\r
- }\r
-\r
- public String getDbVersion()\r
- {\r
- return coordsys.getVersion();\r
- }\r
-\r
- public AlignmentI getSequenceRecords(String queries) throws Exception\r
- {\r
- SequenceThread seqfetcher = new org.biojava.dasobert.das.SequenceThread(\r
- queries, source);\r
- DasSequenceSourceListener ourlistener = new DasSequenceSourceListener(\r
- this, queries);\r
- seqfetcher.addSequenceListener(ourlistener);\r
- seqfetcher.start();\r
- try\r
- {\r
- Thread.sleep(5);\r
- } catch (Exception e)\r
- {\r
- }\r
- ;\r
- while (ourlistener.isNotCalled() && seqfetcher.isAlive())\r
- {\r
- try\r
- {\r
- Thread.sleep(5);\r
- } catch (Exception e)\r
- {\r
- }\r
- ;\r
- }\r
- if (ourlistener.isNotCalled() || ourlistener.hasNoSequences())\r
- {\r
- System.err.println("Sequence Query to " + source.getNickname()\r
- + " with '" + queries + "' returned no sequences.");\r
- return null;\r
- }\r
- else\r
- {\r
- return ourlistener.getSequences();\r
- }\r
- }\r
-\r
- public String getTestQuery()\r
- {\r
- return coordsys.getTestCode();\r
- }\r
-\r
- public boolean isValidReference(String accession)\r
- {\r
- // TODO try to validate an accession against source\r
- // We don't really know how to do this without querying source\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * @return the source\r
- */\r
- public Das1Source getSource()\r
- {\r
- return source;\r
- }\r
-\r
- /**\r
- * @return the coordsys\r
- */\r
- public DasCoordinateSystem getCoordsys()\r
- {\r
- return coordsys;\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)\r
- * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle\r
- * \r
- * This file is part of Jalview.\r
- * \r
- * Jalview is free software: you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License \r
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
- * \r
- * Jalview is distributed in the hope that it will be useful, but \r
- * WITHOUT ANY WARRANTY; without even the implied warranty \r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
- * PURPOSE. See the GNU General Public License for more details.\r
- * \r
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package jalview.ws.dbsources.das;\r
-\r
-import jalview.datamodel.AlignmentI;\r
-import jalview.datamodel.Alignment;\r
-import jalview.datamodel.DBRefEntry;\r
-import jalview.datamodel.Sequence;\r
-import jalview.datamodel.SequenceI;\r
-import jalview.ws.dbsources.DasSequenceSource;\r
-\r
-import org.biojava.dasobert.eventmodel.SequenceEvent;\r
-import org.biojava.dasobert.eventmodel.SequenceListener;\r
-\r
-/**\r
- * Listen for sequence fetch events from a dasobert SequenceThread started with\r
- * a query string and collect sequences returned from the DAS sequence source.\r
- * \r
- * @author JimP\r
- * \r
- */\r
-public class DasSequenceSourceListener implements SequenceListener\r
-{\r
-\r
- String ourAccession = null;\r
-\r
- DasSequenceSource oursource = null;\r
-\r
- /**\r
- * \r
- * @param source\r
- * the DAS Sequence DbProxy object containing database details for\r
- * this source\r
- * @param query\r
- * the query string sent to the das source that we should be\r
- * listening for.\r
- */\r
- public DasSequenceSourceListener(DasSequenceSource source, String query)\r
- {\r
- oursource = source;\r
- ourAccession = query;\r
- }\r
-\r
- public void clearSelection()\r
- {\r
- // TODO Auto-generated method stub\r
-\r
- }\r
-\r
- java.util.Vector seqs = null;\r
-\r
- public void newSequence(SequenceEvent e)\r
- {\r
- if (!e.getAccessionCode().equals(ourAccession))\r
- {\r
- System.err\r
- .println("Warning - received sequence event for strange accession code ("\r
- + e.getAccessionCode()\r
- + ") - we expected "\r
- + ourAccession);\r
-\r
- return;\r
- }\r
- if (seqs == null)\r
- {\r
- if (e.getSequence().length() == 0)\r
- {\r
- System.err.println("Empty sequence returned for accession code ("\r
- + e.getAccessionCode() + ") from " + oursource.getDbName());\r
- called = true;\r
- noSequences = true;\r
- return;\r
- }\r
- seqs = new java.util.Vector();\r
- }\r
- Sequence sq = new Sequence(e.getAccessionCode(), e.getSequence());\r
- sq.addDBRef(new DBRefEntry(oursource.getDbSource(), oursource\r
- .getDbVersion() + ":" + e.getVersion(), e.getAccessionCode()));\r
- seqs.addElement(sq);\r
- called = true;\r
- }\r
-\r
- public void selectedSeqPosition(int position)\r
- {\r
- // TODO Auto-generated method stub\r
-\r
- }\r
-\r
- public void selectedSeqRange(int start, int end)\r
- {\r
- // TODO Auto-generated method stub\r
-\r
- }\r
-\r
- public void selectionLocked(boolean flag)\r
- {\r
- // TODO Auto-generated method stub\r
-\r
- }\r
-\r
- public void newObjectRequested(String accessionCode)\r
- {\r
- // TODO Auto-generated method stub\r
-\r
- }\r
-\r
- boolean noSequences = false;\r
-\r
- public void noObjectFound(String accessionCode)\r
- {\r
- if (accessionCode.equals(ourAccession))\r
- {\r
- noSequences = true;\r
- called = true;\r
- }\r
- }\r
-\r
- public boolean hasNoSequences()\r
- {\r
- return noSequences;\r
- }\r
-\r
- boolean called = false;\r
-\r
- public boolean isNotCalled()\r
- {\r
- return !called;\r
- }\r
-\r
- public AlignmentI getSequences()\r
- {\r
- if (noSequences || seqs != null && seqs.size() == 0)\r
- return null;\r
- SequenceI[] sqs = new SequenceI[seqs.size()];\r
- for (int i = 0, iSize = seqs.size(); i < iSize; i++)\r
- {\r
- sqs[i] = (SequenceI) seqs.elementAt(i);\r
- }\r
- Alignment al = new Alignment(sqs);\r
- if (oursource.getSource().hasCapability("features"))\r
- {\r
- java.util.Vector src = new java.util.Vector();\r
- src.addElement(oursource.getSource());\r
- new jalview.ws.DasSequenceFeatureFetcher(sqs, null, src, false, false);\r
- }\r
-\r
- return al;\r
- }\r
-\r
-}\r
--- /dev/null
+package jalview.ws.dbsources.das.api;
+
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.biodas.jdas.client.ConnectionPropertyProviderI;
+import org.biodas.jdas.client.threads.MultipleConnectionPropertyProviderI;
+import org.biodas.jdas.schema.sources.SOURCE;
+
+/**
+ * API for a registry that provides datasources that jalview can access
+ * @author jprocter
+ *
+ */
+public interface DasSourceRegistryI
+{
+
+ List<jalviewSourceI> getSources();
+
+ String getDasRegistryURL();
+
+ jalviewSourceI getSource(String nickname);
+
+ jalviewSourceI createLocalSource(String uri, String name, boolean sequence,
+ boolean features);
+ boolean removeLocalSource(jalviewSourceI source);
+
+ void refreshSources();
+
+ String getLocalSourceString();
+
+ List<jalviewSourceI> resolveSourceNicknames(List<String> sources);
+ // TODO: refactor to jDAS specific interface
+ MultipleConnectionPropertyProviderI getSessionHandler();
+}
--- /dev/null
+package jalview.ws.dbsources.das.api;
+
+import java.util.List;
+
+import jalview.ws.seqfetcher.DbSourceProxy;
+
+import org.biodas.jdas.schema.sources.MAINTAINER;
+import org.biodas.jdas.schema.sources.VERSION;
+
+public interface jalviewSourceI
+{
+
+ String getTitle();
+
+ VERSION getVersion();
+
+ String getDocHref();
+
+ String getDescription();
+
+ String getUri();
+
+ MAINTAINER getMAINTAINER();
+
+ String getEmail();
+
+ boolean isLocal();
+
+ boolean isSequenceSource();
+
+ String[] getCapabilityList(VERSION v);
+
+ String[] getLabelsFor(VERSION v);
+
+ /**
+ *
+ * @return null if not a sequence source, otherwise a series of database sources that can be used to retrieve sequence data for particular database coordinate systems
+ */
+ List<DbSourceProxy> getSequenceSourceProxies();
+
+ boolean isFeatureSource();
+
+ /**
+ * returns the base URL for the latest version of a source's DAS endpoint set
+ * @return
+ */
+ String getSourceURL();
+
+}
--- /dev/null
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)\r
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle\r
+ * \r
+ * This file is part of Jalview.\r
+ * \r
+ * Jalview is free software: you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License \r
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
+ * \r
+ * Jalview is distributed in the hope that it will be useful, but \r
+ * WITHOUT ANY WARRANTY; without even the implied warranty \r
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
+ * PURPOSE. See the GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package jalview.ws.dbsources.das.datamodel;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.StringTokenizer;\r
+import java.util.Vector;\r
+\r
+import org.biodas.jdas.client.adapters.sequence.DasSequenceAdapter;\r
+import org.biodas.jdas.client.threads.SequenceClientMultipleSources;\r
+import org.biodas.jdas.schema.sequence.SEQUENCE;\r
+import org.biodas.jdas.schema.sources.COORDINATES;\r
+import org.biodas.jdas.schema.sources.SOURCE;\r
+import org.biodas.jdas.schema.sources.VERSION;\r
+\r
+import com.stevesoft.pat.Regex;\r
+\r
+import jalview.ws.dbsources.das.api.jalviewSourceI;\r
+import jalview.ws.seqfetcher.*;\r
+import jalview.bin.Cache;\r
+import jalview.datamodel.Alignment;\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.datamodel.DBRefEntry;\r
+import jalview.datamodel.Sequence;\r
+import jalview.datamodel.SequenceI;\r
+\r
+/**\r
+ * an instance of this class is created for each unique DAS Sequence source (ie\r
+ * one capable of handling the 'sequence' for a particular MapMaster)\r
+ * \r
+ * @author JimP\r
+ * \r
+ */\r
+public class DasSequenceSource extends DbSourceProxyImpl implements\r
+ DbSourceProxy\r
+{\r
+ private jalviewSourceI jsrc;\r
+\r
+ protected SOURCE source = null;\r
+\r
+ protected VERSION version = null;\r
+\r
+ protected COORDINATES coordsys = null;\r
+\r
+ protected String dbname = "DASCS";\r
+\r
+ protected String dbrefname = "das:source";\r
+\r
+ /**\r
+ * create a new DbSource proxy for a DAS 1 source\r
+ * \r
+ * @param dbnbame\r
+ * Human Readable Name to use when fetching from this source\r
+ * @param dbrefname\r
+ * DbRefName for DbRefs attached to sequences retrieved from this\r
+ * source\r
+ * @param source\r
+ * Das1Source\r
+ * @param coordsys\r
+ * specific coordinate system to use for this source\r
+ * @throws Exception\r
+ * if source is not capable of the 'sequence' command\r
+ */\r
+ public DasSequenceSource(String dbname, String dbrefname, SOURCE source,\r
+ VERSION version, COORDINATES coordsys) throws Exception\r
+ {\r
+ if (!(jsrc = new JalviewSource(source, false)).isSequenceSource())\r
+ {\r
+ throw new Exception("Source " + source.getTitle()\r
+ + " does not support the sequence command.");\r
+ }\r
+ this.source = source;\r
+ this.dbname = dbname;\r
+ this.dbrefname = dbrefname;\r
+ this.coordsys = coordsys;\r
+ }\r
+\r
+ public String getAccessionSeparator()\r
+ {\r
+ return "\t";\r
+ }\r
+\r
+ public Regex getAccessionValidator()\r
+ {\r
+ /** ? * */\r
+ return Regex.perlCode("\\S+");\r
+ }\r
+\r
+ public String getDbName()\r
+ {\r
+ // TODO: map to\r
+ return dbname + " (DAS)";\r
+ }\r
+\r
+ public String getDbSource()\r
+ {\r
+ return dbrefname;\r
+ }\r
+\r
+ public String getDbVersion()\r
+ {\r
+ return coordsys.getVersion();\r
+ }\r
+\r
+\r
+ public AlignmentI getSequenceRecords(String queries) throws Exception\r
+ {\r
+ StringTokenizer st = new StringTokenizer(queries, "\t");\r
+ List<String> toks = new ArrayList<String>(), src = new ArrayList<String>();\r
+ while (st.hasMoreTokens())\r
+ {\r
+ toks.add(st.nextToken());\r
+ }\r
+ src.add(jsrc.getSourceURL());\r
+ Map<String, Map<List<String>, DasSequenceAdapter>> resultset = new HashMap<String, Map<List<String>, DasSequenceAdapter>>();\r
+ Map<String, Map<List<String>, Exception>> errors = new HashMap<String, Map<List<String>, Exception>>();\r
+ SequenceClientMultipleSources sclient;\r
+ sclient = new SequenceClientMultipleSources();\r
+ sclient.fetchData(src, toks, resultset, errors);\r
+ sclient.shutDown();\r
+ while (!sclient.isTerminated())\r
+ {\r
+ try {Thread.sleep(200);\r
+ \r
+ } catch (InterruptedException x) {}\r
+ }\r
+ \r
+ if (resultset.isEmpty())\r
+ {\r
+ System.err.println("Sequence Query to " + jsrc.getTitle() + " with '"\r
+ + queries + "' returned no sequences.");\r
+ return null;\r
+ }\r
+ else\r
+ {\r
+ Vector<SequenceI> seqs=null;\r
+ for (Map.Entry<String, Map<List<String>, DasSequenceAdapter>> resset : resultset\r
+ .entrySet())\r
+ {\r
+ for (Map.Entry<List<String>, DasSequenceAdapter> result : resset\r
+ .getValue().entrySet())\r
+ {\r
+ DasSequenceAdapter dasseqresp = result.getValue();\r
+ List<String> accessions = result.getKey();\r
+ for (SEQUENCE e : dasseqresp.getSequence())\r
+ {\r
+ String lbl = e.getId();\r
+\r
+ if (toks.indexOf(lbl) == -1)\r
+ {\r
+ System.err\r
+ .println("Warning - received sequence event for strange accession code ("\r
+ + lbl + ")");\r
+ }\r
+ else\r
+ {\r
+ if (seqs == null)\r
+ {\r
+ if (e.getContent().length() == 0)\r
+ {\r
+ System.err\r
+ .println("Empty sequence returned for accession code ("\r
+ + lbl\r
+ + ") from "\r
+ + resset.getKey()\r
+ + " (source is "\r
+ + getDbName());\r
+ continue;\r
+ }\r
+ }\r
+ seqs = new java.util.Vector<SequenceI>();\r
+ // JDAS returns a sequence complete with any newlines and spaces in the XML\r
+ Sequence sq = new Sequence(lbl, e.getContent().replaceAll("\\s+", ""));\r
+ sq.addDBRef(new DBRefEntry(getDbSource(), getDbVersion()\r
+ + ":" + e.getVersion(), lbl));\r
+ seqs.addElement(sq);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ if (seqs == null || seqs.size() == 0)\r
+ return null;\r
+ SequenceI[] sqs = new SequenceI[seqs.size()];\r
+ for (int i = 0, iSize = seqs.size(); i < iSize; i++)\r
+ {\r
+ sqs[i] = (SequenceI) seqs.elementAt(i);\r
+ }\r
+ Alignment al = new Alignment(sqs);\r
+ if (jsrc.isFeatureSource())\r
+ {\r
+ java.util.Vector<jalviewSourceI> srcs = new java.util.Vector<jalviewSourceI>();\r
+ srcs.addElement(jsrc);\r
+ try {\r
+ new jalview.ws.DasSequenceFeatureFetcher(sqs, null, srcs, false,\r
+ false);\r
+ } catch (Exception x)\r
+ {\r
+ Cache.log.error("Couldn't retrieve features for sequence from its source.",x);\r
+ }\r
+ }\r
+\r
+ return al;\r
+ }\r
+ }\r
+\r
+ public String getTestQuery()\r
+ {\r
+ return coordsys.getTestRange();\r
+ }\r
+\r
+ public boolean isValidReference(String accession)\r
+ {\r
+ // TODO try to validate an accession against source\r
+ // We don't really know how to do this without querying source\r
+\r
+ return true;\r
+ }\r
+\r
+ /**\r
+ * @return the source\r
+ */\r
+ public SOURCE getSource()\r
+ {\r
+ return source;\r
+ }\r
+\r
+ /**\r
+ * @return the coordsys\r
+ */\r
+ public COORDINATES getCoordsys()\r
+ {\r
+ return coordsys;\r
+ }\r
+}\r
--- /dev/null
+/**
+ *
+ */
+package jalview.ws.dbsources.das.datamodel;
+
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import javax.swing.JOptionPane;
+
+import org.apache.http.auth.InvalidCredentialsException;
+import org.biodas.jdas.client.ConnectionPropertyProviderI;
+import org.biodas.jdas.client.SourcesClient;
+import org.biodas.jdas.client.threads.MultipleConnectionPropertyProviderI;
+import org.biodas.jdas.dassources.Capabilities;
+import org.biodas.jdas.schema.sources.CAPABILITY;
+import org.biodas.jdas.schema.sources.SOURCE;
+import org.biodas.jdas.schema.sources.SOURCES;
+import org.biodas.jdas.schema.sources.VERSION;
+
+import jalview.bin.Cache;
+import jalview.ws.dbsources.das.api.DasSourceRegistryI;
+import jalview.ws.dbsources.das.api.jalviewSourceI;
+
+/**
+ *
+ */
+public class DasSourceRegistry implements DasSourceRegistryI,
+ MultipleConnectionPropertyProviderI
+{
+ // private org.biodas.jdas.schema.sources.SOURCE[] dasSources = null;
+ private List<jalviewSourceI> dasSources = null;
+
+ private Hashtable<String, jalviewSourceI> sourceNames = null;
+
+ private Hashtable<String, jalviewSourceI> localSources = null;
+
+ public static String DEFAULT_REGISTRY = "http://www.dasregistry.org/das1/sources/";
+
+ /**
+ * true if thread is running and we are talking to DAS registry service
+ */
+ private boolean loadingDasSources = false;
+
+ public boolean isLoadingDasSources()
+ {
+ return loadingDasSources;
+ }
+
+ public String getDasRegistryURL()
+ {
+ String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",
+ DEFAULT_REGISTRY);
+
+ if (registry.indexOf("/registry/das1/sources/") > -1)
+ {
+ jalview.bin.Cache.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL,
+ DEFAULT_REGISTRY);
+ registry = DEFAULT_REGISTRY;
+ }
+ return registry;
+ }
+
+ /**
+ * query the default DAS Source Registry for sources. Uses value of jalview
+ * property DAS_REGISTRY_URL and the DasSourceBrowser.DEFAULT_REGISTRY if that
+ * doesn't exist.
+ *
+ * @return list of sources
+ */
+ private List<jalviewSourceI> getDASSources()
+ {
+
+ return getDASSources(getDasRegistryURL());
+ }
+
+ /**
+ * query the given URL for DasSources.
+ *
+ * @param registryURL
+ * return sources from registryURL
+ */
+ private static List<jalviewSourceI> getDASSources(String registryURL)
+ {
+ try
+ {
+ URL url = new URL(registryURL);
+ org.biodas.jdas.client.SourcesClientInterface client = new SourcesClient();
+
+ SOURCES sources = client.fetchDataRegistry(registryURL, null, null,
+ null, null, null, null);
+
+ List<SOURCE> dassources = sources.getSOURCE();
+ ArrayList<jalviewSourceI> dsrc = new ArrayList<jalviewSourceI>();
+ for (SOURCE src : dassources)
+ {
+ dsrc.add(new JalviewSource(src, false));
+ }
+ return dsrc;
+ } catch (Exception ex)
+ {
+ System.err.println("Failed to contact DAS1 registry at "
+ + registryURL);
+ ex.printStackTrace();
+ return new ArrayList<jalviewSourceI>();
+ }
+ }
+
+ public void run()
+ {
+ getSources();
+ }
+
+ @Override
+ public List<jalviewSourceI> getSources()
+ {
+ if (dasSources == null)
+ {
+ dasSources = getDASSources();
+ }
+ return appendLocalSources();
+ }
+
+ /**
+ * generate Sources from the local das source list
+ *
+ */
+ private void addLocalDasSources()
+ {
+ if (localSources == null)
+ {
+ // get local sources from properties and initialise the local source list
+ String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
+ if (local != null)
+ {
+ StringTokenizer st = new StringTokenizer(local, "\t");
+ while (st.hasMoreTokens())
+ {
+ String token = st.nextToken();
+ int bar = token.indexOf("|");
+ String url = token.substring(bar + 1);
+ boolean features = true, sequence = false;
+ if (url.startsWith("sequence:"))
+ {
+ url = url.substring(9);
+ // this source also serves sequences as well as features
+ sequence = true;
+ }
+ createLocalSource(url, token.substring(0, bar), sequence,
+ features);
+ }
+ }
+ }
+ }
+
+ private List<jalviewSourceI> appendLocalSources()
+ {
+ List<jalviewSourceI> srclist = new ArrayList<jalviewSourceI>();
+ addLocalDasSources();
+ sourceNames = new Hashtable<String, jalviewSourceI>();
+ if (dasSources != null)
+ {
+ for (jalviewSourceI src : dasSources)
+ {
+ sourceNames.put(src.getTitle(), src);
+ srclist.add(src);
+ }
+ }
+
+ if (localSources == null)
+ {
+ return srclist;
+ }
+ Enumeration en = localSources.keys();
+ while (en.hasMoreElements())
+ {
+ String key = en.nextElement().toString();
+ jalviewSourceI jvsrc = localSources.get(key);
+ sourceNames.put(key, jvsrc);
+ srclist.add(jvsrc);
+ }
+ return srclist;
+ }
+
+ /*
+ *
+ */
+
+ @Override
+ public jalviewSourceI createLocalSource(String url, String name,
+ boolean sequence, boolean features)
+ {
+ SOURCE local = _createLocalSource(url, name, sequence, features);
+
+ if (localSources == null)
+ {
+ localSources = new Hashtable<String, jalviewSourceI>();
+ }
+ jalviewSourceI src = new JalviewSource(local, true);
+ localSources.put(local.getTitle(), src);
+ return src;
+ }
+
+ 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>());
+ VERSION v = new VERSION();
+ List<CAPABILITY> cp = new ArrayList<CAPABILITY>();
+ 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());
+ cap.setQueryUri(url + "/sequence");
+ cp.add(cap);
+ }
+ if (features)
+ {
+ CAPABILITY cap = new CAPABILITY();
+ cap.setType("das1:" + Capabilities.FEATURES.getName());
+ cap.setQueryUri(url + "/features");
+ cp.add(cap);
+ }
+
+ v.getCAPABILITY().addAll(cp);
+ local.getVERSION().add(v);
+
+ return local;
+ }
+
+ @Override
+ public jalviewSourceI getSource(String nickname)
+ {
+ return sourceNames.get(nickname);
+ }
+
+ @Override
+ public boolean removeLocalSource(jalviewSourceI source)
+ {
+ if (localSources.containsValue(source))
+ {
+ localSources.remove(source.getTitle());
+ sourceNames.remove(source.getTitle());
+ dasSources.remove(source);
+ jalview.bin.Cache.setProperty("DAS_LOCAL_SOURCE",
+ getLocalSourceString());
+
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void refreshSources()
+ {
+ dasSources = null;
+ sourceNames = null;
+ run();
+ }
+
+ @Override
+ public List<jalviewSourceI> resolveSourceNicknames(List<String> sources)
+ {
+ ArrayList<jalviewSourceI> resolved = new ArrayList<jalviewSourceI>();
+ if (sourceNames != null)
+ {
+ for (String src : sources)
+ {
+ jalviewSourceI dsrc = sourceNames.get(src);
+ if (dsrc != null)
+ {
+ resolved.add(dsrc);
+ }
+ }
+ }
+ return resolved;
+ }
+
+ @Override
+ public String getLocalSourceString()
+ {
+ if (localSources != null)
+ {
+ StringBuffer sb = new StringBuffer();
+ Enumeration en = localSources.keys();
+ while (en.hasMoreElements())
+ {
+ String token = en.nextElement().toString();
+ jalviewSourceI srco = localSources.get(token);
+ sb.append(token + "|"
+ + (srco.isSequenceSource() ? "sequence:" : "")
+ + srco.getUri() + "\t");
+ }
+ return sb.toString();
+ }
+ return "";
+ }
+
+ private static final Hashtable<URL, String> authStash;
+ static
+ {
+ authStash = new Hashtable<URL, String>();
+
+ try
+ {
+ // TODO: allow same credentials for https and http
+ authStash.put(new URL(
+ "http://www.compbio.dundee.ac.uk/geneweb/das/myseq/"),
+ "Basic SmltOm1pSg==");
+ } catch (MalformedURLException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public MultipleConnectionPropertyProviderI getSessionHandler()
+ {
+ return this;
+ }
+
+ @Override
+ public ConnectionPropertyProviderI getConnectionPropertyProviderFor(
+ String arg0)
+ {
+
+ final ConnectionPropertyProviderI conprov = new ConnectionPropertyProviderI()
+ {
+ boolean authed = false;
+
+ @Override
+ public void setConnectionProperties(HttpURLConnection connection)
+ {
+ String auth = authStash.get(connection.getURL());
+ if (auth != null && auth.length() > 0)
+ {
+ connection.setRequestProperty("Authorisation", auth);
+ authed = true;
+ }
+ else
+ {
+ authed = false;
+ }
+ }
+
+ @Override
+ public boolean getResponseProperties(HttpURLConnection connection)
+ {
+ String auth = authStash.get(connection.getURL());
+ if (auth != null && auth.length() == 0)
+ {
+ // don't attempt to check if we authed or not - user entered empty
+ // password
+ return false;
+ }
+ if (!authed)
+ {
+ if (auth != null)
+ {
+ // try and pass credentials.
+ return true;
+ }
+ // see if we should try and create a new auth record.
+ String ameth = connection.getHeaderField("X-DAS-AuthMethods");
+ Cache.log.debug("Could authenticate to " + connection.getURL()
+ + " with : " + ameth);
+ // TODO: search auth string and raise login box - return if auth was
+ // provided
+ return false;
+ }
+ else
+ {
+ // check to see if auth was successful
+ String asuc = connection
+ .getHeaderField("X-DAS_AuthenticatedUser");
+ if (asuc != null && asuc.trim().length() > 0)
+ {
+ // authentication was successful
+ Cache.log.debug("Authenticated successfully to "
+ + connection.getURL().toString());
+ return false;
+ }
+ // it wasn't - so we should tell the user it failed and ask if they
+ // want to attempt authentication again.
+ authStash.remove(connection.getURL());
+ // open a new login/password dialog with cancel button
+ // set new authStash content with password and return true
+ return true; //
+ // User cancelled auth - so put empty string in stash to indicate we
+ // don't want to auth with this server.
+ // authStash.put(connection.getURL(), "");
+ // return false;
+ }
+ }
+ };
+ return conprov;
+ }
+
+}
--- /dev/null
+package jalview.ws.dbsources.das.datamodel;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.biodas.jdas.dassources.Capabilities;
+import org.biodas.jdas.dassources.utils.DasTimeFormat;
+import org.biodas.jdas.dassources.utils.RegistrySourceAdapter;
+import org.biodas.jdas.schema.sources.CAPABILITY;
+import org.biodas.jdas.schema.sources.COORDINATES;
+import org.biodas.jdas.schema.sources.MAINTAINER;
+import org.biodas.jdas.schema.sources.PROP;
+import org.biodas.jdas.schema.sources.SOURCE;
+import org.biodas.jdas.schema.sources.VERSION;
+
+import jalview.ws.dbsources.das.api.jalviewSourceI;
+import jalview.ws.seqfetcher.DbSourceProxy;
+
+public class JalviewSource implements jalviewSourceI
+{
+ SOURCE source;
+
+ public JalviewSource(SOURCE local2, boolean local)
+ {
+ this.local = local;
+ source = local2;
+ }
+
+ @Override
+ public String getTitle()
+ {
+ return source.getTitle();
+ }
+
+ @Override
+ public VERSION getVersion()
+ {
+
+ return getVersionFor(source);
+ }
+
+ @Override
+ public String getDocHref()
+ {
+ return source.getDocHref();
+ }
+
+ @Override
+ public String getDescription()
+ {
+ return source.getDescription();
+ }
+
+ @Override
+ public String getUri()
+ {
+ return source.getUri();
+ }
+
+ @Override
+ public MAINTAINER getMAINTAINER()
+ {
+ return source.getMAINTAINER();
+ }
+
+ @Override
+ public String getEmail()
+ {
+ return (local) ? null: source.getMAINTAINER().getEmail();
+ }
+
+ boolean local = false;
+
+ @Override
+ public boolean isLocal()
+ {
+ return local;
+ }
+
+ @Override
+ public boolean isSequenceSource()
+ {
+ String seqcap = "das1:" + Capabilities.SEQUENCE.getName();
+ for (String cp : getCapabilityList(getVersionFor(source)))
+ {
+ if (cp.equals(seqcap))
+ {
+ return true;
+
+ }
+ }
+ return false;
+ }
+ @Override
+ public boolean isFeatureSource()
+ {
+ String seqcap = "das1:" + Capabilities.FEATURES.getName();
+ for (String cp : getCapabilityList(getVersionFor(source)))
+ {
+ if (cp.equals(seqcap))
+ {
+ return true;
+
+ }
+ }
+ return false;
+ }
+
+ private VERSION getVersionFor(SOURCE ds)
+ {
+ 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;
+ }
+ }
+ return latest;
+ }
+
+ private boolean isLaterThan(String ref, String newer)
+ {
+ Date refdate = null, newdate = null;
+ try
+ {
+ refdate = DasTimeFormat.fromDASString(ref);
+
+ } catch (ParseException x)
+ {
+ return false;
+ }
+ try
+ {
+ newdate = DasTimeFormat.fromDASString(newer);
+ } catch (ParseException e)
+ {
+ // TODO: handle exception
+ }
+ if (refdate != null)
+ {
+ if (newdate != null)
+ {
+ return refdate.before(newdate);
+ }
+ return false;
+ }
+ 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
+ return false;
+ }
+
+ public String[] getLabelsFor(VERSION v)
+ {
+ ArrayList<String> labels = new ArrayList<String>();
+ for (PROP p : v.getPROP())
+ {
+ if (p.getName().equalsIgnoreCase("LABEL"))
+ {
+ labels.add(p.getValue());
+ }
+ }
+ return labels.toArray(new String[0]);
+ }
+
+ private CAPABILITY getCapability(Capabilities capability) {
+ for (CAPABILITY p: getVersion().getCAPABILITY()) {
+ if (p.getType().equalsIgnoreCase(capability.getName()) || p.getType().equalsIgnoreCase("das1:"+capability.getName()))
+ {
+ return p;
+ }
+ }
+ return null;
+ }
+ public String[] getCapabilityList(VERSION v)
+ {
+
+ ArrayList<String> labels = new ArrayList<String>();
+ 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]);
+ }
+
+ @Override
+ public List<DbSourceProxy> getSequenceSourceProxies()
+ {
+ if (!isSequenceSource())
+ {
+ return null;
+ }
+ ArrayList<DbSourceProxy> seqsources = new ArrayList<DbSourceProxy>();
+ if (!local)
+ {
+ VERSION v = getVersion();
+ for (COORDINATES cs : v.getCOORDINATES())
+ {
+
+ /*
+ * if (css == null || css.length == 0) { // TODO: query das source
+ * directly to identify coordinate system... or // have to make up a
+ * coordinate system css = new DasCoordinateSystem[] { new
+ * DasCoordinateSystem() }; css[0].setName(d1s.getNickname());
+ * css[0].setUniqueId(d1s.getNickname()); } for (int c = 0; c <
+ * css.length; c++) {
+ */
+ try
+ {
+ seqsources.add(new DasSequenceSource("das:" + getTitle() + " ("
+ + cs.getContent() + ")", cs.getContent(), source, v, cs));
+ } catch (Exception e)
+ {
+ System.err.println("Ignoring sequence coord system " + cs + " ("
+ + cs.getContent() + ") for source " + getTitle()
+ + "- threw exception when constructing fetcher.\n");
+ e.printStackTrace();
+ }
+ }
+ } else {
+ try
+ {
+ seqsources.add(new DasSequenceSource("das:"+getTitle(), getTitle(), source, getVersion(), null));
+ } catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ return seqsources;
+ }
+ @Override
+ public String getSourceURL()
+ {
+ try {
+ String url = new RegistrySourceAdapter(source).getOriginalDataSourceUri();
+ return url;
+ }
+ catch (Exception x)
+ {
+ System.err.println("Serious: Couldn't get the URL for source "+source.getTitle());
+ x.printStackTrace();
+ }
+ return null;
+ }
+}
* database (unify with io)\r
* \r
* @author JimP\r
- * \r
+ * TODO: promote to API\r
*/\r
public interface DbSourceProxy\r
{\r
+++ /dev/null
-/**
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 19.03.2004
- * @author Andreas Prlic
- *
- */
-package org.biojava.dasobert.das;
-
-import java.io.*;
-import java.lang.reflect.*;
-import java.net.*;
-import java.util.*;
-import java.util.logging.*;
-import javax.xml.parsers.*;
-
-import org.xml.sax.*;
-
-/**
- * A class to perform a DAS features request
- *
- * @author Andreas Prlic Adapted for jalview use.
- * @author Andrew Waterhouse Updated to Das 1.53e feature spec.
- * @author Jim Procter
- */
-public class DAS_FeatureRetrieve
-{
- String version;
-
- List features;
-
- Logger logger;
-
- int comeBackLater;
-
- URL url;
-
- /**
- * @param url
- * the URL the features should be downloaded from
- *
- */
- public DAS_FeatureRetrieve(URL url)
- {
- super();
-
- logger = Logger.getLogger("org.biojava.spice");
- features = new ArrayList();
- comeBackLater = -1;
- this.url = url;
- reload();
- }
-
- /**
- * contact the DAS-feature server again. Usually it is not necessary to call
- * this again, because the constructor already does, but if comeBackLater > -1
- * this should be called again.
- *
- */
- public void reload()
- {
-
- try
- {
-
- InputStream dasInStream = null;
- try
- {
- dasInStream = open(url);
- } catch (Exception e)
- {
- comeBackLater = -1;
- System.out.println("NO RESPONSE FROM " + url);
- logger.log(Level.FINE, "could not open connection to " + url, e);
- return;
- }
-
- SAXParserFactory spfactory = SAXParserFactory.newInstance();
-
- spfactory.setValidating(false);
-
- SAXParser saxParser = null;
-
- try
- {
- saxParser = spfactory.newSAXParser();
- } catch (ParserConfigurationException e)
- {
- e.printStackTrace();
- }
-
- String vali = System.getProperty("XMLVALIDATION");
-
- boolean validation = false;
- if (vali != null)
- {
- if (vali.equals("true"))
- {
- validation = true;
- }
- }
-
- XMLReader xmlreader = saxParser.getXMLReader();
-
- // XMLReader xmlreader = XMLReaderFactory.createXMLReader();
- try
- {
- xmlreader.setFeature("http://xml.org/sax/features/validation",
- validation);
- } catch (SAXException e)
- {
- logger.log(Level.FINE, "Cannot set validation " + validation);
- }
-
- try
- {
- xmlreader
- .setFeature(
- "http://apache.org/xml/features/nonvalidating/load-external-dtd",
- validation);
- } catch (SAXNotRecognizedException e)
- {
- e.printStackTrace();
- logger
- .log(Level.FINE, "Cannot set load-external-dtd "
- + validation);
-
- }
-
- DAS_Feature_Handler cont_handle = new DAS_Feature_Handler();
- cont_handle.setDASCommand(url.toString());
- xmlreader.setContentHandler(cont_handle);
- xmlreader.setErrorHandler(new org.xml.sax.helpers.DefaultHandler());
- InputSource insource = new InputSource();
- insource.setByteStream(dasInStream);
-
- try
- {
- xmlreader.parse(insource);
- features = cont_handle.get_features();
- version = cont_handle.getVersion();
-
- comeBackLater = cont_handle.getComBackLater();
- } catch (Exception e)
- {
- System.out
- .println("Error parsing response from: " + url + "\n" + e);
- logger.log(Level.FINE, "error while parsing response from " + url);
- comeBackLater = -1;
- features = new ArrayList();
- }
- } catch (Exception ex)
- {
- ex.printStackTrace();
- comeBackLater = -1;
- }
- }
-
- /**
- * open HttpURLConnection. Recommended way to open HttpURLConnections, since
- * this take care of setting timeouts properly for java 1.4 and 1.5
- */
- public static HttpURLConnection openHttpURLConnection(URL url)
- throws IOException, ConnectException
- {
- HttpURLConnection huc = null;
- huc = (HttpURLConnection) url.openConnection();
-
- String os_name = java.lang.System.getProperty("os.name");
- String os_version = java.lang.System.getProperty("os.version");
- String os_arch = java.lang.System.getProperty("os.arch");
- String VERSION = "1.0";
-
- String userAgent = "Jalview " + VERSION + "(" + os_name + "; "
- + os_arch + " ; " + os_version + ")";
- // e.g. "Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.2) Gecko/20040803"
- huc.addRequestProperty("User-Agent", userAgent);
- // logger.finest("opening "+url);
-
- int timeout = 10000;
- System
- .setProperty("sun.net.client.defaultConnectTimeout", timeout
- + "");
- System.setProperty("sun.net.client.defaultReadTimeout", timeout + "");
-
- // use reflection to determine if get and set timeout methods for
- // urlconnection are available
- // seems java 1.5 does not watch the System properties any longer...
- // and java 1.4 did not provide these...
- // for 1.4 see setSystemProperties
-
- try
- {
- // try to use reflection to set timeout property
- Class urlconnectionClass = Class
- .forName("java.net.HttpURLConnection");
-
- Method setconnecttimeout = urlconnectionClass.getMethod(
- "setConnectTimeout", new Class[]
- { int.class });
- setconnecttimeout.invoke(huc, new Object[]
- { new Integer(timeout) });
-
- Method setreadtimeout = urlconnectionClass.getMethod(
- "setReadTimeout", new Class[]
- { int.class });
- setreadtimeout.invoke(huc, new Object[]
- { new Integer(timeout) });
- // System.out.println("successfully set java 1.5 timeout");
- } catch (Exception e)
- {
- // e.printStackTrace();
- // most likely it was a NoSuchMEthodException and we are running java 1.4.
- }
- return huc;
- }
-
- private InputStream open(URL url) throws java.io.IOException,
- java.net.ConnectException
- {
- InputStream inStream = null;
-
- HttpURLConnection huc = openHttpURLConnection(url);
-
- inStream = huc.getInputStream();
-
- return inStream;
-
- }
-
- /**
- * returns a List of Features
- *
- * @return a List of Maps containing the features
- */
- public List get_features()
- {
-
- return features;
- }
-
- /**
- * Get the version string of the reference object. If it does not match the
- * version string that is obtained from the reference server there is a
- * version problem!
- *
- * @return version string. (e.g. a MD5 digest of the reference sequence)
- */
- public String getVersion()
- {
- return version;
- }
-
- public void setVersion(String version)
- {
- this.version = version;
- }
-
- /**
- * returns the comeBackLater value - if a server returned suchh -
- *
- * @return comeBackLater in seconds, or -1 if not provided by server
- */
- public int getComeBackLater()
- {
-
- return comeBackLater;
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 19.03.2004
- * @author Andreas Prlic
- *
- */
-package org.biojava.dasobert.das;
-
-import java.util.*;
-
-import org.xml.sax.*;
-import org.xml.sax.helpers.*;
-
-/**
- * a class to parse the response of a DAS - Feature request
- *
- * @author Andreas Prlic Adapted for jalview use.
- * @author Andrew Waterhouse Updated to Das 1.53e feature spec.
- * @author Jim Procter
- *
- */
-public class DAS_Feature_Handler extends DefaultHandler
-{
-
- /**
- *
- */
- List features;
-
- boolean first_flag;
-
- HashMap feature;
-
- String featurefield;
-
- StringBuffer characterdata;
-
- String dasCommand;
-
- int comeBackLater;
-
- int maxFeatures;
-
- String segmentId;
-
- String version;
-
- String type_id;
-
- String type_category;
-
- public DAS_Feature_Handler()
- {
- super();
-
- features = new ArrayList();
- first_flag = true;
- featurefield = "";
- characterdata = new StringBuffer();
- dasCommand = "";
- comeBackLater = -1;
- maxFeatures = -1;
- segmentId = "";
- version = "";
- type_id = "";
- type_category = "";
- }
-
- /**
- * get the id information specified int the SEGMENT field of the DAS response
- *
- * @return the segmentId or an emtpy string if not available
- */
- public String getSegmentId()
- {
- return segmentId;
- }
-
- /**
- * get the version informationspecified in the SEGMENT field of the DAS
- * response
- *
- * @return the version information of an empty string if not available
- */
- public String getVersion()
- {
- return version;
- }
-
- public boolean isMD5Checksum()
- {
-
- if ((version != null) && (version.length() == 32))
- return true;
- return false;
- }
-
- /**
- * specifies a maximum number of features to be downloaded. if a server
- * returns more, they will be ignored. default is to load all features
- *
- * @param max
- * the maximium number of features to be downloaded
- */
-
- public void setMaxFeatures(int max)
- {
- maxFeatures = max;
- }
-
- public int getMaxFeatures()
- {
- return maxFeatures;
- }
-
- public void setDASCommand(String cmd)
- {
- dasCommand = cmd;
- }
-
- public String getDASCommand()
- {
- return dasCommand;
- }
-
- public List get_features()
- {
- return features;
- }
-
- public int getComBackLater()
- {
- return comeBackLater;
- }
-
- void start_feature(String uri, String name, String qName, Attributes atts)
- {
-
- if ((maxFeatures > 0) && (features.size() > maxFeatures))
- {
- characterdata = new StringBuffer();
- return;
- }
- feature = new HashMap();
- String id = atts.getValue("id");
- feature.put("id", id);
- feature.put("dassource", dasCommand);
- characterdata = new StringBuffer();
- }
-
- void add_featuredata(String uri, String name, String qName)
- {
- // System.out.println("featurefield "+featurefield+ " data "+characterdata);
- // NOTE can have multiple lines ..
-
- if ((maxFeatures > 0) && (features.size() > maxFeatures))
- {
- return;
- }
-
- String data = (String) feature.get(featurefield);
- String featureText = characterdata.toString();
- if (data != null)
- {
- featureText = data + " " + featureText;
- }
-
- if (qName.equals("TYPE"))
- {
- if (featureText.length() < 1)
- featureText = type_id;
-
- feature.put("TYPE_ID", type_id);
- feature.put("TYPE_CATEGORY", type_category);
- type_id = "";
- type_category = "";
- }
-
- feature.put(featurefield, featureText);
- featurefield = "";
- characterdata = new StringBuffer();
- }
-
- private void addLink(String uri, String name, String qName,
- Attributes atts)
- {
- String href = atts.getValue("href");
- feature.put("LINK", href);
- characterdata = new StringBuffer();
- featurefield = "LINK-TEXT";
-
- }
-
- private void addGroup(String uri, String name, String qName,
- Attributes atts)
- {
- String id = atts.getValue("id");
- feature.put("GROUP", id);
- characterdata = new StringBuffer();
- featurefield = "GROUP";
- }
-
- public void startElement(String uri, String name, String qName,
- Attributes atts)
- {
- // System.out.println("new element "+qName);
-
- if (qName.equals("FEATURE"))
- {
- start_feature(uri, name, qName, atts);
- }
- else if (qName.equals("LINK"))
- {
- addLink(uri, name, qName, atts);
- }
- else if (qName.equals("GROUP"))
- {
- addGroup(uri, name, qName, atts);
- }
- else if (qName.equals("METHOD") || qName.equals("TYPE")
- || qName.equals("START") || qName.equals("END")
- || qName.equals("NOTE") || qName.equals("SCORE")
- || qName.equals("ORIENTATION"))
- {
- characterdata = new StringBuffer();
- featurefield = qName;
- }
- else if (qName.equals("SEGMENT"))
- {
- String id = atts.getValue("id");
- if (id != null)
- segmentId = id;
- String v = atts.getValue("version");
- if (v != null)
- version = v;
-
- }
- if (qName.equals("TYPE"))
- {
- type_id = atts.getValue("id");
- type_category = atts.getValue("category");
- }
-
- }
-
- public void startDocument()
- {
- }
-
- public void endDocument()
- {
- }
-
- public void endElement(String uri, String name, String qName)
- {
-
- if (qName.equals("METHOD") || qName.equals("TYPE")
- || qName.equals("START") || qName.equals("END")
- || qName.equals("NOTE") || qName.equals("LINK")
- || qName.equals("SCORE") || qName.equals("ORIENTATION")
- || qName.equals("GROUP"))
- {
- add_featuredata(uri, name, qName);
- }
- else if (qName.equals("FEATURE"))
- {
-
- if (maxFeatures > 0)
- {
- if (features.size() < maxFeatures)
- {
- features.add(feature);
- }
- }
- else
- {
- // no restriction
- features.add(feature);
- }
- }
- }
-
- public void characters(char ch[], int start, int length)
- {
- if (maxFeatures > 0)
- if (features.size() > maxFeatures)
- return;
-
- for (int i = start; i < start + length; i++)
- {
-
- characterdata.append(ch[i]);
- }
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 19.03.2004
- * @author Andreas Prlic
- *
- */
-package org.biojava.dasobert.das;
-
-import org.xml.sax.helpers.DefaultHandler;
-import org.xml.sax.Attributes;
-import java.util.logging.*;
-
-/**
- * a class that parses the XML response of a DAS - sequence command.
- *
- * @author Andreas Prlic
- *
- */
-public class DAS_Sequence_Handler extends DefaultHandler
-{
-
- StringBuffer sequence;
-
- int length;
-
- int maxLength;
-
- String version;
-
- boolean dna_flag;
-
- /**
- *
- */
- public DAS_Sequence_Handler()
- {
- super();
-
- sequence = new StringBuffer();
- length = 0;
- dna_flag = false;
- maxLength = -1;
- version = "";
- }
-
- /**
- * set a maximum length of sequence that should be loaded default: -1. if -1
- * no length restriction is being supplied
- *
- * @return the maximum length or -1 if no restriction
- */
- public int getMaxLength()
- {
- return maxLength;
- }
-
- /**
- * set a maximum length of sequence that should be loaded default: -1. if -1
- * no length restriction is being supplied
- *
- * @param maxLength
- * the maximum length or -1 if unrestricted
- */
- public void setMaxLength(int maxLength)
- {
- this.maxLength = maxLength;
- }
-
- public void startElement(String uri, String name, String qName,
- Attributes atts)
- {
-
- if (qName.equals("SEQUENCE"))
- {
- version = atts.getValue("version");
- String lenstr = atts.getValue("stop");
- length = Integer.parseInt(lenstr);
- dna_flag = true;
- }
-
- }
-
- public void characters(char ch[], int start, int length)
- {
-
- if (maxLength > 0)
- if (sequence.length() > maxLength)
- return;
-
- if (dna_flag)
- for (int i = start; i < start + length; i++)
- {
-
- // all sorts of characters can be found in "seqeunces" ... ignore
- // them...
- switch (ch[i])
- {
- case '\\':
- // System.out.print("\\\\");
- break;
- case '"':
- // System.out.print("\\\"");
- break;
- case '\n':
- // System.out.print("\\n");
- break;
- case '\r':
- // System.out.print("\\r");
- break;
- case '\t':
- // System.out.print("\\t");
- break;
- case ' ':
- break;
- default:
- sequence = sequence.append(ch[i]);
-
- break;
- }
- }
-
- }
-
- public String get_sequence()
- {
-
- if (maxLength < 0)
- {
- if (length != sequence.length())
- {
- Logger logger = Logger.getLogger("org.biojava.spice");
- logger.warning("Sequence does not match specified length!");
- }
- }
-
- return sequence.toString();
- }
-
- public String getVersion()
- {
- return version;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 21.09.2004
- * @author Andreas Prlic
- *
- */
-
-package org.biojava.dasobert.das;
-
-import java.net.*;
-import java.util.*;
-import java.util.logging.*;
-
-import org.biojava.dasobert.dasregistry.*;
-import org.biojava.dasobert.eventmodel.*;
-
-/**
- * a thread that connects to a DAS - Feature service and gets the features
- *
- * @author Andreas Prlic
- */
-
-public class FeatureThread implements Runnable
-{
-
- /**
- * number of times the client tries to reconnect to the server if a "come back
- * later" is returned. the server should provide a reasonable estimation how
- * long it will take him to create results. if this number of requests is
- * still not successfull, give up.
- */
- public static int MAX_COME_BACK_ITERATIONS = 5;
-
- public static int MAX_NR_FEATURES = 300;
-
- static Logger logger = Logger.getLogger("org.biojava.spice");
-
- Das1Source dasSource;
-
- String ac;
-
- List featureListeners;
-
- Thread thread;
-
- public FeatureThread(String accessionCode, Das1Source dasSource)
- {
- this.dasSource = dasSource;
- this.ac = accessionCode;
- featureListeners = new ArrayList();
- }
-
- public void addFeatureListener(FeatureListener li)
- {
- featureListeners.add(li);
- }
-
- public void clearFeatureListeners()
- {
- featureListeners.clear();
- }
-
- public synchronized void stop()
- {
- thread = null;
- notify();
- }
-
- public void run()
- {
- Thread me = Thread.currentThread();
- while (thread == me)
- {
- String url = dasSource.getUrl();
- String queryString = url + "features?segment=" + ac;
- URL cmd = null;
- try
- {
- cmd = new URL(queryString);
- } catch (MalformedURLException e)
- {
- logger.warning("got MalformedURL from das source " + dasSource);
- e.printStackTrace();
-
- }
-
- logger.info("requesting features from " + cmd);
- DAS_FeatureRetrieve ftmp = new DAS_FeatureRetrieve(cmd);
-
- int comeBackLater = ftmp.getComeBackLater();
- int securityCounter = 0;
- while ((thread == me) && (comeBackLater > 0))
- {
- securityCounter++;
- if (securityCounter >= MAX_COME_BACK_ITERATIONS)
- {
- comeBackLater = -1;
- break;
-
- }
- notifyComeBackLater(comeBackLater);
- // server is still calculating - asks us to come back later
- try
- {
- wait(comeBackLater);
- } catch (InterruptedException e)
- {
- comeBackLater = -1;
- break;
- }
-
- ftmp.reload();
- comeBackLater = ftmp.getComeBackLater();
- }
-
- if (!(thread == me))
- {
- break;
- }
-
- List features = ftmp.get_features();
- String version = ftmp.getVersion();
-
- // a fallback mechanism to prevent DAS sources from bringing down spice
- if (features.size() > MAX_NR_FEATURES)
- {
- logger
- .warning("DAS source returned more than " + MAX_NR_FEATURES
- + "features. "
- + " throwing away excess features at " + cmd);
- features = features.subList(0, MAX_NR_FEATURES);
- }
-
- // notify FeatureListeners
- Map[] feats = (Map[]) features.toArray(new Map[features.size()]);
- notifyFeatureListeners(feats, version);
-
- break;
-
- }
- thread = null;
-
- }
-
- public void start()
- {
- thread = new Thread(this);
- thread.start();
- }
-
- private void notifyFeatureListeners(Map[] feats, String version)
- {
- logger.finest("FeatureThread found " + feats.length + " features");
- FeatureEvent fevent = new FeatureEvent(feats, dasSource, version);
- Iterator fiter = featureListeners.iterator();
- while (fiter.hasNext())
- {
- FeatureListener fi = (FeatureListener) fiter.next();
- fi.newFeatures(fevent);
- }
- }
-
- /**
- * the Annotation server requested to be queried again in a while
- *
- * @param comeBackLater
- */
- private void notifyComeBackLater(int comeBackLater)
- {
- FeatureEvent event = new FeatureEvent(new HashMap[0], dasSource, "");
- event.setComeBackLater(comeBackLater);
- Iterator fiter = featureListeners.iterator();
- while (fiter.hasNext())
- {
- FeatureListener fi = (FeatureListener) fiter.next();
- fi.comeBackLater(event);
- }
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Nov 20, 2005
- *
- */
-package org.biojava.dasobert.das;
-
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.Iterator;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.biojava.dasobert.dasregistry.Das1Source;
-import org.biojava.dasobert.eventmodel.SequenceEvent;
-import org.biojava.dasobert.eventmodel.SequenceListener;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.XMLReader;
-import java.util.*;
-
-/**
- * a thread that gets the sequence from a DAS server
- *
- * @author Andreas Prlic
- *
- */
-public class SequenceThread extends Thread
-{
-
- Das1Source[] sequenceServers;
-
- String sp_accession;
-
- List seqListeners;
-
- String version;
-
- static Logger logger = Logger.getLogger("org.biojava.spice");
-
- public SequenceThread(String sp_accession, Das1Source ds)
- {
- super();
- Das1Source[] dss = new Das1Source[1];
- dss[0] = ds;
- this.sp_accession = sp_accession;
- this.sequenceServers = dss;
- clearSequenceListeners();
- version = "";
- }
-
- public SequenceThread(String sp_accession, Das1Source[] ds)
- {
- super();
-
- this.sp_accession = sp_accession;
- this.sequenceServers = ds;
- clearSequenceListeners();
- }
-
- public void clearSequenceListeners()
- {
- seqListeners = new ArrayList();
- }
-
- public void addSequenceListener(SequenceListener lis)
- {
- seqListeners.add(lis);
- }
-
- public void run()
- {
- getSequence();
- }
-
- public void getSequence()
- {
-
- boolean gotSequence = false;
-
- for (int i = 0; i < sequenceServers.length; i++)
- {
-
- if (gotSequence)
- break;
-
- Das1Source ds = sequenceServers[i];
- String url = ds.getUrl();
- char lastChar = url.charAt(url.length() - 1);
- if (!(lastChar == '/'))
- url += "/";
- String dascmd = url + "sequence?segment=";
- String connstr = dascmd + sp_accession;
-
- try
- {
- version = "";
-
- String sequence = retrieveSequence(connstr);
- // TODO: discriminate exceptions caused by connection/server errors and ones caused by the sequence not being found in the reference source.
- if (sequence!=null)
- {
- // bug in aristotle das source?
- sequence.replaceAll(" ", "");
- gotSequence = true;
- // set the sequence ...
-
- triggerNewSequence(sp_accession, sequence, ds, version);
- }
- return;
- } catch (Exception ex)
- {
- ex.printStackTrace();
- logger.warning(ex.getMessage());
-
- // triggerException(ex);
-
- }
- }
-
- logger
- .log(
- Level.WARNING,
- "could not retreive UniProt sequence from any available DAS sequence server");
-
- triggerNoSequence(sp_accession);
-
- }
-
- // private void triggerException(Exception e){
- // Iterator iter = seqListeners.iterator();
- // while (iter.hasNext()){
- // SequenceListener li = (SequenceListener)iter.next();
- // li.exceptionOccured(e);
- // }
- // }
-
- private void triggerNewSequence(String sp_accession, String sequence,
- Das1Source source, String version)
- {
-
- Iterator iter = seqListeners.iterator();
- while (iter.hasNext())
- {
- SequenceListener li = (SequenceListener) iter.next();
- // SequenceEvent event = new SequenceEvent(sequence);
- SequenceEvent event = new SequenceEvent(sp_accession, sequence,
- version);
- event.setSource(source);
- li.newSequence(event);
- }
- }
-
- private void triggerNoSequence(String ac)
- {
-
- Iterator iter = seqListeners.iterator();
- while (iter.hasNext())
- {
- SequenceListener li = (SequenceListener) iter.next();
- li.noObjectFound(ac);
- }
-
- }
-
- /**
- * retrieve the Sequence from a DAS server.
- *
- * @param connstr -
- * the DAS - request string. e.g.
- * http://www.ebi.ac.uk/das-srv/uniprot/das/aristotle/sequence?segment=P00280
- * @return the requested Sequence
- * @throws Exception
- */
- public String retrieveSequence(String connstr) throws Exception
- {
-
- // logger.finest("trying: " + connstr) ;
- URL dasUrl = new URL(connstr);
- // DAS_httpConnector dhtp = new DAS_httpConnector() ;
- logger.info("requesting sequence from " + connstr);
- InputStream dasInStream = open(dasUrl);
-
- SAXParserFactory spfactory = SAXParserFactory.newInstance();
-
- // never do this
- // String vali = System.getProperty("XMLVALIDATION");
- String vali = "false";
- boolean validate = false;
- if ((vali != null) && (vali.equals("true")))
- validate = true;
- spfactory.setValidating(validate);
-
- SAXParser saxParser = null;
-
- try
- {
- saxParser = spfactory.newSAXParser();
- } catch (ParserConfigurationException e)
- {
- // e.printStackTrace();
- logger.log(Level.FINER, "Uncaught exception", e);
- }
-
- XMLReader xmlreader = saxParser.getXMLReader();
-
- try
- {
- xmlreader.setFeature("http://xml.org/sax/features/validation",
- validate);
- } catch (SAXException e)
- {
- logger.finer("Cannot set validation to " + validate);
- logger.log(Level.FINER, "Uncaught exception", e);
- }
-
- try
- {
- xmlreader
- .setFeature(
- "http://apache.org/xml/features/nonvalidating/load-external-dtd",
- validate);
- } catch (SAXNotRecognizedException e)
- {
- // e.printStackTrace();
- logger.finer("Cannot set load-external-dtd to" + validate);
- logger.log(Level.FINER, "Uncaught exception", e);
- // System.err.println("Cannot set load-external-dtd to" + validate);
- }
- if (dasInStream==null)
- {
- return null;
- }
- // DAS_DNA_Handler cont_handle = new DAS_DNA_Handler() ;
- DAS_Sequence_Handler cont_handle = new DAS_Sequence_Handler();
- xmlreader.setContentHandler(cont_handle);
- xmlreader.setErrorHandler(new org.xml.sax.helpers.DefaultHandler());
- InputSource insource = new InputSource();
- insource.setByteStream(dasInStream);
-
- xmlreader.parse(insource);
- String sequence = cont_handle.get_sequence();
- version = cont_handle.getVersion();
- // logger.finest("Got sequence from DAS: " +sequence);
-
- logger.exiting(this.getClass().getName(), "retreiveSequence", sequence);
- return sequence;
- }
-
- private InputStream open(URL url)
- {
- {
-
- InputStream inStream = null;
- try
- {
-
- HttpURLConnection huc = null;
-
- huc = DAS_FeatureRetrieve.openHttpURLConnection(url);
-
- logger.finest(huc.getResponseMessage());
-
- inStream = huc.getInputStream();
-
- } catch (Exception ex)
- {
- ex.printStackTrace();
- logger.log(Level.WARNING, "exception occured", ex);
- }
-
- return inStream;
- }
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Feb 9, 2006
- *
- */
-package org.biojava.dasobert.das2;
-
-public interface Das2Capability
-{
-
- public boolean equals(Das2Capability other);
-
- public int hashCode();
-
- public void setCapability(String type);
-
- public String getCapability();
-
- public void setQueryUri(String id);
-
- public String getQueryUri();
-
- public void setFormats(String[] formats);
-
- public String[] getFormats();
-
- /**
- * checks if this capability is actually of das1 style
- *
- * @return boolean true if the capability is in DAS1 style
- */
- public boolean isDas1Style();
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Feb 9, 2006
- *
- */
-package org.biojava.dasobert.das2;
-
-public class Das2CapabilityImpl implements Das2Capability
-{
-
- String capability;
-
- String[] formats;
-
- String queryId;
-
- public static String DAS1_CAPABILITY_PREFIX = "das1:";
-
- public Das2CapabilityImpl()
- {
- super();
- capability = "undef";
- queryId = "";
- formats = new String[0];
-
- }
-
- public boolean isDas1Style()
- {
-
- if (capability == null)
- {
- return false;
- }
- if (capability.length() < DAS1_CAPABILITY_PREFIX.length())
- {
- return false;
- }
- if (capability.substring(0, DAS1_CAPABILITY_PREFIX.length()).equals(
- DAS1_CAPABILITY_PREFIX))
- {
- return true;
- }
- return false;
-
- }
-
- public boolean equals(Das2Capability other)
- {
-
- boolean status = true;
-
- if (!capability.equals(other.getCapability()))
- {
- status = false;
- }
- if (!queryId.equals(other.getQueryUri()))
- {
- status = false;
- }
-
- return status;
- }
-
- public int hashCode()
- {
- int h = 7;
- h = 31 * h + (null == capability ? 0 : capability.hashCode());
- h = 31 * h + (null == queryId ? 0 : queryId.hashCode());
-
- return h;
- }
-
- public String toString()
- {
- String txt = "capability " + capability + " queryId " + queryId;
- return txt;
- }
-
- public String getCapability()
- {
-
- return capability;
- }
-
- public String[] getFormats()
- {
- return formats;
- }
-
- public String getQueryUri()
- {
- return queryId;
- }
-
- public void setCapability(String type)
- {
- capability = type;
-
- }
-
- public void setFormats(String[] formats)
- {
-
- this.formats = formats;
- }
-
- public void setQueryUri(String id)
- {
- queryId = id;
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Feb 9, 2006
- *
- */
-package org.biojava.dasobert.das2;
-
-import org.biojava.dasobert.dasregistry.*;
-
-public interface Das2Source extends DasSource
-{
-
- public Das2Capability[] getDas2Capabilities();
-
- public void setDas2Capabilities(Das2Capability[] capabilities);
-
- /**
- * test if this is a DAS1 source represented as a DAS2 source if true - this
- * source can be converted into a DAS1 source by using
- * DasSourceConverter.toDas1(Das2Source);
- *
- * @return true if the DasSource has DAS1 capabilties
- */
- public boolean hasDas1Capabilities();
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Feb 9, 2006
- *
- */
-package org.biojava.dasobert.das2;
-
-import org.biojava.dasobert.dasregistry.*;
-
-public class Das2SourceImpl extends Das1Source implements Das2Source
-
-{
-
- Das2Capability[] capabilities;
-
- public Das2SourceImpl()
- {
- super();
-
- capabilities = new Das2Capability[0];
- }
-
- /**
- * compare if two DasSources are identical
- *
- */
- public boolean equals(DasSource other)
- {
-
- if (this == other)
- {
- return true;
- }
-
- if ((other == null) || (other.getClass() != this.getClass()))
- {
- return false;
- }
-
- // to compare if two Das2Sources are identical we do the following:
- // we check the capabilities
-
- Das2SourceImpl d2o = (Das2SourceImpl) other;
-
- if (nickname.equals(d2o.getNickname()))
- {
- return true;
- }
-
- Das2Capability[] othercaps = d2o.getDas2Capabilities();
-
- if (!(capabilities.length == othercaps.length))
- {
- return false;
- }
-
- for (int x = 0; x < capabilities.length; x++)
- {
- Das2Capability tmpcap = capabilities[x];
- boolean foundCap = false;
- for (int y = 0; y < othercaps.length; y++)
- {
- Das2Capability tmpcapo = othercaps[y];
- if (tmpcap.equals(tmpcapo))
- {
- foundCap = true;
- }
- }
- if (!foundCap)
- {
- return false;
- }
- }
-
- // TODO?
- // should we add a check for coordinate systems?
- // but we already check for the endpoints, that should be enough...
-
- return true;
-
- }
-
- public int hashCode()
- {
- int h = 7;
-
- h = 31 * h + (null == nickname ? 0 : nickname.hashCode());
-
- for (int x = 0; x < capabilities.length; x++)
- {
- Das2Capability cap = capabilities[x];
- h = 31 * h + cap.hashCode();
- }
-
- return h;
- }
-
- public boolean hasDas1Capabilities()
- {
-
- // test if any of the capabilities is a das1 capabilitiy
-
- for (int i = 0; i < capabilities.length; i++)
- {
- Das2Capability cap = capabilities[i];
- if (cap.isDas1Style())
- {
- return true;
- }
- }
- return false;
-
- }
-
- public String[] getCapabilities()
- {
- // todo mark as not needed / not appropriate ...
- return super.getCapabilities();
- }
-
- public void setCapabilities(String[] u)
- {
- // TODO Auto-generated method stub
- super.setCapabilities(u);
- }
-
- public Das2Capability[] getDas2Capabilities()
- {
- // TODO Auto-generated method stub
- return capabilities;
- }
-
- public void setDas2Capabilities(Das2Capability[] capabilities)
- {
- // TODO Auto-generated method stub
- this.capabilities = capabilities;
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Mar 23, 2006
- *
- */
-package org.biojava.dasobert.das2;
-
-// import org.biojava.bio.program.das.dasalignment.DASException;
-import org.biojava.dasobert.dasregistry.*;
-
-public class DasSourceConverter
-{
-
- public DasSourceConverter()
- {
- super();
-
- }
-
- /**
- * convert a das2 source to a das 1 source. This only will work if is passes
- * the Das2Source.isDas1Source() test i.e. this is really a das1 server there
- *
- * @param das2source
- * a DAS2Source to be converted
- * @return a Das1Source
- * @throws DASException
- */
- public static Das1Source toDas1Source(Das2Source das2source)
- throws Exception
- {
- if (!das2source.hasDas1Capabilities())
- {
- throw new Exception(
- "this das source does not have das1 capabilitites");
- }
-
- Das1Source ds = new Das1Source();
- ds.setAdminemail(das2source.getAdminemail());
- ds.setDescription(das2source.getDescription());
- ds.setHelperurl(das2source.getHelperurl());
- ds.setRegisterDate(das2source.getRegisterDate());
- ds.setLeaseDate(das2source.getLeaseDate());
- ds.setLabels(das2source.getLabels());
- ds.setCoordinateSystem(das2source.getCoordinateSystem());
- ds.setNickname(das2source.getNickname());
- ds.setId(das2source.getId());
- ds.setLabels(das2source.getLabels());
-
- // convert the capabilitites to das1 capabiltities and get the url
- Das2Capability[] caps = das2source.getDas2Capabilities();
- String[] das1capabilitites = new String[caps.length];
- int DASPREFIXLENGTH = Das2CapabilityImpl.DAS1_CAPABILITY_PREFIX
- .length();
-
- for (int i = 0; i < caps.length; i++)
- {
- Das2Capability cap = caps[i];
-
- String c = cap.getCapability();
-
- das1capabilitites[i] = c.substring(DASPREFIXLENGTH, c.length());
-
- String query_uri = cap.getQueryUri();
-
- String url = query_uri.substring(0,
- (query_uri.length() - c.length() + DASPREFIXLENGTH));
- ds.setUrl(url);
- }
- ds.setCapabilities(das1capabilitites);
-
- return ds;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Mar 15, 2006
- *
- */
-package org.biojava.dasobert.das2.io;
-
-import java.util.*;
-
-import org.biojava.dasobert.das2.*;
-import org.biojava.dasobert.dasregistry.*;
-import org.xml.sax.*;
-import org.xml.sax.helpers.*;
-
-/**
- * a parser for the DAS2 sources response
- *
- * @author Andreas Prlic
- * @since 6:53:45 PM
- * @version %I% %G%
- */
-public class DAS2SourceHandler extends DefaultHandler
-{
-
- List sources;
-
- Das2Source currentSource;
-
- List coordinates;
-
- List capabilities;
-
- List labels;
-
- public static final String LABELPROPERTY = "label";
-
- public DAS2SourceHandler()
- {
- super();
-
- sources = new ArrayList();
- currentSource = new Das2SourceImpl();
- coordinates = new ArrayList();
- capabilities = new ArrayList();
- labels = new ArrayList();
- }
-
- private void startSource(String uri, String name, String qName,
- Attributes atts)
- {
-
- String id = atts.getValue("uri");
- String title = atts.getValue("title");
- String doc_ref = atts.getValue("doc_href");
- String description = atts.getValue("description");
-
- currentSource.setId(id);
- currentSource.setNickname(title);
- currentSource.setHelperurl(doc_ref);
- currentSource.setDescription(description);
-
- }
-
- private DasCoordinateSystem getCoordinateSystem(String uri, String name,
- String qname, Attributes atts)
- {
- // e.g. uri="http://das.sanger.ac.uk/dasregistry/coordsys/CS_LOCAL6"
- // source="Protein Sequence" authority="UniProt" test_range="P06213" />
- DasCoordinateSystem dcs = new DasCoordinateSystem();
- String id = atts.getValue("uri");
- dcs.setUniqueId(id);
-
- String source = atts.getValue("source");
- dcs.setCategory(source);
-
- String authority = atts.getValue("authority");
- dcs.setName(authority);
-
- String test_range = atts.getValue("test_range");
- dcs.setTestCode(test_range);
-
- try
- {
- String taxidstr = atts.getValue("taxid");
- int taxid = Integer.parseInt(taxidstr);
- dcs.setNCBITaxId(taxid);
- } catch (Exception e)
- {
- }
-
- String version = atts.getValue("version");
- if (version != null)
- {
- dcs.setVersion(version);
- }
-
- return dcs;
- }
-
- public void startElement(String uri, String name, String qName,
- Attributes atts)
- {
- // System.out.println("new element "+qName);
-
- if (qName.equals("SOURCE"))
- {
- // System.out.println("new Source " + atts.getValue(uri));
- currentSource = new Das2SourceImpl();
- coordinates = new ArrayList();
- capabilities = new ArrayList();
-
- startSource(uri, name, qName, atts);
-
- }
- else if (qName.equals("MAINTAINER"))
- {
- String email = atts.getValue("email");
- currentSource.setAdminemail(email);
- }
- else if (qName.equals("COORDINATES"))
- {
- DasCoordinateSystem dcs = getCoordinateSystem(uri, name, qName, atts);
- coordinates.add(dcs);
-
- }
- else if (qName.equals("CAPABILITY"))
- {
- Das2Capability cap = getCapability(uri, name, qName, atts);
- capabilities.add(cap);
- }
- else if (qName.equals("PROPERTY"))
- {
- addProperty(uri, name, qName, atts);
- }
- }
-
- private Das2Capability getCapability(String uri, String name,
- String qName, Attributes atts)
- {
- // e.g <CAPABILITY type="features"
- // query_id="http://das.biopackages.net/das/genome/yeast/S228C/feature" />
- Das2Capability cap = new Das2CapabilityImpl();
-
- String type = atts.getValue("type");
- cap.setCapability(type);
- String query_uri = atts.getValue("query_uri");
- cap.setQueryUri(query_uri);
- return cap;
-
- }
-
- private void addProperty(String uri, String name, String qName,
- Attributes atts)
- {
- String pname = atts.getValue("name");
- String label = atts.getValue("value");
- if (pname.equals(LABELPROPERTY))
- {
- labels.add(label);
- }
- }
-
- public void startDocument()
- {
- sources = new ArrayList();
- coordinates = new ArrayList();
- capabilities = new ArrayList();
- }
-
- public void endElement(String uri, String name, String qName)
- {
- if (qName.equals("SOURCE"))
- {
- currentSource.setDas2Capabilities((Das2Capability[]) capabilities
- .toArray(new Das2Capability[capabilities.size()]));
- // System.out.println("got coordinates " + coordinates.size());
- currentSource.setCoordinateSystem((DasCoordinateSystem[]) coordinates
- .toArray(new DasCoordinateSystem[coordinates.size()]));
-
- currentSource.setLabels((String[]) labels.toArray(new String[labels
- .size()]));
- labels.clear();
-
- // System.out.println("Das2SourceHandler endElement name " + name + " uri
- // " + uri + " qName " + qName);
- // System.out.println("Das2SourceHandler adding to source: " +
- // currentSource.getId());
- sources.add(currentSource);
- currentSource = new Das2SourceImpl();
- }
- }
-
- public DasSource[] getSources()
- {
- // System.out.println("Das2SourceHandler: source size: " + sources.size());
- return (DasSource[]) sources.toArray(new DasSource[sources.size()]);
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Feb 24, 2006
- *
- */
-package org.biojava.dasobert.das2.io;
-
-import java.io.*;
-
-import org.biojava.dasobert.dasregistry.*;
-
-public interface DasSourceReader
-{
-
- public DasSource[] readDasSource(InputStream stream);
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Feb 24, 2006
- *
- */
-package org.biojava.dasobert.das2.io;
-
-import java.io.*;
-import java.net.*;
-import javax.xml.parsers.*;
-
-import org.biojava.dasobert.das.*;
-import org.biojava.dasobert.dasregistry.*;
-import org.xml.sax.*;
-
-public class DasSourceReaderImpl implements DasSourceReader
-{
-
- Exception loggedException;
-
- public DasSourceReaderImpl()
- {
- super();
- loggedException = null;
-
- // open the stream to a server and then parse the result ...
- }
-
- private InputStream open(URL url) throws java.io.IOException,
- java.net.ConnectException
- {
- InputStream inStream = null;
-
- HttpURLConnection huc = DAS_FeatureRetrieve.openHttpURLConnection(url);
-
- inStream = huc.getInputStream();
-
- return inStream;
-
- }
-
- public DasSource[] readDasSource(URL url)
- {
- DasSource[] sources = new DasSource[0];
-
- try
- {
- InputStream stream = open(url);
-
- sources = readDasSource(stream);
- } catch (Exception e)
- {
- System.err.println("Exception for url:"+url);
- e.printStackTrace();
- loggedException = e;
- }
- return sources;
- }
-
- /**
- * read a DAS2 sources response and return a list of DAS sources.
- *
- */
- public DasSource[] readDasSource(InputStream stream)
- {
-
- DasSource[] sources = new DasSource[0];
-
- try
- {
- SAXParserFactory spfactory = SAXParserFactory.newInstance();
-
- spfactory.setValidating(false);
-
- SAXParser saxParser = null;
-
- try
- {
- saxParser = spfactory.newSAXParser();
- } catch (ParserConfigurationException e)
- {
- e.printStackTrace();
- loggedException = e;
- }
-
- String vali = System.getProperty("XMLVALIDATION");
-
- boolean validation = false;
- if (vali != null)
- {
- if (vali.equals("true"))
- {
- validation = true;
- }
- }
-
- XMLReader xmlreader = saxParser.getXMLReader();
-
- // XMLReader xmlreader = XMLReaderFactory.createXMLReader();
- try
- {
- xmlreader.setFeature("http://xml.org/sax/features/validation",
- validation);
- } catch (SAXException e)
- {
- // logger.log(Level.FINE,"Cannot set validation " + validation);
- }
-
- try
- {
- xmlreader
- .setFeature(
- "http://apache.org/xml/features/nonvalidating/load-external-dtd",
- validation);
- } catch (SAXNotRecognizedException e)
- {
- e.printStackTrace();
- // logger.log(Level.FINE,"Cannot set load-external-dtd "+validation);
-
- }
-
- DAS2SourceHandler cont_handle = new DAS2SourceHandler();
-
- xmlreader.setContentHandler(cont_handle);
- xmlreader.setErrorHandler(new org.xml.sax.helpers.DefaultHandler());
- InputSource insource = new InputSource();
- insource.setByteStream(stream);
-
- xmlreader.parse(insource);
- sources = cont_handle.getSources();
-
- } catch (Exception e)
- {
- e.printStackTrace();
- loggedException = e;
- }
- return sources;
- }
-
- public Exception getLoggedException()
- {
- return loggedException;
- }
-
- public static void main(String[] args)
- {
- String url = "http://www.spice-3d.org/dasregistry/das2/sources/";
- DasSourceReaderImpl reader = new DasSourceReaderImpl();
- try
- {
- URL u = new URL(url);
- DasSource[] sources = reader.readDasSource(u);
- for (int i = 0; i < sources.length; i++)
- {
- DasSource ds = sources[i];
- System.out.println(ds.toString());
- }
-
- } catch (Exception e)
- {
- e.printStackTrace();
- }
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 15.04.2004
- * @author Andreas Prlic
- *
- */
-package org.biojava.dasobert.dasregistry;
-
-import java.util.*;
-
-// import org.biojava.dasobert.das2.io.DasSourceWriter;
-// import org.biojava.dasobert.das2.io.DasSourceWriterImpl;
-// import org.biojava.utils.xml.PrettyXMLWriter;
-
-/**
- * a simple Bean class to be returned via SOAP
- *
- * @author Andreas Prlic
- */
-
-public class Das1Source implements DasSource
-{
- String url;
-
- protected String nickname;
-
- String adminemail;
-
- String description;
-
- DasCoordinateSystem[] coordinateSystem;
-
- String[] capabilities;
-
- String[] labels;
-
- String helperurl;
-
- Date registerDate;
-
- Date leaseDate;
-
- String id;
-
- boolean local;
-
- Map properties;
-
- boolean alertAdmin;
-
- public static String EMPTY_ID = "UNK:-1";
-
- public Das1Source()
- {
- id = EMPTY_ID;
- url = "";
- adminemail = "";
- description = "";
- // String empty = "" ;
- nickname = "";
- coordinateSystem = new DasCoordinateSystem[0];
- // coordinateSystem[0] = new DasCoordinateSystem();
- capabilities = new String[0];
- labels = new String[0];
- // capabilities[0] = empty ;
- registerDate = new Date();
- leaseDate = new Date();
- helperurl = "";
- local = true;
- }
-
- public boolean equals(DasSource other)
- {
- System.out.println("Das1Source equals, comparing with other DasSource");
- if (!(other instanceof Das1Source))
- {
- return false;
- }
-
- Das1Source ods = (Das1Source) other;
-
- if (ods.getUrl().equals(url))
- {
- return true;
- }
- if (ods.getNickname().equals(nickname))
- {
- return true;
- }
- return false;
- }
-
- public int hashCode()
- {
- int h = 7;
-
- h = 31 * h + (null == nickname ? 0 : nickname.hashCode());
- h = 31 * h + (null == url ? 0 : url.hashCode());
-
- return h;
- }
-
- /**
- * the DAS2 string representation of this DAS source
- *
- * public String toString() {
- *
- * StringWriter writer = new StringWriter();
- *
- * PrintWriter pw = new PrintWriter(writer); PrettyXMLWriter xw = new
- * PrettyXMLWriter(pw);
- *
- * DasSourceWriter dswriter = new DasSourceWriterImpl(); try {
- * dswriter.writeDasSource(xw,this); } catch (IOException e){
- * e.printStackTrace(); }
- *
- * return writer.toString();
- * }
- */
- public void setLocal(boolean flag)
- {
- local = flag;
- }
-
- public boolean isLocal()
- {
- return local;
- }
-
- public void setId(String i)
- {
- id = i;
- }
-
- /**
- * get a the Id of the DasSource. The Id is a unique db identifier. The public
- * DAS-Registry has Auto_Ids that look like DASSOURCE:12345; public look like
- * XYZ:12345, where the XYZ prefix can be configured in the config file.
- */
- public String getId()
- {
- return id;
- }
-
- public void setNickname(String name)
- {
- nickname = name;
- }
-
- public String getNickname()
- {
- return nickname;
- }
-
- public void setUrl(String u)
- {
- char lastChar = u.charAt(u.length() - 1);
- if (lastChar != '/')
- {
- u += "/";
- }
-
- url = u;
- }
-
- public void setAdminemail(String u)
- {
- adminemail = u;
- }
-
- public void setDescription(String u)
- {
- description = u;
- }
-
- public void setCoordinateSystem(DasCoordinateSystem[] u)
- {
- coordinateSystem = u;
- }
-
- public void setCapabilities(String[] u)
- {
- capabilities = u;
- }
-
- public String getUrl()
- {
- return url;
- }
-
- public String getAdminemail()
- {
- return adminemail;
- }
-
- public String getDescription()
- {
- return description;
- }
-
- public String[] getCapabilities()
- {
- return capabilities;
- }
-
- /**
- * test if a this source has a particular capability
- *
- * @param testCapability
- * @return <code>true</code> if the server has this capability.
- */
- public boolean hasCapability(String testCapability)
- {
- for (int i = 0; i < capabilities.length; i++)
- {
- String cap = capabilities[i];
- if (cap.equals(testCapability))
- return true;
- }
- return false;
- }
-
- public DasCoordinateSystem[] getCoordinateSystem()
- {
- return coordinateSystem;
- }
-
- public void setRegisterDate(Date d)
- {
- registerDate = d;
- }
-
- public Date getRegisterDate()
- {
- return registerDate;
- }
-
- public void setLeaseDate(Date d)
- {
- leaseDate = d;
- }
-
- public Date getLeaseDate()
- {
- return leaseDate;
- }
-
- public void setLabels(String[] ls)
- {
- labels = ls;
- }
-
- public String[] getLabels()
- {
- return labels;
- }
-
- public void setHelperurl(String url)
- {
- helperurl = url;
- }
-
- public String getHelperurl()
- {
- return helperurl;
- }
-
- public void setAlertAdmin(boolean flag)
- {
- alertAdmin = flag;
- }
-
- public boolean getAlertAdmin()
- {
- return alertAdmin;
- }
-
- public Map getProperties()
- {
- return properties;
- }
-
- public void setProperties(Map properties)
- {
- this.properties = properties;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Mar 20, 2006
- *
- */
-package org.biojava.dasobert.dasregistry;
-
-import org.biojava.dasobert.das2.*;
-
-public class Das2Validator
-{
-
- public Das2Validator()
- {
- super();
-
- }
-
- public boolean validate(Das2Source ds)
- {
-
- // TODO this bit still needs to be implemented!
-
- return true;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 15.04.2004
- * @author Andreas Prlic
- *
- */
-
-package org.biojava.dasobert.dasregistry;
-
-import java.util.*;
-
-/**
- * a comparator to sort DasSources
- *
- * @author Andreas Prlic
- */
-
-public abstract class DasCoordSysComparator implements Comparator
-{
-
- private final String name;
-
- private static final Map COMPS_BY_NAME;
-
- public DasCoordSysComparator(String str)
- {
- // System.out.println("new dasSourceComparator " + str);
- name = str;
- }
-
- public static final Comparator BY_NAME = new DasCoordSysComparator("name")
- {
- protected Comparable getField(DasCoordinateSystem ds)
- {
- return ds.getName();
- }
- };
-
- public static final Comparator BY_ID = new DasCoordSysComparator("id")
- {
- protected Comparable getField(DasCoordinateSystem ds)
- {
- return ds.getUniqueId();
- }
- };
-
- public static final Comparator BY_CATEGORY = new DasCoordSysComparator(
- "category")
- {
- protected Comparable getField(DasCoordinateSystem ds)
- {
- return ds.getCategory();
- }
- };
-
- public static final Comparator BY_ORGANISM = new DasCoordSysComparator(
- "organism")
- {
- protected Comparable getField(DasCoordinateSystem ds)
- {
- return ds.getOrganismName();
- }
- };
-
- public static final Comparator BY_TAXID = new DasCoordSysComparator(
- "taxid")
- {
- protected Comparable getField(DasCoordinateSystem ds)
- {
- return ds.getNCBITaxId() + "";
- }
- };
-
- static
- {
- COMPS_BY_NAME = new HashMap();
- COMPS_BY_NAME.put(BY_ID.toString(), BY_ID);
- COMPS_BY_NAME.put(BY_NAME.toString(), BY_NAME);
- COMPS_BY_NAME.put(BY_CATEGORY.toString(), BY_CATEGORY);
- COMPS_BY_NAME.put(BY_ORGANISM.toString(), BY_ORGANISM);
- COMPS_BY_NAME.put(BY_TAXID.toString(), BY_TAXID);
- }
-
- public static Comparator fromString(String name)
- {
- if (COMPS_BY_NAME.containsKey(name))
- {
- return (Comparator) COMPS_BY_NAME.get(name);
- }
- else
- {
- throw new IllegalArgumentException("Can't compare by key " + name);
- }
- }
-
- protected abstract Comparable getField(DasCoordinateSystem ds);
-
- /** compare two DasCoordSys objects */
- public int compare(Object a, Object b)
- {
- DasCoordinateSystem x = (DasCoordinateSystem) a;
- DasCoordinateSystem y = (DasCoordinateSystem) b;
- return getField(x).compareTo(getField(y));
- }
-
- public String toString()
- {
- return name;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 15.04.2004
- * @author Andreas Prlic
- *
- */
-package org.biojava.dasobert.dasregistry;
-
-/**
- * a Bean to be returned via SOAP. It takes care of the DAS - coordinate Systems
- *
- * @author Andreas Prlic
- */
-public class DasCoordinateSystem
-{
-
- String name;
-
- String category;
-
- String organism_name;
-
- int ncbi_tax_id;
-
- String uniqueId;
-
- String version;
-
- String testCode;
-
- public DasCoordinateSystem()
- {
- uniqueId = "";
- name = "";
- category = "";
- organism_name = "";
- ncbi_tax_id = 0;
- version = "";
- testCode = "";
- }
-
- public boolean equals(DasCoordinateSystem other)
- {
- boolean match = true;
- System.out.println("comparing " + this.toString() + " to "
- + other.toString());
- // URI has piority
- if ((!uniqueId.equals("")) && (uniqueId.equals(other.getUniqueId())))
- {
- return true;
- }
-
- if (ncbi_tax_id != other.getNCBITaxId())
- {
- System.out.println("mismatch in ncbi tax id " + ncbi_tax_id + " != "
- + other.getNCBITaxId());
- match = false;
- }
- if (!version.equals(other.getVersion()))
- {
- System.out.println("mismatch in version");
- match = false;
- }
- if (!category.equals(other.getCategory()))
- {
- System.out.println("mismatch in category");
- match = false;
- }
- if (!name.equals(other.getName()))
- {
- System.out.println("mismatch in name");
- match = false;
- }
- System.out.println(" match: " + match);
-
- return match;
- }
-
- public int hashCode()
- {
- int h = 7;
-
- h = 31 * h + (null == name ? 0 : name.hashCode());
- h = 31 * h + (null == category ? 0 : category.hashCode());
-
- return h;
- }
-
- public Object clone()
- {
- DasCoordinateSystem d = new DasCoordinateSystem();
- d.setTestCode(testCode);
- d.setCategory(category);
- d.setName(name);
- d.setNCBITaxId(ncbi_tax_id);
- d.setUniqueId(getUniqueId());
- d.setOrganismName(getOrganismName());
- d.setVersion(getVersion());
- return d;
- }
-
- public String getTestCode()
- {
- return testCode;
- }
-
- public void setTestCode(String testCode)
- {
- if (testCode == null)
- {
- testCode = "";
- }
- this.testCode = testCode;
- }
-
- public void setUniqueId(String id)
- {
- uniqueId = id;
- }
-
- public String getUniqueId()
- {
- return uniqueId;
- }
-
- public void setName(String n)
- {
- name = n;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setCategory(String c)
- {
- category = c;
- }
-
- public String getCategory()
- {
- return category;
- }
-
- public void setOrganismName(String t)
- {
- organism_name = t;
- }
-
- public String getOrganismName()
- {
- return organism_name;
- }
-
- public void setNCBITaxId(int id)
- {
- ncbi_tax_id = id;
- }
-
- public int getNCBITaxId()
- {
- return ncbi_tax_id;
- }
-
- public String getVersion()
- {
- return version;
- }
-
- public void setVersion(String version)
- {
- if (version == null)
- {
- version = "";
- }
- this.version = version;
- }
-
- public String toString()
- {
- String nam = name;
- if (!version.equals(""))
- {
- nam += "_" + version;
- }
-
- if (organism_name.equals(""))
- {
- return nam + "," + category;
- }
- else
- {
- return nam + "," + category + "," + organism_name;
- }
- }
-
- public static DasCoordinateSystem fromString(String rawString)
- {
- String[] spl = rawString.split(",");
- DasCoordinateSystem dcs = new DasCoordinateSystem();
- if (spl.length == 2)
- {
- dcs.setName(spl[0]);
- dcs.setCategory(spl[1]);
- }
- if (spl.length == 3)
- {
- dcs.setName(spl[0]);
- dcs.setCategory(spl[1]);
- dcs.setOrganismName(spl[2]);
- }
- return dcs;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Feb 8, 2006
- *
- */
-package org.biojava.dasobert.dasregistry;
-
-import java.util.*;
-
-public interface DasSource
-{
-
- public void setLocal(boolean flag);
-
- public boolean isLocal();
-
- /**
- * compare if two das sources are equal
- *
- * @param ds
- * @return returns true if two DAS sources are equivalent
- */
- public boolean equals(DasSource ds);
-
- /**
- * classes that implement equals, should also implement hashKey
- *
- * @return the hash code of a das source
- */
- public int hashCode();
-
- public void setId(String i);
-
- /**
- * get a the Id of the DasSource. The Id is a unique db identifier. The public
- * DAS-Registry has Auto_Ids that look like DASSOURCE:12345; public look like
- * XYZ:12345, where the XYZ prefix can be configured in the config file.
- *
- * @return String the ID of a Das Source
- */
- public String getId();
-
- public void setNickname(String name);
-
- public String getNickname();
-
- public void setUrl(String u);
-
- public void setAdminemail(String u);
-
- public void setDescription(String u);
-
- public void setCoordinateSystem(DasCoordinateSystem[] u);
-
- public void setCapabilities(String[] u);
-
- /**
- * test if a this source has a particular capability
- *
- * @param testCapability
- * @return <code>true</code> if the server has this capability.
- */
- public boolean hasCapability(String testCapability);
-
- public String getUrl();
-
- public String getAdminemail();
-
- public String getDescription();
-
- public String[] getCapabilities();
-
- public DasCoordinateSystem[] getCoordinateSystem();
-
- public void setRegisterDate(Date d);
-
- public Date getRegisterDate();
-
- public void setLeaseDate(Date d);
-
- public Date getLeaseDate();
-
- public void setLabels(String[] ls);
-
- public String[] getLabels();
-
- public void setHelperurl(String url);
-
- public String getHelperurl();
-
- // TestCode is now part of the coordinate system!
- // public void setTestCode(String code);
- // public String getTestCode();
-
- public void setAlertAdmin(boolean flag);
-
- public boolean getAlertAdmin();
-
- /**
- * set Properties for this DAS source, e.g. project name
- *
- * @param properties
- */
- public void setProperties(Map properties);
-
- /**
- * get Properties for this DAS source
- *
- * @return Properties
- */
- public Map getProperties();
-
-}
\ No newline at end of file
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 15.04.2004
- * @author Andreas Prlic
- *
- */
-
-package org.biojava.dasobert.dasregistry;
-
-import java.util.*;
-
-/**
- * a comparator to sort DasSources
- *
- * @author Andreas Prlic, Thomas Down
- */
-
-public abstract class DasSourceComparator implements Comparator
-{
-
- private final String name;
-
- private static final Map COMPS_BY_NAME;
-
- private static final int TWODAYS = 1000 * 60 * 60 * 24 * 2;
-
- public DasSourceComparator(String str)
- {
- // System.out.println("new dasSourceComparator " + str);
- name = str;
- }
-
- public static final Comparator BY_ID = new DasSourceComparator("id")
- {
- protected Comparable getField(DasSource ds)
- {
- return ds.getId();
- }
- };
-
- public static final Comparator BY_NICKNAME = new DasSourceComparator(
- "nickname")
- {
- protected Comparable getField(DasSource ds)
- {
- return ds.getNickname();
- }
- };
-
- public static final Comparator BY_STATUS = new DasSourceComparator(
- "status")
- {
- protected Comparable getField(DasSource ds)
- {
-
- Date now = new Date();
-
- if (ds.getLeaseDate().getTime() < (now.getTime() - TWODAYS))
- return new Integer(0);
- return new Integer(1);
- }
- };
-
- public static final Comparator BY_REGISTER_DATE = new DasSourceComparator(
- "registerdate")
- {
- protected Comparable getField(DasSource ds)
- {
- return ds.getRegisterDate();
- }
- };
-
- public static final Comparator BY_LEASE_DATE = new DasSourceComparator(
- "leasedate")
- {
- protected Comparable getField(DasSource ds)
- {
- return ds.getLeaseDate();
- }
- };
-
- public static final Comparator BY_URL = new DasSourceComparator("url")
- {
- protected Comparable getField(DasSource ds)
- {
- return ds.getUrl();
- }
- };
-
- public static final Comparator BY_ADMIN_EMAIL = new DasSourceComparator(
- "adminemail")
- {
- protected Comparable getField(DasSource ds)
- {
- return ds.getAdminemail();
- }
- };
-
- public static final Comparator BY_DESCRIPTION = new DasSourceComparator(
- "description")
- {
- protected Comparable getField(DasSource ds)
- {
- return ds.getDescription();
- }
- };
-
- public static final Comparator BY_CAPABILITIES = new DasSourceComparator(
- "capabilities")
- {
- protected Comparable getField(DasSource ds)
- {
- String[] caps = ds.getCapabilities();
- return caps.length == 0 ? "" : caps[0];
- }
- };
-
- public static final Comparator BY_COORDINATE_SYSTEM = new DasSourceComparator(
- "coordinateSystem")
- {
- protected Comparable getField(DasSource ds)
- {
- DasCoordinateSystem[] dcss = ds.getCoordinateSystem();
- return dcss.length == 0 ? "" : dcss[0].toString();
- }
- };
-
- static
- {
- COMPS_BY_NAME = new HashMap();
- COMPS_BY_NAME.put(BY_ID.toString(), BY_ID);
- COMPS_BY_NAME.put(BY_NICKNAME.toString(), BY_NICKNAME);
- COMPS_BY_NAME.put(BY_REGISTER_DATE.toString(), BY_REGISTER_DATE);
- COMPS_BY_NAME.put(BY_LEASE_DATE.toString(), BY_LEASE_DATE);
- COMPS_BY_NAME.put(BY_URL.toString(), BY_URL);
- COMPS_BY_NAME.put(BY_ADMIN_EMAIL.toString(), BY_ADMIN_EMAIL);
- COMPS_BY_NAME.put(BY_DESCRIPTION.toString(), BY_DESCRIPTION);
- COMPS_BY_NAME.put(BY_CAPABILITIES.toString(), BY_CAPABILITIES);
- COMPS_BY_NAME
- .put(BY_COORDINATE_SYSTEM.toString(), BY_COORDINATE_SYSTEM);
- COMPS_BY_NAME.put(BY_STATUS.toString(), BY_STATUS);
-
- }
-
- public static Comparator fromString(String name)
- {
- if (COMPS_BY_NAME.containsKey(name))
- {
- return (Comparator) COMPS_BY_NAME.get(name);
- }
- else
- {
- throw new IllegalArgumentException("Can't compare by key " + name);
- }
- }
-
- protected abstract Comparable getField(DasSource ds);
-
- /** compare two DasSource objects */
- public int compare(Object a, Object b)
- {
-
- DasSource x = (DasSource) a;
- DasSource y = (DasSource) b;
- return getField(x).compareTo(getField(y));
- }
-
- public String toString()
- {
- return name;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Nov 17, 2006
- *
- */
-
-package org.biojava.dasobert.eventmodel;
-
-import org.biojava.dasobert.dasregistry.Das1Source;
-
-public class AbstractDasEvent
-{
-
- Das1Source dasSource;
-
- public Das1Source getSource()
- {
- return dasSource;
- }
-
- public void setSource(Das1Source source)
- {
- this.dasSource = source;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Oct 28, 2005
- *
- */
-package org.biojava.dasobert.eventmodel;
-
-import java.util.*;
-
-import org.biojava.dasobert.dasregistry.*;
-
-public class FeatureEvent extends AbstractDasEvent
-{
-
- Map[] features;
-
- int comeBackLater;
-
- String version;
-
- public FeatureEvent(Map[] features, Das1Source dasSource, String version)
- {
- super();
- this.features = features;
- this.dasSource = dasSource;
- comeBackLater = -1;
- this.version = version;
- }
-
- public int getComeBackLater()
- {
- return comeBackLater;
- }
-
- public void setComeBackLater(int comeBackLater)
- {
- this.comeBackLater = comeBackLater;
- }
-
- /**
- * get the features that have been found.
- *
- * do something like Map[] features = event.getFeatures();
- *
- * <pre>
- * for (int i = 0; i < features; i++)
- * {
- * Map f = features[i];
- * String type = (String) f.get("TYPE");
- * System.out.println(type);
- * }
- * </pre>
- *
- * @return a Map containng the features
- */
- public Map[] getFeatures()
- {
- return features;
- }
-
- /**
- * Get the version of the reference object that has been annotated. Compare
- * the version string with the version string obtained from the reference
- * server. If they don;t match there is a version problem between the
- * annotation and the reference!
- *
- * @return the version string (e.g. an MD5 digest of the reference sequence)
- */
- public String getVersion()
- {
- return version;
- }
-
- public void setVersion(String version)
- {
- this.version = version;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Oct 28, 2005
- *
- */
-package org.biojava.dasobert.eventmodel;
-
-// import org.biojava.spice.multipanel.eventmodel.FeatureEvent;
-
-/**
- * a feature listener that returns the raw features as returned by a DAS source.
- *
- */
-public interface FeatureListener
-{
-
- /**
- * new features have been returned from the Annotation server
- *
- * @param e
- */
- public void newFeatures(FeatureEvent e);
-
- /**
- * the server says that he is busy and we should try again in x seconds
- *
- * @param e
- */
- public void comeBackLater(FeatureEvent e);
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Nov 1, 2005
- *
- */
-package org.biojava.dasobert.eventmodel;
-
-/**
- * an interface for the listeners of new PDB code requested / new Uniprot code
- * requested
- *
- * @author Andreas Prlic
- *
- */
-public interface ObjectListener
-{
-
- /**
- * a new object has been requested
- *
- * @param accessionCode
- */
- public void newObjectRequested(String accessionCode);
-
- /**
- * no object with that accessionCode has been found
- *
- * @param accessionCode
- */
- public void noObjectFound(String accessionCode);
-
- // public void exceptionOccured(Exception e);
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Nov 20, 2005
- *
- */
-package org.biojava.dasobert.eventmodel;
-
-public class SequenceEvent extends AbstractDasEvent
-{
-
- String sequence;
-
- String accessionCode;
-
- String version;
-
- public SequenceEvent(String accessionCode, String seq, String version)
- {
- super();
- sequence = seq;
- this.accessionCode = accessionCode;
- this.version = version; // bugfix here ?
- }
-
- public String getAccessionCode()
- {
- return accessionCode;
- }
-
- public String getSequence()
- {
- return sequence;
- }
-
- public String getVersion()
- {
- return version;
- }
-
- public void setVersion(String version)
- {
- this.version = version;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Jun 10, 2005
- *
- */
-package org.biojava.dasobert.eventmodel;
-
-/**
- * An interface fore events related to selections of sequence position, sequence
- * range and locking of the selection.
- *
- * @author Andreas Prlic
- *
- */
-public interface SequenceListener extends ObjectListener
-{
-
- /* select a certain sequence position */
- public void selectedSeqPosition(int position);
-
- /**
- * select a certain range of a sequence
- *
- * @param start
- * the start
- * @param end
- * the end of the range
- */
- public void selectedSeqRange(int start, int end);
-
- /**
- * the current selecetion is locked and can not be changed
- *
- * @param flag
- * true if selection should be locked
- */
- public void selectionLocked(boolean flag);
-
- public void newSequence(SequenceEvent e);
-
- /**
- * clear what has been selected
- *
- *
- */
- public void clearSelection();
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Feb 9, 2005
- *
- */
-package org.biojava.dasobert.feature;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * An Abstract class representing a Feature as being diplayed in the
- * SeqFeaturePanel A feature corresponds to everything that is visible in a
- * "line" and can contain one or multiple Segments.
- *
- *
- * @author Andreas Prlic
- *
- */
-public abstract class AbstractFeatureTrack implements FeatureTrack,
- Cloneable
-{
-
- String name;
-
- String method;
-
- String type;
-
- List segments;
-
- String note;
-
- String link;
-
- String source;
-
- String score;
-
- String orientation;
-
- String typeID;
-
- String typeCategory;
-
- public AbstractFeatureTrack()
- {
- source = "Unknown";
- method = "Unknown";
- type = "Unknown";
- note = "";
- link = "";
- score = "";
- orientation = null;
- segments = new ArrayList();
-
- }
-
- public abstract Object clone();
-
- public String toString()
- {
- String str = "Feature: method: " + method + " type: " + type;
- if (name != null)
- str += " name: " + name;
-
- if ((note != null) && (!note.equals("null")))
- {
- if (note.length() > 40)
- str += "note: " + note.substring(0, 39) + "...";
- else
- str += " note: " + note;
- }
- str += " # segments: " + segments.size();
- return str;
- }
-
- /**
- * returns true if the specified sequence position is within the range of this
- * Feature
- *
- * @param seqPosition
- * the position to check
- * @return true if the position is within the ranges of the segments of this
- * feature
- */
- public boolean overlaps(int seqPosition)
- {
- List segments = getSegments();
- Iterator iter = segments.iterator();
-
- while (iter.hasNext())
- {
-
- Segment seg = (Segment) iter.next();
- if (seg.overlaps(seqPosition))
- return true;
- }
-
- return false;
- }
-
- public void setSource(String s)
- {
- source = s;
- }
-
- public String getSource()
- {
- return source;
- };
-
- public void setName(String nam)
- {
- name = nam;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setMethod(String methd)
- {
- method = methd;
- }
-
- public String getMethod()
- {
- return method;
- }
-
- public void setType(String typ)
- {
- type = typ;
- }
-
- public String getType()
- {
- return type;
- }
-
- public void setNote(String nte)
- {
- if (nte != null)
- note = nte;
- }
-
- public String getNote()
- {
- return note;
- }
-
- public void setLink(String lnk)
- {
- link = lnk;
- }
-
- public String getLink()
- {
- return link;
- }
-
- public void setScore(String s)
- {
- score = s;
- }
-
- public String getScore()
- {
- return score;
- }
-
- /** add a segment to this feature */
- public void addSegment(int start, int end, String name)
- {
- Segment s = new SegmentImpl();
- s.setStart(start);
- s.setEnd(end);
- s.setName(name);
- s.setParent(this);
- segments.add(s);
- }
-
- public void addSegment(Segment s)
- {
- s.setParent(this);
- segments.add(s);
- }
-
- public List getSegments()
- {
- return segments;
- }
-
- public String getOrientation()
- {
- return orientation;
- }
-
- public void setOrientation(String orientation)
- {
- this.orientation = orientation;
- }
-
- /**
- * test if two features are equivalent important: only comares type,method and
- * source. The individual segments are not compared!
- *
- */
- public boolean equals(FeatureTrack feat)
- {
- // if ( note == null) {
- // if (( feat.getNote() == null ) ||
- // ( feat.getNote().equals(""))) {
- // } else if ( this.note.equals(feat.getNote())){
- // return true;
- // }
- if (this.type.equals(feat.getType()))
- {
- if (this.method.equals(feat.getMethod()))
- {
- if (this.source.equals(feat.getSource()))
- {
- if (this.note.equals(feat.getNote()))
- {
- return true;
- }
- }
- }
- }
- return false;
-
- }
-
- public String getTypeCategory()
- {
- // TODO Auto-generated method stub
- return typeCategory;
- }
-
- public String getTypeID()
- {
- // TODO Auto-generated method stub
- return typeID;
- }
-
- public void setTypeCategory(String typeCategory)
- {
- this.typeCategory = typeCategory;
-
- }
-
- public void setTypeID(String typeID)
- {
- this.typeID = typeID;
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on May 22, 2007
- *
- */
-
-package org.biojava.dasobert.feature;
-
-import java.awt.Color;
-
-public abstract class AbstractSegment implements Segment, Cloneable
-{
- int start;
-
- int end;
-
- String name;
-
- Color color;
-
- FeatureTrack parent;
-
- String txtColor;
-
- String note;
-
- public abstract Object clone();
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#toString()
- */
- public String toString()
- {
- String str = "Segment: " + name + " " + start + " " + end;
- if ((note != null) && (!note.equals("null")))
- if (note.length() > 40)
- str += note.substring(0, 39) + "...";
- else
- str += note;
- return str;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#getNote()
- */
- public String getNote()
- {
- return note;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#setNote(java.lang.String)
- */
- public void setNote(String note)
- {
- this.note = note;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#setStart(int)
- */
- public void setStart(int strt)
- {
- start = strt;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#getStart()
- */
- public int getStart()
- {
- return start;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#setEnd(int)
- */
- public void setEnd(int ed)
- {
- end = ed;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#getEnd()
- */
- public int getEnd()
- {
- return end;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#setName(java.lang.String)
- */
- public void setName(String nam)
- {
- name = nam;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#getName()
- */
- public String getName()
- {
- return name;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#setColor(java.awt.Color)
- */
- public void setColor(Color col)
- {
- color = col;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#getColor()
- */
- public Color getColor()
- {
- return color;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#setParent(org.biojava.spice.feature.Feature)
- */
- public void setParent(FeatureTrack f)
- {
- parent = f;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#getParent()
- */
- public FeatureTrack getParent()
- {
- return parent;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#setTxtColor(java.lang.String)
- */
- public void setTxtColor(String str)
- {
- txtColor = str;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#getTxtColor()
- */
- public String getTxtColor()
- {
- return txtColor;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#overlaps(int)
- */
- public boolean overlaps(int seqPosition)
- {
- if ((getStart() <= seqPosition) && (getEnd() >= seqPosition))
- {
- return true;
- }
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.biojava.spice.feature.SegmentIF#overlaps(org.biojava.spice.feature.Segment)
- */
- public boolean overlaps(Segment segment)
- {
- if (!(this.start <= this.end))
- throw new IndexOutOfBoundsException("start > end for segment" + this);
-
- if (!(segment.getStart() <= segment.getEnd()))
- throw new IndexOutOfBoundsException("start > end for segment"
- + segment);
-
- // start must be in region of other
- if (this.start >= segment.getStart())
- {
- if (this.start <= segment.getEnd())
- {
- return true;
- }
- }
- // or end must be in region of other..
- if (this.end >= segment.getStart())
- {
- if (this.end <= segment.getEnd())
- {
- return true;
- }
- }
-
- if (this.start <= segment.getStart())
- {
- if (this.end >= segment.getEnd())
- {
- return true;
- }
- }
- return false;
- }
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 23.09.2004
- * @author Andreas Prlic
- *
- */
-
-package org.biojava.dasobert.feature;
-
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * a comparator to sort Features byt type
- *
- * @author Andreas Prlic
- */
-
-public class FeatureComparator implements Comparator
-{
-
- public FeatureComparator()
- {
- }
-
- public int compare(Object a, Object b)
- {
- FeatureTrack x = (FeatureTrack) a;
- FeatureTrack y = (FeatureTrack) b;
-
- String typea = x.getType();
- String typeb = y.getType();
-
- if (!typea.equals(typeb))
- return typea.compareTo(typeb);
-
- List s1 = x.getSegments();
- List s2 = y.getSegments();
-
- Iterator iter1 = s1.iterator();
- Iterator iter2 = s2.iterator();
-
- while (iter1.hasNext())
- {
- Segment seg1 = (Segment) iter1.next();
- int start1 = seg1.getStart();
-
- while (iter2.hasNext())
- {
- Segment seg2 = (Segment) iter2.next();
- int start2 = seg2.getStart();
-
- if (start1 < start2)
- {
- return -1;
- }
- if (start1 > start2)
- {
- return 1;
- }
-
- }
- }
-
- return 0;
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 23.09.2004
- * @author Andreas Prlic
- *
- */
-
-package org.biojava.dasobert.feature;
-
-import java.util.Comparator;
-import java.util.Map;
-
-/**
- * a comparator to sort Features if they are still in a Map ( sorts by type )
- *
- * @author Andreas Prlic
- */
-
-public class FeatureMapComparator implements Comparator
-{
-
- public FeatureMapComparator()
- {
- }
-
- public int compare(Object a, Object b)
- {
- Map x = (Map) a;
- Map y = (Map) b;
-
- String typea = (String) x.get("TYPE");
- String typeb = (String) y.get("TYPE");
-
- if (isSecstruc(typea) && isSecstruc(typeb))
- {
- return 0;
- }
- return typea.compareTo(typeb);
- }
-
- public boolean isSecstruc(String type)
- {
- if (type.equals("HELIX") || type.equals("STRAND")
- || type.equals("TURN"))
- {
- return true;
- }
- return false;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Feb 9, 2005
- *
- */
-package org.biojava.dasobert.feature;
-
-import java.util.List;
-
-/**
- * A feature corresponds to a track in Ensembl
- *
- * @author Andreas Prlic
- *
- */
-public interface FeatureTrack
-{
-
- public Object clone();
-
- /**
- * returns true if the specified sequence position is within the range of this
- * Feature
- *
- * @param seqPosition
- * the position to check
- * @return true if the position is within the ranges of the segments of this
- * feature
- */
- public boolean overlaps(int seqPosition);
-
- public String toString();
-
- public void setSource(String s);
-
- public String getSource();
-
- public void setName(String nam);
-
- public String getName();
-
- public void setMethod(String methd);
-
- public String getMethod();
-
- public void setType(String typ);
-
- public String getType();
-
- public void setNote(String nte);
-
- public String getNote();
-
- public void setLink(String lnk);
-
- public String getLink();
-
- public void setScore(String score);
-
- public String getScore();
-
- public void setOrientation(String orientation);
-
- public String getOrientation();
-
- /**
- * test if two features are equivalent
- *
- * @param feat
- * feature to compare with
- * @return true if equivalend
- */
- public abstract boolean equals(FeatureTrack feat);
-
- /**
- * add a segment to this feature
- *
- * @param start
- * position
- * @param end
- * position
- * @param name
- * of feature
- */
- public abstract void addSegment(int start, int end, String name);
-
- public abstract void addSegment(Segment s);
-
- public abstract List getSegments();
-
- /**
- * set the data from the DAS - type - id field (used for Ontology support)
- *
- * @param typeID
- */
- public void setTypeID(String typeID);
-
- /**
- * set the data from the DAS - type - category field (used for Ontology
- * support)
- *
- * @param typeCategory
- */
- public void setTypeCategory(String typeCategory);
-
- public String getTypeID();
-
- public String getTypeCategory();
-
-}
\ No newline at end of file
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on Dec 5, 2007
- *
- */
-
-package org.biojava.dasobert.feature;
-
-import java.awt.Color;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * converts the features from their "raw" representation as a Map into a Feature
- * class
- *
- * @author Andreas Prlic
- *
- */
-public class FeatureTrackConverter
-{
-
- public static final Color HELIX_COLOR = new Color(255, 51, 51);
-
- public static final Color STRAND_COLOR = new Color(255, 204, 51);
-
- public static final Color TURN_COLOR = new Color(204, 204, 204);
-
- // some annotation types, for which there is a special treatment
- public static final String DISULFID_TYPE = "DISULFID";
-
- public static final String SECSTRUC_TYPE = "SECSTRUC";
-
- public static final String METAL_TYPE = "METAL";
-
- public static final String MSD_SITE_TYPE = "MSD_SITE";
-
- String type;
-
- public static final String TYPE_HISTOGRAM = "histogram";
-
- public static final String TYPE_DEFAULT = "default";
-
- // rotate between these colors
- public static final Color[] entColors = new Color[]
- { new Color(51, 51, 255), // blue
- new Color(102, 255, 255), // cyan
- new Color(153, 255, 153), // green
- new Color(153, 255, 153), // green
- new Color(255, 153, 153), // pink
- new Color(255, 51, 51), // red
- new Color(255, 51, 255) // pink
- };
-
- public static final String[] txtColors = new String[]
- { "blue", "pink", "green", "yellow", "red", "cyan", "pink" };
-
- Map[] stylesheet;
-
- boolean isHistogram = false;
-
- public FeatureTrackConverter()
- {
- type = TYPE_DEFAULT;
- stylesheet = new Map[0];
- }
-
- public FeatureTrackConverter(Map[] stylesheet)
- {
-
- if (stylesheet == null)
- stylesheet = new Map[0];
-
- this.stylesheet = stylesheet;
-
- }
-
- public FeatureTrackConverter(Map[] stylesheet, boolean isHistogram)
- {
- this(stylesheet);
- this.isHistogram = isHistogram;
- if (isHistogram)
- type = TYPE_HISTOGRAM;
- }
-
- public String getType()
- {
- return type;
- }
-
- public void setType(String type)
- {
- if (type.equals(TYPE_HISTOGRAM))
- isHistogram = true;
- this.type = type;
- }
-
- public boolean isHistogram()
- {
- return isHistogram;
- }
-
- public void setHistogram(boolean isHistogram)
- {
- this.isHistogram = isHistogram;
- }
-
- public FeatureTrack[] convertMap2Features(Map[] mapfeatures)
- {
- List features = new ArrayList();
-
- boolean first = true;
- boolean secstruc = false;
- boolean isGroup = false;
-
- FeatureTrack feat = null;
- Segment segment = null;
-
- int featuresCounter = 0;
- String prevGroup = null;
-
- for (int i = 0; i < mapfeatures.length; i++)
- {
-
- Map currentFeatureMap = mapfeatures[i];
- String type = (String) currentFeatureMap.get("TYPE");
-
- String group = (String) currentFeatureMap.get("GROUP");
- if (group != null)
- {
- if (prevGroup != null)
- {
- if (group.equals(prevGroup))
- {
- feat.setName(group);
- isGroup = true;
- }
- else
- {
- isGroup = false;
- }
- }
- else
- {
- isGroup = false;
- }
- }
- else
- {
- isGroup = false;
- }
-
- // we are skipping literature references for the moment
- // TODO: add a display to spice for non-positional features
- //
- if (type.equals("reference") || type.equals("GOA"))
- {
- continue;
- }
-
- if (!first)
- {
- // if not first feature
-
- if ((!secstruc) && (!isGroup))
- {
-
- // if not secondary structure and not in a group ...
- features = testAddFeatures(features, feat);
-
- }
- else if (!(type.equals("HELIX") || type.equals("STRAND") || type
- .equals("TURN")))
- {
- // end of secondary structure
- secstruc = false;
- if (feat != null && (!isGroup))
- {
- features = testAddFeatures(features, feat);
- }
-
- }
- } // end of not first
-
- first = false;
- if ((!secstruc) && (!isGroup))
- {
- featuresCounter += 1;
- feat = getNewFeat(currentFeatureMap);
- }
-
- if (type.equals("STRAND"))
- {
- secstruc = true;
- currentFeatureMap.put("colorTxt", "yellow");
- feat.setName("SECSTRUC");
- feat.setType("SECSTRUC");
- }
-
- else if (type.equals("HELIX"))
- {
- secstruc = true;
- currentFeatureMap.put("colorTxt", "red");
- feat.setName("SECSTRUC");
- feat.setType("SECSTRUC");
- }
-
- else if (type.equals("TURN"))
- {
- secstruc = true;
- currentFeatureMap.put("colorTxt", "white");
-
- feat.setName("SECSTRUC");
- feat.setType("SECSTRUC");
- }
- else
- {
- secstruc = false;
- currentFeatureMap.put("colorTxt", txtColors[featuresCounter
- % txtColors.length]);
- if (!isGroup)
- {
- try
- {
- feat.setName(type);
-
- } catch (NullPointerException e)
- {
- // e.printStackTrace();
- feat.setName("null");
- }
- }
- }
-
- segment = getNewSegment(currentFeatureMap);
-
- feat.addSegment(segment);
- prevGroup = group;
- }
-
- if (feat != null)
- features = testAddFeatures(features, feat);
-
- return (FeatureTrack[]) features.toArray(new FeatureTrack[features
- .size()]);
- }
-
- /**
- * test if this features is added as a new feature to the features list, or if
- * it is joint with an already existing one...
- *
- * @param features
- * @param newFeature
- * @return a List of FeatureTrack objects
- */
- protected List testAddFeatures(List features, FeatureTrack newFeature)
- {
-
- // System.out.println("testing " + newFeature + " " +
- // newFeature.getScore());
- Iterator iter = features.iterator();
-
- if (isHistogramFeatureType(newFeature))
- {
-
- // return histogram type features
- type = TYPE_HISTOGRAM;
-
- Segment seg = getHistogramSegmentFromFeature(newFeature);
-
- while (iter.hasNext())
- {
- FeatureTrack knownFeature = (FeatureTrack) iter.next();
- String knownType = knownFeature.getType();
-
- // System.out.println("found histogram style " + feat);
- // set type of this DAS source to being HISTOGRAM style
-
- if (knownType.equals(newFeature.getType()))
- {
- // convert the feature into a HistogramSegment and add to the already
- // known feature
-
- knownFeature.addSegment(seg);
- // we can return now
- return features;
- }
-
- }
- // we could not link this to any existing feature
- // convert it to a new HistogramFeature
- HistogramFeature hfeat = new HistogramFeature();
-
- hfeat.setLink(newFeature.getLink());
- hfeat.setMethod(newFeature.getMethod());
- hfeat.setName(newFeature.getName());
- hfeat.setNote(newFeature.getNote());
- hfeat.setScore("0");
- hfeat.setSource(newFeature.getSource());
- hfeat.addSegment(seg);
- hfeat.setType(newFeature.getType());
-
- newFeature = hfeat;
- features.add(newFeature);
- return features;
- }
-
- while (iter.hasNext())
- {
- FeatureTrack knownFeature = (FeatureTrack) iter.next();
- // this only compares method source and type ...
- boolean sameFeat = false;
- if (knownFeature.equals(newFeature))
- sameFeat = true;
-
- if ((knownFeature.getSource().equals(newFeature.getSource()))
- && (knownFeature.getMethod().equals(newFeature.getMethod()))
- && (knownFeature.getNote().equals(newFeature.getNote()))
- && isSecondaryStructureFeat(knownFeature)
- && isSecondaryStructureFeat(newFeature))
- sameFeat = true;
-
- if (sameFeat)
- {
-
- // seems to be of same type, method and source, so check if the segments
- // can be joined
-
- List tmpsegs = knownFeature.getSegments();
- Iterator segiter = tmpsegs.iterator();
- List newsegs = newFeature.getSegments();
- Iterator newsegsiter = newsegs.iterator();
- boolean overlap = false;
- while (newsegsiter.hasNext())
- {
- Segment newseg = (Segment) newsegsiter.next();
-
- while (segiter.hasNext())
- {
- Segment tmpseg = (Segment) segiter.next();
-
- if (tmpseg.overlaps(newseg))
- overlap = true;
- }
- }
-
- if (!overlap)
- {
- // add all new segments to old features...
- newsegsiter = newsegs.iterator();
- while (newsegsiter.hasNext())
- {
- Segment newseg = (Segment) newsegsiter.next();
- knownFeature.addSegment(newseg);
- }
-
- return features;
- }
- }
-
- }
-
- // if we get here, the features could not be joint with any other one, so
- // there is always some overlap
- // add to the list of known features
- features.add(newFeature);
- return features;
- }
-
- private FeatureTrack getNewFeat(Map currentFeatureMap)
- {
- FeatureTrack feat = new FeatureTrackImpl();
- // logger.finest(currentFeatureMap);
- // System.out.println("DrawableDasSource " + currentFeatureMap);
- feat.setSource((String) currentFeatureMap.get("dassource"));
- feat.setName((String) currentFeatureMap.get("NAME"));
- feat.setType((String) currentFeatureMap.get("TYPE"));
- feat.setLink((String) currentFeatureMap.get("LINK"));
- feat.setNote((String) currentFeatureMap.get("NOTE"));
-
- String typeID = (String) currentFeatureMap.get("TYPE_ID");
- String typeCategory = (String) currentFeatureMap.get("TYPE_CATEGORY");
- feat.setTypeID(typeID);
- feat.setTypeCategory(typeCategory);
-
- String method = (String) currentFeatureMap.get("METHOD");
- if (method == null)
- {
- method = "";
- }
- feat.setMethod(method);
- feat.setScore((String) currentFeatureMap.get("SCORE"));
- return feat;
- }
-
- private Segment getNewSegment(Map featureMap)
- {
- Segment s = new SegmentImpl();
- String sstart = (String) featureMap.get("START");
- String send = (String) featureMap.get("END");
- int start = Integer.parseInt(sstart);
- int end = Integer.parseInt(send);
- s.setStart(start);
- s.setEnd(end);
- s.setName((String) featureMap.get("TYPE"));
- s.setTxtColor((String) featureMap.get("colorTxt"));
- s.setColor((Color) featureMap.get("color"));
- s.setNote((String) featureMap.get("NOTE"));
- return s;
-
- }
-
- private boolean isSecondaryStructureFeat(FeatureTrack feat)
- {
- String type = feat.getType();
- if (type.equals("HELIX") || type.equals("STRAND")
- || type.equals("TURN"))
- return true;
- return false;
- }
-
- private boolean isHistogramFeatureType(FeatureTrack feat)
- {
- String ftype = feat.getType();
-
- Map[] style = stylesheet;
-
- // System.out.println("is HistogramFeature type " + ftype + " " + style );
-
- // todo : move this info into a config file...
-
- if (ftype.equals("hydrophobicity"))
- {
- return true;
- }
- if (getType().equals(TYPE_HISTOGRAM))
- return true;
-
- if (style != null)
- {
-
- for (int i = 0; i < style.length; i++)
- {
- Map m = style[i];
-
- // make sure the stylesheet is for this feature type
- String styleType = (String) m.get("type");
- if (styleType != null)
- {
- if (!styleType.equals(ftype))
- {
- continue;
- }
- }
- else
- {
- continue;
- }
-
- String type = (String) m.get("style");
- if (type != null)
- {
- // System.out.println("stylesheet type " + type);
- if (type.equals("gradient") || (type.equals("lineplot"))
- || (type.equals("histogram")))
- {
-
- return true;
- }
- }
- }
- }
-
- return false;
- }
-
- private HistogramSegment getHistogramSegmentFromFeature(FeatureTrack feat)
- {
- HistogramSegment s = new HistogramSegment();
-
- double score = 0.0;
-
- try
- {
- score = Double.parseDouble(feat.getScore());
-
- } catch (Exception e)
- {
- // e.printStackTrace();
- }
- s.setScore(score);
- List segments = feat.getSegments();
- if (segments.size() > 0)
- {
- Segment seg = (Segment) segments.get(0);
- s.setName(seg.getName());
- s.setStart(seg.getStart());
- s.setEnd(seg.getEnd());
- s.setNote(seg.getNote());
- s.setColor(seg.getColor());
- s.setTxtColor(seg.getTxtColor());
- }
-
- return s;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 22.09.2004
- * @author Andreas Prlic
- *
- */
-
-package org.biojava.dasobert.feature;
-
-import java.util.Iterator;
-
-/**
- * a class to store FeatureData and to visualize them coordinate system of
- * features is always UniProt ! PDBresnum features served by DAS need to be
- * converted into UniProt coord sys first.
- *
- * a feature consists of one or several segments. segmetns cotnains <start> and
- * <end> information.
- *
- * @author Andreas Prlic
- */
-public class FeatureTrackImpl extends AbstractFeatureTrack implements
- FeatureTrack
-
-{
-
- public Object clone()
- {
-
- FeatureTrack f = new FeatureTrackImpl();
- f.setName(name);
- f.setMethod(method);
- f.setType(type);
- f.setNote(note);
- f.setLink(link);
- f.setSource(source);
- f.setScore(score);
-
- Iterator iter = segments.iterator();
-
- while (iter.hasNext())
- {
- Segment s = (Segment) iter.next();
- f.addSegment((Segment) s.clone());
- }
-
- return f;
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on May 22, 2007
- *
- */
-
-package org.biojava.dasobert.feature;
-
-import java.util.Iterator;
-
-/**
- * a class that represents Histogram Style features in addition to normal
- * features they know about Max and Minimum scores for the whole line Histogram
- * feautes have only one (Histogram) Segment, which contains the scores for each
- * position
- *
- * @author Andreas Prlic
- *
- */
-public class HistogramFeature extends AbstractFeatureTrack
-{
-
- double max;
-
- double min;
-
- public HistogramFeature()
- {
- super();
- // TODO Auto-generated constructor stub
- }
-
- public double getMax()
- {
- return max;
- }
-
- public void setMax(double max)
- {
- this.max = max;
- }
-
- public double getMin()
- {
- return min;
- }
-
- public void setMin(double min)
- {
- this.min = min;
- }
-
- public Object clone()
- {
-
- HistogramFeature f = new HistogramFeature();
-
- f.setName(name);
- f.setMethod(method);
- f.setType(type);
- f.setNote(note);
- f.setLink(link);
- f.setSource(source);
- f.setScore(score);
-
- Iterator iter = segments.iterator();
-
- while (iter.hasNext())
- {
- Segment s = (Segment) iter.next();
- f.addSegment((Segment) s.clone());
- }
-
- return f;
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on May 22, 2007
- *
- */
-
-package org.biojava.dasobert.feature;
-
-/**
- * a Histogram segment is an extension of the standard Segment with a score
- *
- * @author Andreas Prlic
- *
- */
-public class HistogramSegment extends AbstractSegment
-{
-
- double score;
-
- public HistogramSegment()
- {
- super();
-
- }
-
- public double getScore()
- {
- return score;
- }
-
- public void setScore(double score)
- {
- this.score = score;
- }
-
- public Object clone()
- {
-
- Segment s = new HistogramSegment();
- s.setStart(start);
- s.setEnd(end);
- s.setName(name);
- s.setColor(color);
- s.setTxtColor(txtColor);
- s.setNote(note);
- return s;
-
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on 22.09.2004
- * @author Andreas Prlic
- *
- */
-
-package org.biojava.dasobert.feature;
-
-import java.awt.Color;
-
-/** a class to keep track of location information for a feature */
-public interface Segment
-{
-
- public Object clone();
-
- public String toString();
-
- public String getNote();
-
- public void setNote(String note);
-
- public void setStart(int strt);
-
- public int getStart();
-
- public void setEnd(int ed);
-
- public int getEnd();
-
- public void setName(String nam);
-
- public String getName();
-
- public void setColor(Color col);
-
- public Color getColor();
-
- public void setParent(FeatureTrack f);
-
- public FeatureTrack getParent();
-
- public void setTxtColor(String str);
-
- public String getTxtColor();
-
- /**
- * returns true if the specified sequence position is within the range of this
- * Segment
- *
- * @param seqPosition
- * the position to check
- * @return true if seqPos >= start && seqPos <= end
- */
- public boolean overlaps(int seqPosition);
-
- /**
- * tests if two segments are overlapping
- *
- * @param segment
- * to compare with
- * @return true if segments overlap
- */
- public boolean overlaps(Segment segment);
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on May 22, 2007
- *
- */
-
-package org.biojava.dasobert.feature;
-
-import java.util.Comparator;
-
-public class SegmentComparator implements Comparator
-{
-
- public int compare(Object arg0, Object arg1)
- {
-
- Segment s1 = (Segment) arg0;
- Segment s2 = (Segment) arg1;
-
- if (s1.getStart() < s2.getStart())
- return -1;
- if (s1.getStart() > s2.getStart())
- return 1;
-
- return 0;
- }
-
-}
+++ /dev/null
-/*
- * BioJava development code
- *
- * This code may be freely distributed and modified under the
- * terms of the GNU Lesser General Public Licence. This should
- * be distributed with the code. If you do not have a copy,
- * see:
- *
- * http://www.gnu.org/copyleft/lesser.html
- *
- * Copyright for this code is held jointly by the individual
- * authors. These should be listed in @author doc comments.
- *
- * For more information on the BioJava project and its aims,
- * or to join the biojava-l mailing list, visit the home page
- * at:
- *
- * http://www.biojava.org/
- *
- * Created on May 22, 2007
- *
- */
-
-package org.biojava.dasobert.feature;
-
-import java.awt.Color;
-
-public class SegmentImpl extends AbstractSegment
-{
-
- public SegmentImpl()
- {
- super();
- start = 0;
- end = 0;
- name = "Unknown";
- color = Color.white;
- txtColor = "white";
- parent = null;
- note = "";
- }
-
- public boolean equals(Segment s)
- {
- if (s == null)
- return false;
-
- if ((start == s.getStart()) && (end == s.getEnd())
- && (name.equals(s.getName())))
- {
- if (note == null)
- {
- if (s.getNote() == null)
- return true;
- }
- else
- {
- if (s.getNote() != null)
- {
- if (s.getNote().equals(note))
- return true;
- }
- }
-
- }
-
- return false;
- }
-
- public Object clone()
- {
-
- Segment s = new SegmentImpl();
- s.setStart(start);
- s.setEnd(end);
- s.setName(name);
- s.setColor(color);
- s.setTxtColor(txtColor);
- s.setNote(note);
- return s;
-
- }
-}