From: Jim Procter Date: Tue, 26 Jun 2018 15:16:15 +0000 (+0100) Subject: JAL-3035 - jalview-das is no more ! X-Git-Tag: Release_2_11_0~28^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b483c2012e40cab4b38f650dc049c94efe7e27c2;p=jalview.git JAL-3035 - jalview-das is no more ! - jsdas lib removed - DAS settings panel deleted (Feature settings pane has no tabs now) - all code for wrapping DAS sources and retrieving sequences and features from them is gone - test methods/main methods have been de-dasified or removed if their only purpose was to test DAS source discovery - fancy sorting code to account for DAS sequence source names has been removed --- diff --git a/.classpath b/.classpath index 0cdc4b9..d32799b 100644 --- a/.classpath +++ b/.classpath @@ -36,7 +36,6 @@ - diff --git a/lib/jdas-1.0.4.jar b/lib/jdas-1.0.4.jar deleted file mode 100644 index fb5d128..0000000 Binary files a/lib/jdas-1.0.4.jar and /dev/null differ diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index dcd6546..83bc810 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -28,8 +28,6 @@ import jalview.schemes.UserColourScheme; import jalview.structure.StructureImportSettings; import jalview.urls.IdOrgSettings; import jalview.util.ColorUtils; -import jalview.ws.dbsources.das.api.DasSourceRegistryI; -import jalview.ws.dbsources.das.datamodel.DasSourceRegistry; import jalview.ws.sifts.SiftsSettings; import java.awt.Color; @@ -982,22 +980,6 @@ public class Cache 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; - } - /** * Set the specified value, or remove it if null or empty. Does not save the * properties file. diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 30620a1..ea2f1d6 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -149,7 +149,6 @@ public class Jalview af.setProgressBar(MessageManager .getString("status.das_features_being_retrived"), id); af.featureSettings_actionPerformed(null); - af.featureSettings.fetchDasFeatures(dasSources, true); af.setProgressBar(null, id); synchronized (us) { diff --git a/src/jalview/gui/DasSourceBrowser.java b/src/jalview/gui/DasSourceBrowser.java deleted file mode 100644 index 8570ac3..0000000 --- a/src/jalview/gui/DasSourceBrowser.java +++ /dev/null @@ -1,864 +0,0 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ -package jalview.gui; - -import jalview.jbgui.GDasSourceBrowser; -import jalview.util.MessageManager; -import jalview.util.TableSorter; -import jalview.ws.dbsources.das.api.DasSourceRegistryI; -import jalview.ws.dbsources.das.api.jalviewSourceI; - -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.StringTokenizer; -import java.util.Vector; - -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.table.AbstractTableModel; - -import org.biodas.jdas.schema.sources.CAPABILITY; -import org.biodas.jdas.schema.sources.COORDINATES; -import org.biodas.jdas.schema.sources.PROP; -import org.biodas.jdas.schema.sources.VERSION; - -public class DasSourceBrowser extends GDasSourceBrowser - implements Runnable, ListSelectionListener -{ - DasSourceRegistryI sourceRegistry = null; - - Vector selectedSources; - - public DasSourceBrowser(FeatureSettings featureSettings) - { - fs = featureSettings; - // TODO DasSourceRegistryProvider API - sourceRegistry = jalview.bin.Cache.getDasSourceRegistry(); - String registry = sourceRegistry.getDasRegistryURL(); - - registryURL.setText(registry); - - setSelectedFromProperties(); - - displayFullDetails(null); - table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - - filter1.addListSelectionListener(this); - filter2.addListSelectionListener(this); - filter3.addListSelectionListener(this); - - // Ask to be notified of selection changes. - ListSelectionModel rowSM = table.getSelectionModel(); - rowSM.addListSelectionListener(new ListSelectionListener() - { - @Override - public void valueChanged(ListSelectionEvent e) - { - ListSelectionModel lsm = (ListSelectionModel) e.getSource(); - if (!lsm.isSelectionEmpty()) - { - int selectedRow = lsm.getMinSelectionIndex(); - displayFullDetails(table.getValueAt(selectedRow, 0).toString()); - } - } - }); - - table.addMouseListener(new MouseAdapter() - { - @Override - public void mouseClicked(MouseEvent evt) - { - if (evt.getClickCount() == 2 || evt.isPopupTrigger()) - { - editRemoveLocalSource(evt); - } - } - }); - - if (sourceRegistry.getSources() != null) - { - init(); - } - } - - FeatureSettings fs = null; - - private boolean loadingDasSources; - - public DasSourceBrowser() - { - this(null); - } - - @Override - public void paintComponent(java.awt.Graphics g) - { - if (sourceRegistry == null) - { - Thread worker = new Thread(this); - worker.start(); - } - } - - void init() - { - List sources = sourceRegistry.getSources(); - int dSize = sources.size(); - Object[][] data = new Object[dSize][2]; - for (int i = 0; i < dSize; i++) - { - data[i][0] = sources.get(i).getTitle(); // what's equivalent of nickname - data[i][1] = new Boolean( - selectedSources.contains(sources.get(i).getTitle())); - } - - refreshTableData(data); - setCapabilities(sourceRegistry); - - javax.swing.SwingUtilities.invokeLater(new Runnable() - { - @Override - public void run() - { - TableSorter sorter = (TableSorter) table.getModel(); - sorter.setSortingStatus(1, TableSorter.DESCENDING); - sorter.setSortingStatus(1, TableSorter.NOT_SORTED); - } - }); - - progressBar.setIndeterminate(false); - progressBar.setVisible(false); - addLocal.setVisible(true); - refresh.setVisible(true); - } - - public void refreshTableData(Object[][] data) - { - TableSorter sorter = new TableSorter(new DASTableModel(data)); - sorter.setTableHeader(table.getTableHeader()); - table.setModel(sorter); - } - - void displayFullDetails(String nickName) - { - - StringBuffer text = new StringBuffer( - ""); - - if (nickName == null) - { - fullDetails.setText(text + MessageManager - .getString("label.select_das_service_from_table")); - return; - } - - int dSize = sourceRegistry.getSources().size(); - for (jalviewSourceI ds : sourceRegistry.getSources()) - { - if (!ds.getTitle().equals(nickName)) - { - continue; - } - - VERSION latest = ds.getVersion(); - text.append( - "Id: " + ds.getUri() + "
"); - text.append("Nickname: " - + ds.getTitle() + "
"); - - text.append("URL: " + ds.getSourceURL() + "" - + "
"); - if (!ds.isLocal()) - { - if (ds.getDocHref() != null && ds.getDocHref().length() > 0) - { - text.append("Site: " + ds.getDocHref() + "" - + "
"); - } - - text.append("Description: " - + ds.getDescription() + "
"); - - text.append( - "Admin Email: " + ds.getEmail() + "" - + "
"); - - text.append("Registered at: " - + latest.getCreated() + "
"); - - // TODO: Identify last successful test date - // text.append("Last successful test: " - // + latest.dasSources[i].getLeaseDate() + "
"); - } - else - { - text.append("Source was added manually.
"); - } - text.append("Labels: "); - boolean b = false; - for (PROP labl : latest.getPROP()) - { - if (labl.getName().equalsIgnoreCase("LABEL")) - { - if (b) - { - text.append(","); - } - text.append(" "); - - text.append(labl.getValue()); - b = true; - } - ; - } - text.append("
"); - - text.append("Capabilities: "); - CAPABILITY[] scap = latest.getCAPABILITY().toArray(new CAPABILITY[0]); - for (int j = 0; j < scap.length; j++) - { - text.append(scap[j].getType()); - if (j < scap.length - 1) - { - text.append(", "); - } - } - text.append("
"); - - text.append("Coordinates:"); - int i = 1; - for (COORDINATES dcs : latest.getCOORDINATES()) - { - text.append("
" + i++ + ". "); - text.append(dcs.getAuthority() + " : " + dcs.getSource()); - if (dcs.getTaxid() != null && dcs.getTaxid().trim().length() > 0) - { - text.append(" [TaxId:" + dcs.getTaxid() + "]"); - } - if (dcs.getVersion() != null - && dcs.getVersion().trim().length() > 0) - { - { - text.append(" {v. " + dcs.getVersion() + "}"); - } - } - text.append(" (" + dcs.getUri() - + ")"); - } - text.append("
"); - - break; - } - - fullDetails.setText(text.toString()); - javax.swing.SwingUtilities.invokeLater(new Runnable() - { - @Override - public void run() - { - fullDetailsScrollpane.getVerticalScrollBar().setValue(0); - } - }); - } - - @Override - public void run() - { - loadingDasSources = true; - - addLocal.setVisible(false); - refresh.setVisible(false); - progressBar.setVisible(true); - progressBar.setIndeterminate(true); - setParentGuiEnabled(false); - // Refresh the source list. - sourceRegistry.refreshSources(); - - init(); - - setParentGuiEnabled(true); - loadingDasSources = false; - - } - - private void setParentGuiEnabled(boolean b) - { - if (fs != null) - { - fs.fetchDAS.setEnabled(b); - fs.saveDAS.setEnabled(b); - } - } - - public Vector getSelectedSources() - { - // wait around if we're still loading. - while (sourceRegistry == null) - { - if (!loadingDasSources) - { - new Thread(this).start(); - try - { - Thread.sleep(5); - } catch (Exception e) - { - } - ; - while (loadingDasSources) - { - try - { - Thread.sleep(5); - } catch (Exception e) - { - } - ; - } - ; - } - } - - Vector selected = new Vector(); - for (String source : selectedSources) - { - jalviewSourceI srce = sourceRegistry.getSource(source); - if (srce != null) - { - selected.addElement(srce); - } - } - return selected; - } - - @Override - public void refresh_actionPerformed(ActionEvent e) - { - saveProperties(jalview.bin.Cache.applicationProperties); - - Thread worker = new Thread(this); - worker.start(); - } - - private void setCapabilities(DasSourceRegistryI sourceRegistry2) - { - Vector authority = new Vector(); - Vector type = new Vector(); - Vector label = new Vector(); - Vector taxIds = new Vector(); - authority.add("Any"); - type.add("Any"); - label.add("Any"); - - for (jalviewSourceI ds : sourceRegistry2.getSources()) - { - VERSION latest = ds.getVersion(); - - for (COORDINATES cs : latest.getCOORDINATES()) - { - if (!type.contains(cs.getSource())) - { - type.add(cs.getSource()); // source==category - } - - if (!authority.contains(cs.getAuthority())) - { - authority.add(cs.getAuthority()); - } - } - - for (PROP slabel : latest.getPROP()) - { - if (slabel.getName().equalsIgnoreCase("LABEL") - && !label.contains(slabel.getValue())) - { - label.add(slabel.getValue()); - } - } - - } - - filter1.setListData(authority); - filter2.setListData(type); - filter3.setListData(label); - // filter4 taxIds - - javax.swing.SwingUtilities.invokeLater(new Runnable() - { - @Override - public void run() - { - filter1.setSelectedIndex(0); - filter2.setSelectedIndex(0); - filter3.setSelectedIndex(0); - } - }); - } - - @Override - public void amendLocal(boolean newSource) - { - String url = "http://localhost:8080/", nickname = ""; - boolean seqsrc = false; - if (!newSource) - { - int selectedRow = table.getSelectionModel().getMinSelectionIndex(); - nickname = table.getValueAt(selectedRow, 0).toString(); - jalviewSourceI source = sourceRegistry.getSource(nickname); - url = source.getUri(); - seqsrc = source.isSequenceSource(); - } - - JTextField nametf = new JTextField(nickname, 40); - JTextField urltf = new JTextField(url, 40); - JCheckBox seqs = new JCheckBox( - MessageManager.getString("label.sequence_source")); - seqs.setSelected(seqsrc); - JPanel panel = new JPanel(new BorderLayout()); - JPanel pane12 = new JPanel(new BorderLayout()); - pane12.add(new JLabel(MessageManager.getString("label.name:")), - BorderLayout.CENTER); - pane12.add(nametf, BorderLayout.EAST); - panel.add(pane12, BorderLayout.NORTH); - pane12 = new JPanel(new BorderLayout()); - pane12.add(new JLabel(MessageManager.getString("label.url:")), - BorderLayout.NORTH); - pane12.add(seqs, BorderLayout.SOUTH); - pane12.add(urltf, BorderLayout.EAST); - panel.add(pane12, BorderLayout.SOUTH); - - int reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop, - panel, MessageManager.getString("label.enter_local_das_source"), - JvOptionPane.OK_CANCEL_OPTION); - - if (reply != JvOptionPane.OK_OPTION) - { - return; - } - - if (!urltf.getText().endsWith("/")) - { - urltf.setText(urltf.getText() + "/"); - } - - jalviewSourceI local = sourceRegistry.createLocalSource(urltf.getText(), - nametf.getText(), seqs.isSelected(), true); - List sources = sourceRegistry.getSources(); - int osize = sources.size(); - int size = osize + (newSource ? 1 : 0); - - Object[][] data = new Object[size][2]; - DASTableModel dtm = (table != null) - ? (DASTableModel) ((TableSorter) table.getModel()) - .getTableModel() - : null; - for (int i = 0; i < osize; i++) - { - String osrc = (dtm == null || i >= osize) ? null - : (String) dtm.getValueAt(i, 0); - if (!newSource && osrc != null - && dtm.getValueAt(i, 0).equals(nickname)) - { - data[i][0] = local.getTitle(); - data[i][1] = new Boolean(true); - } - else - { - data[i][0] = osrc; - data[i][1] = new Boolean(selectedSources.contains(osrc)); - } - } - // Always add a new source at the end - if (newSource) - { - data[osize][0] = local.getTitle(); - data[osize][1] = new Boolean(true); - selectedSources.add(local.getTitle()); - } - - refreshTableData(data); - - SwingUtilities.invokeLater(new Runnable() - { - @Override - public void run() - { - scrollPane.getVerticalScrollBar() - .setValue(scrollPane.getVerticalScrollBar().getMaximum()); - } - }); - - displayFullDetails(local.getTitle()); - } - - public void editRemoveLocalSource(MouseEvent evt) - { - int selectedRow = table.getSelectionModel().getMinSelectionIndex(); - if (selectedRow == -1) - { - return; - } - - String nickname = table.getValueAt(selectedRow, 0).toString(); - - if (!sourceRegistry.getSource(nickname).isLocal()) - { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString( - "label.you_can_only_edit_or_remove_local_das_sources"), - MessageManager.getString("label.public_das_source"), - JvOptionPane.WARNING_MESSAGE); - return; - } - - Object[] options = { "Edit", "Remove", "Cancel" }; - int choice = JvOptionPane.showInternalOptionDialog(Desktop.desktop, - "Do you want to edit or remove " + nickname + "?", - "Edit / Remove Local DAS Source", - JvOptionPane.YES_NO_CANCEL_OPTION, - JvOptionPane.QUESTION_MESSAGE, null, options, options[2]); - - switch (choice) - { - case 0: - amendLocal(false); - break; - case 1: - sourceRegistry.removeLocalSource(sourceRegistry.getSource(nickname)); - selectedSources.remove(nickname); - Object[][] data = new Object[sourceRegistry.getSources().size()][2]; - int index = 0, l = table.getRowCount(); - - for (int i = 0; i < l; i++) - { - String nm; - if ((nm = (String) table.getValueAt(i, 0)).equals(nickname)) - { - continue; - } - else - { - data[index][0] = nm; - data[index][1] = new Boolean(selectedSources.contains(nm)); - index++; - } - } - refreshTableData(data); - SwingUtilities.invokeLater(new Runnable() - { - @Override - public void run() - { - scrollPane.getVerticalScrollBar() - .setValue(scrollPane.getVerticalScrollBar().getMaximum()); - } - }); - - break; - } - } - - @Override - public void valueChanged(ListSelectionEvent evt) - { - // Called when the MainTable selection changes - if (evt.getValueIsAdjusting()) - { - return; - } - - displayFullDetails(null); - - // Filter the displayed data sources - - ArrayList names = new ArrayList(); - ArrayList selected = new ArrayList(); - - // The features filter is not visible, but we must still - // filter the das source list here. - // July 2006 - only 6 sources fo not serve features - Object[] dummyFeatureList = new Object[] { "features" }; - List srcs = sourceRegistry.getSources(); - for (jalviewSourceI ds : srcs) - { - - VERSION v = ds.getVersion(); - List coords = v.getCOORDINATES(); - if (ds.isLocal() || ((coords == null || coords.size() == 0) - && filter1.getSelectedIndex() == 0 - && filter2.getSelectedIndex() == 0 - && filter3.getSelectedIndex() == 0)) - { - // THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT - // HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT - // IS ADDED FROM THE REGISTRY - names.add(ds.getTitle()); - selected.add(new Boolean(selectedSources.contains(ds.getTitle()))); - continue; - } - - if (!selectedInList(dummyFeatureList, ds.getCapabilityList(v)) - || !selectedInList(filter3.getSelectedValues(), - ds.getLabelsFor(v))) - { - continue; - } - - for (int j = 0; j < coords.size(); j++) - { - if (selectedInList(filter1.getSelectedValues(), - new String[] - { coords.get(j).getAuthority() }) - && selectedInList(filter2.getSelectedValues(), new String[] - { coords.get(j).getSource() })) - { - names.add(ds.getTitle()); - selected.add( - new Boolean(selectedSources.contains(ds.getTitle()))); - break; - } - } - } - - int dSize = names.size(); - Object[][] data = new Object[dSize][2]; - for (int d = 0; d < dSize; d++) - { - data[d][0] = names.get(d); - data[d][1] = selected.get(d); - } - - refreshTableData(data); - } - - private boolean selectedInList(Object[] selection, String[] items) - { - for (int i = 0; i < selection.length; i++) - { - if (selection[i].equals("Any")) - { - return true; - } - if (items == null || items.length == 0) - { - return false; - } - String sel = (items[0].startsWith("das1:") ? "das1:" : "") - + selection[i]; - for (int j = 0; j < items.length; j++) - { - if (sel.equals(items[j])) - { - return true; - } - } - } - - return false; - } - - void setSelectedFromProperties() - { - String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", - "uniprot"); - StringTokenizer st = new StringTokenizer(active, "\t"); - selectedSources = new Vector(); - while (st.hasMoreTokens()) - { - selectedSources.addElement(st.nextToken()); - } - } - - @Override - public void reset_actionPerformed(ActionEvent e) - { - registryURL.setText(sourceRegistry.getDasRegistryURL()); - } - - /** - * set the DAS source settings in the given jalview properties. - * - * @param properties - */ - public void saveProperties(Properties properties) - { - if (registryURL.getText() == null || registryURL.getText().length() < 1) - { - properties.remove(jalview.bin.Cache.DAS_REGISTRY_URL); - } - else - { - properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, - registryURL.getText()); - } - - StringBuffer sb = new StringBuffer(); - for (int r = 0; r < table.getModel().getRowCount(); r++) - { - if (((Boolean) table.getValueAt(r, 1)).booleanValue()) - { - sb.append(table.getValueAt(r, 0) + "\t"); - } - } - - properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE, - sb.toString()); - - String sourceprop = sourceRegistry.getLocalSourceString(); - properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sourceprop); - } - - class DASTableModel extends AbstractTableModel - { - - public DASTableModel(Object[][] data) - { - this.data = data; - } - - private String[] columnNames = new String[] { - MessageManager.getString("label.nickname"), - MessageManager.getString("label.use_source") }; - - private Object[][] data; - - @Override - public int getColumnCount() - { - return columnNames.length; - } - - @Override - public int getRowCount() - { - return data.length; - } - - @Override - public String getColumnName(int col) - { - return columnNames[col]; - } - - @Override - public Object getValueAt(int row, int col) - { - return data[row][col]; - } - - /* - * JTable uses this method to determine the default renderer/ editor for - * each cell. If we didn't implement this method, then the last column would - * contain text ("true"/"false"), rather than a check box. - */ - @Override - public Class getColumnClass(int c) - { - return getValueAt(0, c).getClass(); - } - - /* - * Don't need to implement this method unless your table's editable. - */ - @Override - public boolean isCellEditable(int row, int col) - { - // Note that the data/cell address is constant, - // no matter where the cell appears onscreen. - return col == 1; - - } - - /* - * Don't need to implement this method unless your table's data can change. - */ - @Override - public void setValueAt(Object value, int row, int col) - { - data[row][col] = value; - fireTableCellUpdated(row, col); - - String name = getValueAt(row, 0).toString(); - boolean selected = ((Boolean) value).booleanValue(); - - if (selectedSources.contains(name) && !selected) - { - selectedSources.remove(name); - } - - if (!selectedSources.contains(name) && selected) - { - selectedSources.add(name); - } - } - } - - public void initDasSources() - { - - Thread thr = new Thread(new Runnable() - { - @Override - public void run() - { - // this actually initialises the das source list - paintComponent(null); // yuk - } - }); - thr.start(); - while (loadingDasSources || sourceRegistry == null) - { - try - { - Thread.sleep(10); - } catch (Exception e) - { - } - ; - } - } - - /** - * disable or enable the buttons on the source browser - * - * @param b - */ - public void setGuiEnabled(boolean b) - { - refresh.setEnabled(b); - addLocal.setEnabled(b); - } -} diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 821454f..78c1cac 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -36,10 +36,7 @@ import jalview.schemabinding.version2.MatcherSet; import jalview.schemes.FeatureColour; import jalview.util.MessageManager; import jalview.util.Platform; -import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean; -import jalview.ws.DasSequenceFeatureFetcher; -import jalview.ws.dbsources.das.api.jalviewSourceI; import java.awt.BorderLayout; import java.awt.Color; @@ -74,7 +71,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.Vector; import javax.help.HelpSetException; import javax.swing.AbstractCellEditor; @@ -96,7 +92,6 @@ import javax.swing.JSlider; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.table.AbstractTableModel; @@ -127,12 +122,6 @@ public class FeatureSettings extends JPanel private static final int MIN_HEIGHT = 400; - DasSourceBrowser dassourceBrowser; - - DasSequenceFeatureFetcher dasFeatureFetcher; - - JPanel dasSettingsPane = new JPanel(); - final FeatureRenderer fr; public final AlignFrame af; @@ -325,9 +314,6 @@ public class FeatureSettings extends JPanel // MessageManager.getString("label.feature_settings_click_drag"))); scrollPane.setViewportView(table); - dassourceBrowser = new DasSourceBrowser(this); - dasSettingsPane.add(dassourceBrowser, BorderLayout.CENTER); - if (af.getViewport().isShowSequenceFeatures() || !fr.hasRenderOrder()) { fr.findAllFeatures(true); // display everything! @@ -376,7 +362,6 @@ public class FeatureSettings extends JPanel javax.swing.event.InternalFrameEvent evt) { fr.removePropertyChangeListener(change); - dassourceBrowser.fs = null; }; }); frame.setLayer(JLayeredPane.PALETTE_LAYER); @@ -1158,8 +1143,6 @@ public class FeatureSettings extends JPanel JPanel settingsPane = new JPanel(); settingsPane.setLayout(new BorderLayout()); - dasSettingsPane.setLayout(new BorderLayout()); - JPanel bigPanel = new JPanel(); bigPanel.setLayout(new BorderLayout()); @@ -1314,38 +1297,6 @@ public class FeatureSettings extends JPanel transparency.setMaximum(70); transparency.setToolTipText( MessageManager.getString("label.transparency_tip")); - fetchDAS.setText(MessageManager.getString("label.fetch_das_features")); - fetchDAS.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - fetchDAS_actionPerformed(e); - } - }); - saveDAS.setText(MessageManager.getString("action.save_as_default")); - saveDAS.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - saveDAS_actionPerformed(e); - } - }); - - JPanel dasButtonPanel = new JPanel(); - dasButtonPanel.setBorder(BorderFactory.createEtchedBorder()); - dasSettingsPane.setBorder(null); - cancelDAS.setEnabled(false); - cancelDAS.setText(MessageManager.getString("action.cancel_fetch")); - cancelDAS.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - cancelDAS_actionPerformed(e); - } - }); JPanel transPanel = new JPanel(new GridLayout(1, 2)); bigPanel.add(transPanel, BorderLayout.SOUTH); @@ -1365,172 +1316,11 @@ public class FeatureSettings extends JPanel buttonPanel.add(loadColours); buttonPanel.add(saveColours); bigPanel.add(scrollPane, BorderLayout.CENTER); - dasSettingsPane.add(dasButtonPanel, BorderLayout.SOUTH); - dasButtonPanel.add(fetchDAS); - dasButtonPanel.add(cancelDAS); - dasButtonPanel.add(saveDAS); settingsPane.add(bigPanel, BorderLayout.CENTER); settingsPane.add(buttonPanel, BorderLayout.SOUTH); this.add(settingsPane); } - public void fetchDAS_actionPerformed(ActionEvent e) - { - fetchDAS.setEnabled(false); - cancelDAS.setEnabled(true); - dassourceBrowser.setGuiEnabled(false); - Vector selectedSources = dassourceBrowser - .getSelectedSources(); - doDasFeatureFetch(selectedSources, true, true); - } - - /** - * get the features from selectedSources for all or the current selection - * - * @param selectedSources - * @param checkDbRefs - * @param promptFetchDbRefs - */ - private void doDasFeatureFetch(List selectedSources, - boolean checkDbRefs, boolean promptFetchDbRefs) - { - SequenceI[] dataset, seqs; - int iSize; - AlignmentViewport vp = af.getViewport(); - if (vp.getSelectionGroup() != null - && vp.getSelectionGroup().getSize() > 0) - { - iSize = vp.getSelectionGroup().getSize(); - dataset = new SequenceI[iSize]; - seqs = vp.getSelectionGroup().getSequencesInOrder(vp.getAlignment()); - } - else - { - iSize = vp.getAlignment().getHeight(); - seqs = vp.getAlignment().getSequencesArray(); - } - - dataset = new SequenceI[iSize]; - for (int i = 0; i < iSize; i++) - { - dataset[i] = seqs[i].getDatasetSequence(); - } - - cancelDAS.setEnabled(true); - dasFeatureFetcher = new jalview.ws.DasSequenceFeatureFetcher(dataset, - this, selectedSources, checkDbRefs, promptFetchDbRefs); - af.getViewport().setShowSequenceFeatures(true); - af.showSeqFeatures.setSelected(true); - } - - /** - * blocking call to initialise the das source browser - */ - public void initDasSources() - { - dassourceBrowser.initDasSources(); - } - - /** - * examine the current list of das sources and return any matching the given - * nicknames in sources - * - * @param sources - * Vector of Strings to resolve to DAS source nicknames. - * @return sources that are present in source list. - */ - public List resolveSourceNicknames(Vector sources) - { - return dassourceBrowser.sourceRegistry.resolveSourceNicknames(sources); - } - - /** - * get currently selected das sources. ensure you have called initDasSources - * before calling this. - * - * @return vector of selected das source nicknames - */ - public Vector getSelectedSources() - { - return dassourceBrowser.getSelectedSources(); - } - - /** - * properly initialise DAS fetcher and then initiate a new thread to fetch - * features from the named sources (rather than any turned on by default) - * - * @param sources - * @param block - * if true then runs in same thread, otherwise passes to the Swing - * executor - */ - public void fetchDasFeatures(Vector sources, boolean block) - { - initDasSources(); - List resolved = dassourceBrowser.sourceRegistry - .resolveSourceNicknames(sources); - if (resolved.size() == 0) - { - resolved = dassourceBrowser.getSelectedSources(); - } - if (resolved.size() > 0) - { - final List dassources = resolved; - fetchDAS.setEnabled(false); - // cancelDAS.setEnabled(true); doDasFetch does this. - Runnable fetcher = new Runnable() - { - - @Override - public void run() - { - doDasFeatureFetch(dassources, true, false); - - } - }; - if (block) - { - fetcher.run(); - } - else - { - SwingUtilities.invokeLater(fetcher); - } - } - } - - public void saveDAS_actionPerformed(ActionEvent e) - { - dassourceBrowser - .saveProperties(jalview.bin.Cache.applicationProperties); - } - - public void complete() - { - fetchDAS.setEnabled(true); - cancelDAS.setEnabled(false); - dassourceBrowser.setGuiEnabled(true); - - } - - public void cancelDAS_actionPerformed(ActionEvent e) - { - if (dasFeatureFetcher != null) - { - dasFeatureFetcher.cancel(); - } - complete(); - } - - public void noDasSourceActive() - { - complete(); - JvOptionPane.showInternalConfirmDialog(Desktop.desktop, - MessageManager.getString("label.no_das_sources_selected_warn"), - MessageManager.getString("label.no_das_sources_selected_title"), - JvOptionPane.DEFAULT_OPTION, JvOptionPane.INFORMATION_MESSAGE); - } - // /////////////////////////////////////////////////////////////////////// // http://java.sun.com/docs/books/tutorial/uiswing/components/table.html // /////////////////////////////////////////////////////////////////////// diff --git a/src/jalview/gui/JDatabaseTree.java b/src/jalview/gui/JDatabaseTree.java index 1018d6e..8d62433 100644 --- a/src/jalview/gui/JDatabaseTree.java +++ b/src/jalview/gui/JDatabaseTree.java @@ -20,7 +20,6 @@ */ package jalview.gui; -import jalview.bin.Cache; import jalview.util.MessageManager; import jalview.ws.seqfetcher.DbSourceProxy; @@ -42,7 +41,6 @@ import java.util.List; import java.util.Vector; import javax.swing.JButton; -import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -518,54 +516,6 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener lstners.remove(actionListener); } - public static void main(String args[]) - { - Cache.getDasSourceRegistry(); - JDatabaseTree jdt = new JDatabaseTree(new jalview.ws.SequenceFetcher()); - JFrame foo = new JFrame(); - foo.setLayout(new BorderLayout()); - foo.add(jdt.getDatabaseSelectorButton(), BorderLayout.CENTER); - foo.pack(); - foo.setVisible(true); - int nultimes = 5; - final Thread us = Thread.currentThread(); - jdt.addActionListener(new ActionListener() - { - - @Override - public void actionPerformed(ActionEvent e) - { - us.interrupt(); - } - }); - do - { - try - { - Thread.sleep(50); - } catch (InterruptedException x) - { - nultimes--; - if (!jdt.hasSelection()) - { - System.out.println("No Selection"); - } - else - { - System.out.println("Selection: " + jdt.getSelectedItem()); - int s = 1; - for (DbSourceProxy pr : jdt.getSelectedSources()) - { - System.out.println("Source " + s++ + ": " + pr.getDbName() - + " (" + pr.getDbSource() + ") Version " - + pr.getDbVersion() + ". Test:\t" + pr.getTestQuery()); - } - System.out.println("Test queries: " + jdt.getExampleQueries()); - } - } - } while (nultimes > 0 && foo.isVisible()); - foo.setVisible(false); - } @Override public void keyPressed(KeyEvent arg0) diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 5aab26d..7d02fac 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -168,8 +168,6 @@ public class Preferences extends GPreferences JInternalFrame frame; - DasSourceBrowser dasSource; - private WsPreferences wsPrefs; private OptionsParam promptEachTimeOpt = new OptionsParam( @@ -190,8 +188,6 @@ public class Preferences extends GPreferences super(); frame = new JInternalFrame(); frame.setContentPane(this); - dasSource = new DasSourceBrowser(); - dasTab.add(dasSource, BorderLayout.CENTER); wsPrefs = new WsPreferences(); wsTab.add(wsPrefs, BorderLayout.CENTER); int width = 500, height = 450; @@ -797,7 +793,6 @@ public class Preferences extends GPreferences Cache.applicationProperties.setProperty("PAD_GAPS", Boolean.toString(padGaps.isSelected())); - dasSource.saveProperties(Cache.applicationProperties); wsPrefs.updateAndRefreshWsMenuConfig(false); Cache.saveProperties(); Desktop.instance.doConfigureStructurePrefs(); diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index f545e70..8754fbb 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -34,7 +34,6 @@ import jalview.io.gff.SequenceOntologyI; import jalview.util.DBRefUtils; import jalview.util.MessageManager; import jalview.util.Platform; -import jalview.ws.dbsources.das.api.DasSourceRegistryI; import jalview.ws.seqfetcher.DbSourceProxy; import java.awt.BorderLayout; @@ -111,10 +110,6 @@ public class SequenceFetcher extends JPanel implements Runnable private static jalview.ws.SequenceFetcher sfetch = null; - private static long lastDasSourceRegistry = -3; - - private static DasSourceRegistryI dasRegistry = null; - private static boolean _initingFetcher = false; private static Thread initingThread = null; @@ -165,11 +160,7 @@ public class SequenceFetcher extends JPanel implements Runnable Thread.currentThread().hashCode()); } } - if (sfetch == null || dasRegistry != Cache.getDasSourceRegistry() - || lastDasSourceRegistry != (Cache.getDasSourceRegistry() - .getDasRegistryURL() - + Cache.getDasSourceRegistry().getLocalSourceString()) - .hashCode()) + if (sfetch == null) { _initingFetcher = true; initingThread = Thread.currentThread(); @@ -183,16 +174,12 @@ public class SequenceFetcher extends JPanel implements Runnable "status.init_sequence_database_fetchers"), Thread.currentThread().hashCode()); } - dasRegistry = Cache.getDasSourceRegistry(); - dasRegistry.refreshSources(); jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher(); if (guiWindow != null) { guiWindow.setProgressBar(null, Thread.currentThread().hashCode()); } - lastDasSourceRegistry = (dasRegistry.getDasRegistryURL() - + dasRegistry.getLocalSourceString()).hashCode(); sfetch = sf; _initingFetcher = false; initingThread = null; @@ -564,15 +551,10 @@ public class SequenceFetcher extends JPanel implements Runnable dbeg.setText(MessageManager.formatMessage("label.example_query_param", new String[] { eq })); + // TODO this should be a property of the SequenceFetcher whether commas are and + // colons are allowed in the IDs... + boolean enablePunct = !(eq != null && eq.indexOf(",") > -1); - for (DbSourceProxy dbs : database.getSelectedSources()) - { - if (dbs instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource) - { - enablePunct = false; - break; - } - } replacePunctuation.setEnabled(enablePunct); } catch (Exception ex) diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 26e0919..6807382 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -264,10 +264,6 @@ public class GPreferences extends JPanel protected JCheckBox sortByTree = new JCheckBox(); - /* - * DAS Settings tab - */ - protected JPanel dasTab = new JPanel(); /* * Web Services tab @@ -326,12 +322,6 @@ public class GPreferences extends JPanel MessageManager.getString("label.editing")); /* - * See DasSourceBrowser for the real work of configuring this tab. - */ - dasTab.setLayout(new BorderLayout()); - tabbedPane.add(dasTab, MessageManager.getString("label.das_settings")); - - /* * See WsPreferences for the real work of configuring this tab. */ wsTab.setLayout(new BorderLayout()); diff --git a/src/jalview/ws/DBRefFetcher.java b/src/jalview/ws/DBRefFetcher.java index 1677eca..061e70c 100644 --- a/src/jalview/ws/DBRefFetcher.java +++ b/src/jalview/ws/DBRefFetcher.java @@ -28,15 +28,12 @@ import jalview.datamodel.DBRefSource; import jalview.datamodel.Mapping; import jalview.datamodel.SequenceI; import jalview.gui.CutAndPasteTransfer; -import jalview.gui.DasSourceBrowser; import jalview.gui.Desktop; import jalview.gui.FeatureSettings; import jalview.gui.IProgressIndicator; import jalview.gui.OOMWarning; import jalview.util.DBRefUtils; import jalview.util.MessageManager; -import jalview.ws.dbsources.das.api.jalviewSourceI; -import jalview.ws.dbsources.das.datamodel.DasSequenceSource; import jalview.ws.seqfetcher.DbSourceProxy; import java.util.ArrayList; @@ -119,7 +116,7 @@ public class DBRefFetcher implements Runnable DbSourceProxy[] sources, FeatureSettings featureSettings, boolean isNucleotide) { - listeners = new ArrayList(); + listeners = new ArrayList<>(); this.progressWindow = progressIndicatorFrame; alseqs = new SequenceI[seqs.length]; SequenceI[] ds = new SequenceI[seqs.length]; @@ -165,23 +162,7 @@ public class DBRefFetcher implements Runnable { // af.featureSettings_actionPerformed(null); String[] defdb = null; - List selsources = new ArrayList(); - Vector dasselsrc = (featureSettings != null) - ? featureSettings.getSelectedSources() - : new DasSourceBrowser().getSelectedSources(); - - for (jalviewSourceI src : dasselsrc) - { - List sp = src.getSequenceSourceProxies(); - if (sp != null) - { - selsources.addAll(sp); - if (sp.size() > 1) - { - Cache.log.debug("Added many Db Sources for :" + src.getTitle()); - } - } - } + List selsources = new ArrayList<>(); // select appropriate databases based on alignFrame context. if (forNucleotide) { @@ -191,7 +172,7 @@ public class DBRefFetcher implements Runnable { defdb = DBRefSource.PROTEINDBS; } - List srces = new ArrayList(); + List srces = new ArrayList<>(); for (String ddb : defdb) { List srcesfordb = sfetcher.getSourceProxy(ddb); @@ -235,30 +216,6 @@ public class DBRefFetcher implements Runnable } /** - * retrieve all the das sequence sources and add them to the list of db - * sources to retrieve from - */ - public void appendAllDasSources() - { - if (dbSources == null) - { - dbSources = new DbSourceProxy[0]; - } - // append additional sources - DbSourceProxy[] otherdb = sfetcher - .getDbSourceProxyInstances(DasSequenceSource.class); - if (otherdb != null && otherdb.length > 0) - { - DbSourceProxy[] newsrc = new DbSourceProxy[dbSources.length - + otherdb.length]; - System.arraycopy(dbSources, 0, newsrc, 0, dbSources.length); - System.arraycopy(otherdb, 0, newsrc, dbSources.length, - otherdb.length); - dbSources = newsrc; - } - } - - /** * start the fetcher thread * * @param waitTillFinished @@ -311,14 +268,14 @@ public class DBRefFetcher implements Runnable } else if (seqs == null) { - seqs = new Vector(); + seqs = new Vector<>(); seqs.addElement(seq); } } else { - seqs = new Vector(); + seqs = new Vector<>(); seqs.addElement(seq); } @@ -357,9 +314,9 @@ public class DBRefFetcher implements Runnable e.printStackTrace(); } - Vector sdataset = new Vector( + Vector sdataset = new Vector<>( Arrays.asList(dataset)); - List warningMessages = new ArrayList(); + List warningMessages = new ArrayList<>(); int db = 0; while (sdataset.size() > 0 && db < dbSources.length) @@ -371,8 +328,8 @@ public class DBRefFetcher implements Runnable SequenceI[] currSeqs = new SequenceI[sdataset.size()]; sdataset.copyInto(currSeqs);// seqs that are to be validated against // dbSources[db] - Vector queries = new Vector(); // generated queries curSeq - seqRefs = new Hashtable>(); + Vector queries = new Vector<>(); // generated queries curSeq + seqRefs = new Hashtable<>(); int seqIndex = 0; @@ -574,7 +531,7 @@ public class DBRefFetcher implements Runnable { // Work out which sequences this sequence matches, // taking into account all accessionIds and names in the file - Vector sequenceMatches = new Vector(); + Vector sequenceMatches = new Vector<>(); // look for corresponding accession ids DBRefEntry[] entryRefs = DBRefUtils .selectRefs(retrievedSeq.getDBRefs(), new String[] @@ -826,7 +783,7 @@ public class DBRefFetcher implements Runnable */ private SequenceI[] recoverDbSequences(SequenceI[] sequencesArray) { - Vector nseq = new Vector(); + Vector nseq = new Vector<>(); for (int i = 0; sequencesArray != null && i < sequencesArray.length; i++) { diff --git a/src/jalview/ws/DasSequenceFeatureFetcher.java b/src/jalview/ws/DasSequenceFeatureFetcher.java deleted file mode 100644 index c661e2c..0000000 --- a/src/jalview/ws/DasSequenceFeatureFetcher.java +++ /dev/null @@ -1,925 +0,0 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ -package jalview.ws; - -import jalview.bin.Cache; -import jalview.datamodel.DBRefEntry; -import jalview.datamodel.DBRefSource; -import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceI; -import jalview.gui.AlignFrame; -import jalview.gui.Desktop; -import jalview.gui.FeatureSettings; -import jalview.gui.JvOptionPane; -import jalview.util.DBRefUtils; -import jalview.util.MessageManager; -import jalview.util.UrlLink; -import jalview.ws.dbsources.das.api.DasSourceRegistryI; -import jalview.ws.dbsources.das.api.jalviewSourceI; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.Vector; - -import org.biodas.jdas.client.FeaturesClient; -import org.biodas.jdas.client.adapters.features.DasGFFAdapter; -import org.biodas.jdas.client.adapters.features.DasGFFAdapter.GFFAdapter; -import org.biodas.jdas.client.threads.FeaturesClientMultipleSources; -import org.biodas.jdas.schema.features.ERRORSEGMENT; -import org.biodas.jdas.schema.features.FEATURE; -import org.biodas.jdas.schema.features.LINK; -import org.biodas.jdas.schema.features.SEGMENT; -import org.biodas.jdas.schema.features.TYPE; -import org.biodas.jdas.schema.features.UNKNOWNFEATURE; -import org.biodas.jdas.schema.features.UNKNOWNSEGMENT; -import org.biodas.jdas.schema.sources.COORDINATES; - -/** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ -public class DasSequenceFeatureFetcher -{ - SequenceI[] sequences; - - AlignFrame af; - - FeatureSettings fsettings; - - StringBuffer sbuffer = new StringBuffer(); - - List selectedSources; - - boolean cancelled = false; - - private void debug(String mesg) - { - debug(mesg, null); - } - - private void debug(String mesg, Exception e) - { - if (Cache.log != null) - { - Cache.log.debug(mesg, e); - } - else - { - System.err.println(mesg); - if (e != null) - { - e.printStackTrace(); - } - } - } - - long startTime; - - private DasSourceRegistryI sourceRegistry; - - private boolean useJDASMultiThread = true; - - /** - * Creates a new SequenceFeatureFetcher object. Uses default - * - * @param align - * DOCUMENT ME! - * @param ap - * DOCUMENT ME! - */ - public DasSequenceFeatureFetcher(SequenceI[] sequences, - FeatureSettings fsettings, Vector selectedSources) - { - this(sequences, fsettings, selectedSources, true, true, true); - } - - public DasSequenceFeatureFetcher(SequenceI[] oursequences, - FeatureSettings fsettings, List selectedSources2, - boolean checkDbrefs, boolean promptFetchDbrefs) - { - this(oursequences, fsettings, selectedSources2, checkDbrefs, - promptFetchDbrefs, true); - } - - public DasSequenceFeatureFetcher(SequenceI[] oursequences, - FeatureSettings fsettings, List selectedSources2, - boolean checkDbrefs, boolean promptFetchDbrefs, - boolean useJDasMultiThread) - { - this.useJDASMultiThread = useJDasMultiThread; - this.selectedSources = new ArrayList<>(); - // filter both sequences and sources to eliminate duplicates - for (jalviewSourceI src : selectedSources2) - { - if (!selectedSources.contains(src)) - { - selectedSources.add(src); - } - ; - } - Vector sqs = new Vector(); - for (int i = 0; i < oursequences.length; i++) - { - if (!sqs.contains(oursequences[i])) - { - sqs.addElement(oursequences[i]); - } - } - sequences = new SequenceI[sqs.size()]; - for (int i = 0; i < sequences.length; i++) - { - sequences[i] = (SequenceI) sqs.elementAt(i); - } - if (fsettings != null) - { - this.fsettings = fsettings; - this.af = fsettings.af; - af.setShowSeqFeatures(true); - } - int uniprotCount = 0; - for (jalviewSourceI source : selectedSources) - { - for (COORDINATES coords : source.getVersion().getCOORDINATES()) - { - // TODO: match UniProt coord system canonically (?) - does - // UniProt==uniprot==UNIPROT ? - if (coords.getAuthority().toLowerCase().equals("uniprot")) - { - uniprotCount++; - break; - } - } - } - - int refCount = 0; - for (int i = 0; i < sequences.length; i++) - { - DBRefEntry[] dbref = sequences[i].getDBRefs(); - if (dbref != null) - { - for (int j = 0; j < dbref.length; j++) - { - if (dbref[j].getSource().equals(DBRefSource.UNIPROT)) - { - refCount++; - break; - } - } - } - } - - if (checkDbrefs && refCount < sequences.length && uniprotCount > 0) - { - - int reply = JvOptionPane.YES_OPTION; - if (promptFetchDbrefs) - { - reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop, - MessageManager.getString( - "info.you_want_jalview_to_find_uniprot_accessions"), - MessageManager - .getString("label.find_uniprot_accession_ids"), - JvOptionPane.YES_NO_OPTION, JvOptionPane.QUESTION_MESSAGE); - } - - if (reply == JvOptionPane.YES_OPTION) - { - Thread thread = new Thread(new FetchDBRefs()); - thread.start(); - } - else - { - _startFetching(); - } - } - else - { - _startFetching(); - } - - } - - private void _startFetching() - { - running = true; - new Thread(new FetchSeqFeatures()).start(); - } - - class FetchSeqFeatures implements Runnable - { - @Override - public void run() - { - startFetching(); - setGuiFetchComplete(); - } - } - - class FetchDBRefs implements Runnable - { - @Override - public void run() - { - running = true; - boolean isNucleotide = af.getViewport().getAlignment().isNucleotide(); - new DBRefFetcher(sequences, af, null, af.featureSettings, - isNucleotide).fetchDBRefs(true); - - startFetching(); - setGuiFetchComplete(); - } - } - - /** - * Spawns Fetcher threads to add features to sequences in the dataset - */ - void startFetching() - { - running = true; - cancelled = false; - startTime = System.currentTimeMillis(); - if (af != null) - { - af.setProgressBar(MessageManager.getString( - "status.fetching_das_sequence_features"), startTime); - } - if (sourceRegistry == null) - { - sourceRegistry = Cache.getDasSourceRegistry(); - } - if (selectedSources == null || selectedSources.size() == 0) - { - try - { - jalviewSourceI[] sources = sourceRegistry.getSources() - .toArray(new jalviewSourceI[0]); - String active = Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot"); - StringTokenizer st = new StringTokenizer(active, "\t"); - selectedSources = new Vector(); - String token; - while (st.hasMoreTokens()) - { - token = st.nextToken(); - for (int i = 0; i < sources.length; i++) - { - if (sources[i].getTitle().equals(token)) - { - selectedSources.add(sources[i]); - break; - } - } - } - } catch (Exception ex) - { - debug("Exception whilst setting default feature sources from registry and local preferences.", - ex); - } - } - - if (selectedSources == null || selectedSources.size() == 0) - { - System.out.println("No DAS Sources active"); - cancelled = true; - setGuiNoDassourceActive(); - return; - } - - sourcesRemaining = selectedSources.size(); - FeaturesClientMultipleSources fc = new FeaturesClientMultipleSources(); - fc.setConnProps(sourceRegistry.getSessionHandler()); - // Now sending requests one at a time to each server - ArrayList srcobj = new ArrayList<>(); - ArrayList src = new ArrayList<>(); - List> ids = new ArrayList<>(); - List> idobj = new ArrayList<>(); - List> sqset = new ArrayList<>(); - for (jalviewSourceI _sr : selectedSources) - { - - Map slist = new HashMap<>(); - List idob = new ArrayList<>(); - List qset = new ArrayList<>(); - - for (SequenceI seq : sequences) - { - Object[] idset = nextSequence(_sr, seq); - if (idset != null) - { - List _idob = (List) idset[0]; - List _qset = (List) idset[1]; - if (_idob.size() > 0) - { - // add sequence's ref for each id derived from it - // (space inefficient, but most unambiguous) - // could replace with hash with _qset values as keys. - Iterator dbobj = _idob.iterator(); - for (String q : _qset) - { - SequenceI osq = slist.get(q); - DBRefEntry dr = dbobj.next(); - if (osq != null && osq != seq) - { - // skip - non-canonical query - } - else - { - idob.add(dr); - qset.add(q); - slist.put(q, seq); - } - } - } - } - } - if (idob.size() > 0) - { - srcobj.add(_sr); - src.add(_sr.getSourceURL()); - ids.add(qset); - idobj.add(idob); - sqset.add(slist); - } - } - Map, Exception>> errors = new HashMap<>(); - Map, DasGFFAdapter>> results = new HashMap<>(); - if (!useJDASMultiThread) - { - Iterator sources = src.iterator(); - // iterate over each query for each source and do each one individually - for (List idl : ids) - { - String source = sources.next(); - FeaturesClient featuresc = new FeaturesClient( - sourceRegistry.getSessionHandler() - .getConnectionPropertyProviderFor(source)); - for (String id : idl) - { - List qid = Arrays.asList(new String[] { id }); - try - { - DasGFFAdapter dga = featuresc.fetchData(source, qid); - Map, DasGFFAdapter> ers = results.get(source); - if (ers == null) - { - results.put(source, - ers = new HashMap<>()); - } - ers.put(qid, dga); - } catch (Exception ex) - { - Map, Exception> ers = errors.get(source); - if (ers == null) - { - errors.put(source, - ers = new HashMap<>()); - } - ers.put(qid, ex); - } - } - } - } - else - { - // pass them all at once - fc.fetchData(src, ids, false, results, errors); - fc.shutDown(); - while (!fc.isTerminated()) - { - try - { - Thread.sleep(200); - } catch (InterruptedException x) - { - - } - } - } - Iterator> idset = ids.iterator(); - Iterator> idobjset = idobj.iterator(); - Iterator> seqset = sqset.iterator(); - for (jalviewSourceI source : srcobj) - { - processResponse(seqset.next(), source, idset.next(), idobjset.next(), - results.get(source.getSourceURL()), - errors.get(source.getSourceURL())); - } - } - - private void processResponse(Map sequencemap, - jalviewSourceI jvsource, List ids, List idobj, - Map, DasGFFAdapter> results, - Map, Exception> errors) - { - Set sequences = new HashSet<>(); - String source = jvsource.getSourceURL(); - // process features - DasGFFAdapter result = (results == null) ? null : results.get(ids); - Exception error = (errors == null) ? null : errors.get(ids); - if (result == null) - { - debug("das source " + source + " could not be contacted. " - + (error == null ? "" : error.toString())); - } - else - { - - GFFAdapter gff = result.getGFF(); - List segments = gff.getSegments(); - List errorsegs = gff.getErrorSegments(); - List unkfeats = gff.getUnknownFeatures(); - List unksegs = gff.getUnknownSegments(); - debug("das source " + source + " returned " + gff.getTotal() - + " responses. " + (errorsegs != null ? errorsegs.size() : 0) - + " were incorrect segment queries, " - + (unkfeats != null ? unkfeats.size() : 0) - + " were unknown features " - + (unksegs != null ? unksegs.size() : 0) - + " were unknown segments and " - + (segments != null ? segments.size() : 0) - + " were segment responses."); - Iterator dbr = idobj.iterator(); - if (segments != null) - { - for (SEGMENT seg : segments) - { - String id = seg.getId(); - if (ids.indexOf(id) == -1) - { - id = id.toUpperCase(); - } - DBRefEntry dbref = idobj.get(ids.indexOf(id)); - SequenceI sequence = sequencemap.get(id); - boolean added = false; - sequences.add(sequence); - - for (FEATURE feat : seg.getFEATURE()) - { - // standard DAS feature-> jalview sequence feature transformation - SequenceFeature f = newSequenceFeature(feat, - jvsource.getTitle()); - if (!parseSeqFeature(sequence, f, feat, jvsource)) - { - if (dbref.getMap() != null && f.getBegin() > 0 - && f.getEnd() > 0) - { - debug("mapping from " + f.getBegin() + " - " + f.getEnd()); - SequenceFeature vf[] = null; - - try - { - vf = dbref.getMap().locateFeature(f); - } catch (Exception ex) - { - Cache.log.warn( - "Error in 'experimental' mapping of features. Please try to reproduce and then report info to jalview-discuss@jalview.org."); - Cache.log.warn("Mapping feature from " + f.getBegin() - + " to " + f.getEnd() + " in dbref " - + dbref.getAccessionId() + " in " - + dbref.getSource()); - Cache.log.warn("using das Source " + source); - Cache.log.warn("Exception", ex); - } - - if (vf != null) - { - for (int v = 0; v < vf.length; v++) - { - debug("mapping to " + v + ": " + vf[v].getBegin() - + " - " + vf[v].getEnd()); - sequence.addSequenceFeature(vf[v]); - } - } - } - else - { - sequence.addSequenceFeature(f); - } - } - } - } - featuresAdded(sequences); - } - else - { - // System.out.println("No features found for " + seq.getName() - // + " from: " + e.getDasSource().getNickname()); - } - } - } - - private void setGuiNoDassourceActive() - { - - if (af != null) - { - af.setProgressBar( - MessageManager.getString("status.no_das_sources_active"), - startTime); - } - if (getFeatSettings() != null) - { - fsettings.noDasSourceActive(); - } - } - - /** - * Update our fsettings dialog reference if we didn't have one when we were - * first initialised. - * - * @return fsettings - */ - private FeatureSettings getFeatSettings() - { - if (fsettings == null) - { - if (af != null) - { - fsettings = af.featureSettings; - } - } - return fsettings; - } - - public void cancel() - { - if (af != null) - { - af.setProgressBar(MessageManager.getString( - "status.das_feature_fetching_cancelled"), startTime); - } - cancelled = true; - } - - int sourcesRemaining = 0; - - private boolean running = false; - - private void setGuiFetchComplete() - { - running = false; - if (!cancelled && af != null) - { - // only update the progress bar if we've completed the fetch normally - af.setProgressBar(MessageManager.getString( - "status.das_feature_fetching_complete"), startTime); - } - - if (af != null && af.featureSettings != null) - { - af.featureSettings.discoverAllFeatureData(); - } - - if (getFeatSettings() != null) - { - fsettings.complete(); - } - } - - void featuresAdded(Set seqs) - { - if (af == null) - { - // no gui to update with features. - return; - } - af.getFeatureRenderer().featuresAdded(); - - int start = af.getViewport().getRanges().getStartSeq(); - int end = af.getViewport().getRanges().getEndSeq(); - int index; - for (index = start; index < end; index++) - { - for (SequenceI seq : seqs) - { - if (seq == af.getViewport().getAlignment().getSequenceAt(index) - .getDatasetSequence()) - { - af.alignPanel.paintAlignment(true, true); - index = end; - break; - } - } - } - } - - Object[] nextSequence(jalviewSourceI dasSource, SequenceI seq) - { - if (cancelled) - { - return null; - } - DBRefEntry[] uprefs = DBRefUtils.selectRefs(seq.getDBRefs(), - new String[] - { - // jalview.datamodel.DBRefSource.PDB, - DBRefSource.UNIPROT, - // jalview.datamodel.DBRefSource.EMBL - not tested on any EMBL coord - // sys sources - }); - // TODO: minimal list of DAS queries to make by querying with untyped ID if - // distinct from any typed IDs - - List ids = new ArrayList<>(); - List qstring = new ArrayList<>(); - boolean dasCoordSysFound = false; - - if (uprefs != null) - { - // do any of these ids match the source's coordinate system ? - for (int j = 0; !dasCoordSysFound && j < uprefs.length; j++) - { - - for (COORDINATES csys : dasSource.getVersion().getCOORDINATES()) - { - if (DBRefUtils.isDasCoordinateSystem(csys.getAuthority(), - uprefs[j])) - { - debug("Launched fetcher for coordinate system " - + csys.getAuthority()); - // Will have to pass any mapping information to the fetcher - // - the start/end for the DBRefEntry may not be the same as the - // sequence's start/end - - System.out.println( - seq.getName() + " " + (seq.getDatasetSequence() == null) - + " " + csys.getUri()); - - dasCoordSysFound = true; // break's out of the loop - ids.add(uprefs[j]); - qstring.add(uprefs[j].getAccessionId()); - } - else - { - System.out.println("IGNORE " + csys.getAuthority()); - } - } - } - } - - if (!dasCoordSysFound) - { - String id = null; - // try and use the name as the sequence id - if (seq.getName().indexOf("|") > -1) - { - id = seq.getName().substring(seq.getName().lastIndexOf("|") + 1); - if (id.trim().length() < 4) - { - // hack - we regard a significant ID as being at least 4 - // non-whitespace characters - id = seq.getName().substring(0, seq.getName().lastIndexOf("|")); - if (id.indexOf("|") > -1) - { - id = id.substring(id.lastIndexOf("|") + 1); - } - } - } - else - { - id = seq.getName(); - } - if (id != null) - { - DBRefEntry dbre = new DBRefEntry(); - dbre.setAccessionId(id); - // Should try to call a general feature fetcher that - // queries many sources with name to discover applicable ID references - ids.add(dbre); - qstring.add(dbre.getAccessionId()); - } - } - - return new Object[] { ids, qstring }; - } - - /** - * examine the given sequence feature to determine if it should actually be - * turned into sequence annotation or database cross references rather than a - * simple sequence feature. - * - * @param seq - * the sequence to annotate - * @param f - * the jalview sequence feature generated from the DAS feature - * @param map - * the sequence feature attributes - * @param source - * the source that emitted the feature - * @return true if feature was consumed as another kind of annotation. - */ - protected boolean parseSeqFeature(SequenceI seq, SequenceFeature f, - FEATURE feature, jalviewSourceI source) - { - SequenceI mseq = seq; - while (seq.getDatasetSequence() != null) - { - seq = seq.getDatasetSequence(); - } - if (f.getType() != null) - { - String type = f.getType(); - if (type.equalsIgnoreCase("protein_name")) - { - // parse name onto the alignment sequence or the dataset sequence. - if (seq.getDescription() == null - || seq.getDescription().trim().length() == 0) - { - // could look at the note series to pick out the first long name, for - // the moment just use the whole description string - seq.setDescription(f.getDescription()); - } - if (mseq.getDescription() == null - || mseq.getDescription().trim().length() == 0) - { - // could look at the note series to pick out the first long name, for - // the moment just use the whole description string - mseq.setDescription(f.getDescription()); - } - return true; - } - // check if source has biosapiens or other sequence ontology label - if (type.equalsIgnoreCase("DBXREF") || type.equalsIgnoreCase("DBREF")) - { - // try to parse the accession out - - DBRefEntry dbr = new DBRefEntry(); - dbr.setVersion(source.getTitle()); - StringTokenizer st = new StringTokenizer(f.getDescription(), ":"); - if (st.hasMoreTokens()) - { - dbr.setSource(st.nextToken()); - } - if (st.hasMoreTokens()) - { - dbr.setAccessionId(st.nextToken()); - } - seq.addDBRef(dbr); - - if (f.links != null && f.links.size() > 0) - { - // feature is also appended to enable links to be seen. - // TODO: consider extending dbrefs to have their own links ? - // TODO: new feature: extract dbref links from DAS servers and add the - // URL pattern to the list of DB name associated links in the user's - // preferences ? - // for the moment - just fix up the existing feature so it displays - // correctly. - // f.setType(dbr.getSource()); - // f.setDescription(); - f.setValue("linkonly", Boolean.TRUE); - // f.setDescription(""); - Vector newlinks = new Vector(); - Enumeration it = f.links.elements(); - while (it.hasMoreElements()) - { - String elm; - UrlLink urllink = new UrlLink(elm = (String) it.nextElement()); - if (urllink.isValid()) - { - urllink.setLabel(f.getDescription()); - newlinks.addElement(urllink.toString()); - } - else - { - // couldn't parse the link properly. Keep it anyway - just in - // case. - debug("couldn't parse link string - " + elm); - newlinks.addElement(elm); - } - } - f.links = newlinks; - seq.addSequenceFeature(f); - } - return true; - } - } - return false; - } - - /** - * creates a jalview sequence feature from a das feature document - * - * @param feat - * @return sequence feature object created using dasfeature information - */ - SequenceFeature newSequenceFeature(FEATURE feat, String nickname) - { - if (feat == null) - { - return null; - } - try - { - /** - * Different qNames for a DAS Feature - are string keys to the HashMaps in - * features "METHOD") || qName.equals("TYPE") || qName.equals("START") || - * qName.equals("END") || qName.equals("NOTE") || qName.equals("LINK") || - * qName.equals("SCORE") - */ - String desc = new String(); - if (feat.getNOTE() != null) - { - for (String note : feat.getNOTE()) - { - desc += note; - } - } - - int start = 0, end = 0; - float score = 0f; - - try - { - start = Integer.parseInt(feat.getSTART().toString()); - } catch (Exception ex) - { - } - try - { - end = Integer.parseInt(feat.getEND().toString()); - } catch (Exception ex) - { - } - try - { - Object scr = feat.getSCORE(); - if (scr != null) - { - score = (float) Double.parseDouble(scr.toString()); - - } - } catch (Exception ex) - { - } - - SequenceFeature f = new SequenceFeature(getTypeString(feat.getTYPE()), - desc, start, end, score, nickname); - - if (feat.getLINK() != null) - { - for (LINK link : feat.getLINK()) - { - // Do not put feature extent in link text for non-positional features - if (f.begin == 0 && f.end == 0) - { - f.addLink(f.getType() + " " + link.getContent() + "|" - + link.getHref()); - } - else - { - f.addLink(f.getType() + " " + f.begin + "_" + f.end + " " - + link.getContent() + "|" + link.getHref()); - } - } - } - - return f; - } catch (Exception e) - { - System.out.println("ERRR " + e); - e.printStackTrace(); - System.out.println("############"); - debug("Failed to parse " + feat.toString(), e); - return null; - } - } - - private String getTypeString(TYPE type) - { - return type.getContent(); - } - - public boolean isRunning() - { - return running; - } - -} diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java index a0b77de..29d4ec7 100644 --- a/src/jalview/ws/SequenceFetcher.java +++ b/src/jalview/ws/SequenceFetcher.java @@ -29,12 +29,10 @@ import jalview.ws.dbsources.PfamFull; import jalview.ws.dbsources.PfamSeed; import jalview.ws.dbsources.RfamSeed; import jalview.ws.dbsources.Uniprot; -import jalview.ws.dbsources.das.api.jalviewSourceI; import jalview.ws.seqfetcher.ASequenceFetcher; import jalview.ws.seqfetcher.DbSourceProxy; import java.util.ArrayList; -import java.util.List; /** * This implements the run-time discovery of sequence database clients. @@ -50,11 +48,6 @@ public class SequenceFetcher extends ASequenceFetcher */ public SequenceFetcher() { - this(true); - } - - public SequenceFetcher(boolean addDas) - { addDBRefSourceImpl(EnsemblGene.class); addDBRefSourceImpl(EnsemblGenomes.class); addDBRefSourceImpl(EmblSource.class); @@ -64,26 +57,19 @@ public class SequenceFetcher extends ASequenceFetcher addDBRefSourceImpl(PfamFull.class); addDBRefSourceImpl(PfamSeed.class); addDBRefSourceImpl(RfamSeed.class); - - if (addDas) - { - registerDasSequenceSources(); - } } /** - * return an ordered list of database sources where non-das database classes - * appear before das database classes + * return an ordered list of database sources excluding alignment only databases */ public String[] getOrderedSupportedSources() { String[] srcs = this.getSupportedDb(); - ArrayList dassrc = new ArrayList(), - nondas = new ArrayList(); + ArrayList src = new ArrayList<>(); + for (int i = 0; i < srcs.length; i++) { - boolean das = false, skip = false; - String nm; + boolean skip = false; for (DbSourceProxy dbs : getSourceProxy(srcs[i])) { // Skip the alignment databases for the moment - they're not useful for @@ -92,86 +78,28 @@ public class SequenceFetcher extends ASequenceFetcher { skip = true; } - else - { - nm = dbs.getDbName(); - if (getSourceProxy( - srcs[i]) instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource) - { - if (nm.startsWith("das:")) - { - nm = nm.substring(4); - das = true; - } - break; - } - } } if (skip) { continue; } - if (das) { - dassrc.add(srcs[i]); - } - else - { - nondas.add(srcs[i]); + src.add(srcs[i]); } } - String[] tosort = nondas.toArray(new String[0]), - sorted = nondas.toArray(new String[0]); + String[] tosort = src.toArray(new String[0]), + sorted = src.toArray(new String[0]); for (int j = 0, jSize = sorted.length; j < jSize; j++) { tosort[j] = tosort[j].toLowerCase(); } jalview.util.QuickSort.sort(tosort, sorted); // construct array with all sources listed - - srcs = new String[sorted.length + dassrc.size()]; int i = 0; for (int j = sorted.length - 1; j >= 0; j--, i++) { srcs[i] = sorted[j]; - sorted[j] = null; - } - - sorted = dassrc.toArray(new String[0]); - tosort = dassrc.toArray(new String[0]); - for (int j = 0, jSize = sorted.length; j < jSize; j++) - { - tosort[j] = tosort[j].toLowerCase(); - } - jalview.util.QuickSort.sort(tosort, sorted); - for (int j = sorted.length - 1; j >= 0; j--, i++) - { - srcs[i] = sorted[j]; } return srcs; } - - /** - * query the currently defined DAS source registry for sequence sources and - * add a DasSequenceSource instance for each source to the SequenceFetcher - * source list. - */ - public void registerDasSequenceSources() - { - // TODO: define a context as a registry provider (either desktop, - // jalview.bin.cache, or something else). - for (jalviewSourceI source : jalview.bin.Cache.getDasSourceRegistry() - .getSources()) - { - if (source.isSequenceSource()) - { - List dassources = source.getSequenceSourceProxies(); - for (DbSourceProxy seqsrc : dassources) - { - addDbRefSourceImpl(seqsrc); - } - } - } - } - } diff --git a/src/jalview/ws/dbsources/das/api/DasSourceRegistryI.java b/src/jalview/ws/dbsources/das/api/DasSourceRegistryI.java deleted file mode 100644 index 55c50b2..0000000 --- a/src/jalview/ws/dbsources/das/api/DasSourceRegistryI.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ -package jalview.ws.dbsources.das.api; - -import java.util.List; - -import org.biodas.jdas.client.threads.MultipleConnectionPropertyProviderI; - -/** - * API for a registry that provides datasources that jalview can access - * - * @author jprocter - * - */ -public interface DasSourceRegistryI -{ - - List getSources(); - - String getDasRegistryURL(); - - jalviewSourceI getSource(String nickname); - - // TODO: re JAL-424 - introduce form where local source is queried for - // metadata, rather than have it all provided by caller. - jalviewSourceI createLocalSource(String uri, String name, - boolean sequence, boolean features); - - boolean removeLocalSource(jalviewSourceI source); - - void refreshSources(); - - String getLocalSourceString(); - - List resolveSourceNicknames(List sources); - - // TODO: refactor to jDAS specific interface - MultipleConnectionPropertyProviderI getSessionHandler(); -} diff --git a/src/jalview/ws/dbsources/das/api/jalviewSourceI.java b/src/jalview/ws/dbsources/das/api/jalviewSourceI.java deleted file mode 100644 index bc3c8ea..0000000 --- a/src/jalview/ws/dbsources/das/api/jalviewSourceI.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ -package jalview.ws.dbsources.das.api; - -import jalview.ws.seqfetcher.DbSourceProxy; - -import java.util.List; - -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 getSequenceSourceProxies(); - - boolean isFeatureSource(); - - /** - * returns the base URL for the latest version of a source's DAS endpoint set - * - * @return - */ - String getSourceURL(); - - /** - * test to see if this source's latest version is older than the given source - * - * @param jalviewSourceI - * @return true if newer than given source - */ - boolean isNewerThan(jalviewSourceI jalviewSourceI); - - /** - * test if the source is a reference source for the authority - * - * @return - */ - boolean isReferenceSource(); - -} diff --git a/src/jalview/ws/dbsources/das/datamodel/DasSequenceSource.java b/src/jalview/ws/dbsources/das/datamodel/DasSequenceSource.java deleted file mode 100644 index 84f6d4d..0000000 --- a/src/jalview/ws/dbsources/das/datamodel/DasSequenceSource.java +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ -package jalview.ws.dbsources.das.datamodel; - -import jalview.bin.Cache; -import jalview.datamodel.Alignment; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.DBRefEntry; -import jalview.datamodel.Sequence; -import jalview.datamodel.SequenceI; -import jalview.util.MessageManager; -import jalview.ws.dbsources.das.api.jalviewSourceI; -import jalview.ws.seqfetcher.DbSourceProxy; -import jalview.ws.seqfetcher.DbSourceProxyImpl; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; -import java.util.Vector; - -import org.biodas.jdas.client.SequenceClient; -import org.biodas.jdas.client.adapters.sequence.DasSequenceAdapter; -import org.biodas.jdas.client.threads.MultipleConnectionPropertyProviderI; -import org.biodas.jdas.client.threads.SequenceClientMultipleSources; -import org.biodas.jdas.schema.sequence.SEQUENCE; -import org.biodas.jdas.schema.sources.COORDINATES; -import org.biodas.jdas.schema.sources.SOURCE; -import org.biodas.jdas.schema.sources.VERSION; - -import com.stevesoft.pat.Regex; - -/** - * an instance of this class is created for each unique DAS Sequence source (ie - * one capable of handling the 'sequence' for a particular MapMaster) - * - * @author JimP - * - */ -public class DasSequenceSource extends DbSourceProxyImpl - implements DbSourceProxy -{ - private jalviewSourceI jsrc; - - protected SOURCE source = null; - - protected VERSION version = null; - - protected COORDINATES coordsys = null; - - protected String dbname = "DASCS"; - - protected String dbrefname = "das:source"; - - protected MultipleConnectionPropertyProviderI connprops = null; - - /** - * DAS sources are tier 1 - if we have a direct DB connection then we should - * prefer it - */ - private int tier = 1; - - /** - * create a new DbSource proxy for a DAS 1 source - * - * @param dbnbame - * Human Readable Name to use when fetching from this source - * @param dbrefname - * DbRefName for DbRefs attached to sequences retrieved from this - * source - * @param source - * Das1Source - * @param coordsys - * specific coordinate system to use for this source - * @throws Exception - * if source is not capable of the 'sequence' command - */ - public DasSequenceSource(String dbname, String dbrefname, SOURCE source, - VERSION version, COORDINATES coordsys, - MultipleConnectionPropertyProviderI connprops) throws Exception - { - if (!(jsrc = new JalviewSource(source, connprops, false)) - .isSequenceSource()) - { - throw new Exception(MessageManager.formatMessage( - "exception.das_source_doesnt_support_sequence_command", - new String[] - { source.getTitle() })); - } - this.tier = 1 + ((jsrc.isLocal() || jsrc.isReferenceSource()) ? 0 : 1); - this.source = source; - this.dbname = dbname; - this.dbrefname = dbrefname.toUpperCase(); - if (coordsys != null) - { - this.coordsys = coordsys; - } - this.connprops = connprops; - } - - public String getAccessionSeparator() - { - return "\t"; - } - - public Regex getAccessionValidator() - { - /** ? * */ - return Regex.perlCode("m/([^:]+)(:\\d+,\\d+)?/"); - } - - public String getDbName() - { - // TODO: map to - return dbname + " (DAS)"; - } - - public String getDbSource() - { - return dbrefname; - } - - public String getDbVersion() - { - return coordsys != null ? coordsys.getVersion() : ""; - } - - public AlignmentI getSequenceRecords(String queries) throws Exception - { - StringTokenizer st = new StringTokenizer(queries, "\t"); - List toks = new ArrayList(), - src = new ArrayList(), acIds = new ArrayList(); - while (st.hasMoreTokens()) - { - String t; - toks.add(t = st.nextToken()); - acIds.add(t.replaceAll(":[0-9,]+", "")); - } - src.add(jsrc.getSourceURL()); - Map, DasSequenceAdapter>> resultset = new HashMap, DasSequenceAdapter>>(); - Map, Exception>> errors = new HashMap, Exception>>(); - - // First try multiple sources - boolean multiple = true, retry = false; - do - { - if (!multiple) - { - retry = false; - // slow, fetch one at a time. - for (String sr : src) - { - System.err.println( - "Retrieving IDs individually from das source: " + sr); - org.biodas.jdas.client.SequenceClient sq = new SequenceClient( - connprops.getConnectionPropertyProviderFor(sr)); - for (String q : toks) - { - List qset = Arrays.asList(new String[] { q }); - try - { - DasSequenceAdapter s = sq.fetchData(sr, qset); - Map, DasSequenceAdapter> dss = resultset.get(sr); - if (dss == null) - { - resultset.put(sr, - dss = new HashMap, DasSequenceAdapter>()); - } - dss.put(qset, s); - } catch (Exception x) - { - Map, Exception> ers = errors.get(sr); - if (ers == null) - { - errors.put(sr, - ers = new HashMap, Exception>()); - } - ers.put(qset, x); - } - } - } - } - else - { - SequenceClientMultipleSources sclient; - sclient = new SequenceClientMultipleSources(); - sclient.fetchData(src, toks, resultset, errors); - sclient.shutDown(); - while (!sclient.isTerminated()) - { - try - { - Thread.sleep(200); - - } catch (InterruptedException x) - { - } - } - if (resultset.isEmpty() && !errors.isEmpty()) - { - retry = true; - multiple = false; - } - } - } while (retry); - - if (resultset.isEmpty()) - { - System.err.println("Sequence Query to " + jsrc.getTitle() + " with '" - + queries + "' returned no sequences."); - return null; - } - else - { - Vector seqs = null; - for (Map.Entry, DasSequenceAdapter>> resset : resultset - .entrySet()) - { - for (Map.Entry, DasSequenceAdapter> result : resset - .getValue().entrySet()) - { - DasSequenceAdapter dasseqresp = result.getValue(); - List accessions = result.getKey(); - for (SEQUENCE e : dasseqresp.getSequence()) - { - String lbl = e.getId(); - - if (acIds.indexOf(lbl) == -1) - { - System.err.println( - "Warning - received sequence event for strange accession code (" - + lbl + ")"); - } - else - { - if (seqs == null) - { - if (e.getContent().length() == 0) - { - System.err.println( - "Empty sequence returned for accession code (" - + lbl + ") from " + resset.getKey() - + " (source is " + getDbName()); - continue; - } - } - seqs = new java.util.Vector(); - // JDAS returns a sequence complete with any newlines and spaces - // in the XML - Sequence sq = new Sequence(lbl, - e.getContent().replaceAll("\\s+", "")); - sq.setStart(e.getStart().intValue()); - sq.addDBRef(new DBRefEntry(getDbSource(), - getDbVersion() + ":" + e.getVersion(), lbl)); - seqs.addElement(sq); - } - } - } - } - - if (seqs == null || seqs.size() == 0) - return null; - SequenceI[] sqs = new SequenceI[seqs.size()]; - for (int i = 0, iSize = seqs.size(); i < iSize; i++) - { - sqs[i] = (SequenceI) seqs.elementAt(i); - } - Alignment al = new Alignment(sqs); - if (jsrc.isFeatureSource()) - { - java.util.Vector srcs = new java.util.Vector(); - srcs.addElement(jsrc); - try - { - jalview.ws.DasSequenceFeatureFetcher dssf = new jalview.ws.DasSequenceFeatureFetcher( - sqs, null, srcs, false, false, multiple); - while (dssf.isRunning()) - { - try - { - Thread.sleep(200); - } catch (InterruptedException x) - { - - } - } - - } catch (Exception x) - { - Cache.log.error( - "Couldn't retrieve features for sequence from its source.", - x); - } - } - - return al; - } - } - - public String getTestQuery() - { - return coordsys == null ? "" : coordsys.getTestRange(); - } - - public boolean isValidReference(String accession) - { - // TODO try to validate an accession against source - // We don't really know how to do this without querying source - - return true; - } - - /** - * @return the source - */ - public SOURCE getSource() - { - return source; - } - - /** - * @return the coordsys - */ - public COORDINATES getCoordsys() - { - return coordsys; - } - - @Override - public int getTier() - { - return tier; - } -} diff --git a/src/jalview/ws/dbsources/das/datamodel/DasSourceRegistry.java b/src/jalview/ws/dbsources/das/datamodel/DasSourceRegistry.java deleted file mode 100644 index de7f380..0000000 --- a/src/jalview/ws/dbsources/das/datamodel/DasSourceRegistry.java +++ /dev/null @@ -1,484 +0,0 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ -package jalview.ws.dbsources.das.datamodel; - -import jalview.bin.Cache; -import jalview.ws.dbsources.das.api.DasSourceRegistryI; -import jalview.ws.dbsources.das.api.jalviewSourceI; - -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.List; -import java.util.StringTokenizer; - -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; - -/** - * - */ -public class DasSourceRegistry - implements DasSourceRegistryI, MultipleConnectionPropertyProviderI -{ - // private org.biodas.jdas.schema.sources.SOURCE[] dasSources = null; - private List dasSources = null; - - private Hashtable sourceNames = null; - - private Hashtable localSources = null; - - // public static String DEFAULT_REGISTRY = "http://www.dasregistry.org/das/"; - public static String DEFAULT_REGISTRY = "http://www.ebi.ac.uk/das-srv/registry/das/"; - - /** - * true if thread is running and we are talking to DAS registry service - */ - private boolean loadingDasSources = false; - - public boolean isLoadingDasSources() - { - return loadingDasSources; - } - - @Override - 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; - } - if (registry.lastIndexOf("sources.xml") == registry.length() - 11) - { - // no trailing sources.xml document for registry in JDAS - jalview.bin.Cache.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, - registry = registry.substring(0, - registry.lastIndexOf("sources.xml"))); - } - 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 getDASSources() - { - - return getDASSources(getDasRegistryURL(), this); - } - - /** - * query the given URL for DasSources. - * - * @param registryURL - * return sources from registryURL - */ - private static List getDASSources(String registryURL, - MultipleConnectionPropertyProviderI registry) - { - 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 dassources = sources.getSOURCE(); - ArrayList dsrc = new ArrayList(); - HashMap latests = new HashMap(); - Integer latest; - for (SOURCE src : dassources) - { - JalviewSource jsrc = new JalviewSource(src, registry, false); - latest = latests.get(jsrc.getSourceURL()); - if (latest != null) - { - if (jsrc.isNewerThan(dsrc.get(latest.intValue()))) - { - dsrc.set(latest.intValue(), jsrc); - } - else - { - System.out.println( - "Debug: Ignored older source " + jsrc.getTitle()); - } - } - else - { - latests.put(jsrc.getSourceURL(), Integer.valueOf(dsrc.size())); - dsrc.add(jsrc); - } - } - return dsrc; - } catch (Exception ex) - { - System.out.println( - "DAS1 registry at " + registryURL + " no longer exists"); - return new ArrayList(); - } - } - - public void run() - { - getSources(); - } - - @Override - public List 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) - { - int n = 1; - StringTokenizer st = new StringTokenizer(local, "\t"); - while (st.hasMoreTokens()) - { - String token = st.nextToken(); - int bar = token.indexOf("|"); - if (bar == -1) - { - System.err.println( - "Warning: DAS user local source appears to have no nickname (expected a '|' followed by nickname)\nOffending definition: '" - + token + "'"); - } - 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; - } - try - { - if (bar > -1) - { - createLocalSource(url, token.substring(0, bar), sequence, - features); - } - else - { - createLocalSource(url, "User Source" + n, sequence, features); - } - } catch (Exception q) - { - System.err.println( - "Unexpected exception when creating local source from '" - + token + "'"); - q.printStackTrace(); - } - n++; - } - } - } - } - - private List appendLocalSources() - { - List srclist = new ArrayList(); - addLocalDasSources(); - sourceNames = new Hashtable(); - 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(); - } - jalviewSourceI src = new JalviewSource(local, this, 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 v = new VERSION(); - List cp = new ArrayList(); - if (sequence) - { - /* - * Could try and synthesize a coordinate system for the source if needbe - * COORDINATES coord = new COORDINATES(); coord.setAuthority("NCBI"); - * coord.setSource("Chromosome"); coord.setTaxid("9606"); - * coord.setVersion("35"); version.getCOORDINATES().add(coord); - */ - CAPABILITY cap = new CAPABILITY(); - cap.setType("das1:" + Capabilities.SEQUENCE.getName()); - 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 resolveSourceNicknames(List sources) - { - ArrayList resolved = new ArrayList(); - 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 authStash; - static - { - authStash = new Hashtable(); - - 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; - } - -} diff --git a/src/jalview/ws/dbsources/das/datamodel/JalviewSource.java b/src/jalview/ws/dbsources/das/datamodel/JalviewSource.java deleted file mode 100644 index 07ba027..0000000 --- a/src/jalview/ws/dbsources/das/datamodel/JalviewSource.java +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ -package jalview.ws.dbsources.das.datamodel; - -import jalview.util.MessageManager; -import jalview.ws.dbsources.das.api.jalviewSourceI; -import jalview.ws.seqfetcher.DbSourceProxy; - -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; - -import org.biodas.jdas.client.threads.MultipleConnectionPropertyProviderI; -import org.biodas.jdas.dassources.Capabilities; -import org.biodas.jdas.dassources.utils.DasTimeFormat; -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; - -public class JalviewSource implements jalviewSourceI -{ - SOURCE source; - - MultipleConnectionPropertyProviderI connprov; - - public JalviewSource(SOURCE local2, - MultipleConnectionPropertyProviderI connprov, boolean local) - { - this.connprov = connprov; - 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; - } - - /** - * compare date strings. null or unparseable dates are assumed to be oldest - * - * @param ref - * @param newer - * @return true iff ref comes before newer - */ - private boolean isLaterThan(String ref, String newer) - { - Date refdate = null, newdate = null; - if (ref != null && ref.trim().length() > 0) - { - try - { - refdate = DasTimeFormat.fromDASString(ref.trim()); - - } catch (ParseException x) - { - } - } - if (newer != null && newer.trim().length() > 0) - { - try - { - newdate = DasTimeFormat.fromDASString(newer); - } catch (ParseException e) - { - } - } - 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 labels = new ArrayList(); - 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 labels = new ArrayList(); - for (CAPABILITY p : v.getCAPABILITY()) - { - // TODO: work out what to do with namespace prefix - // does SEQUENCE == das1:SEQUENCE and das2:SEQUENCE ? - // for moment, just show all capabilities... - if (p.getType().startsWith("das1:")) - { - labels.add(p.getType()); - } - } - return labels.toArray(new String[0]); - } - - @Override - public List getSequenceSourceProxies() - { - if (!isSequenceSource()) - { - return null; - } - ArrayList seqsources = new ArrayList(); - if (!local) - { - VERSION v = getVersion(); - Map latestc = new Hashtable(); - for (COORDINATES cs : v.getCOORDINATES()) - { - COORDINATES ltst = latestc.get(cs.getUri()); - if (ltst == null || ltst.getVersion() == null - || (ltst.getVersion() != null && cs.getVersion() != null - && isLaterThan(ltst.getVersion(), cs.getVersion()))) - { - latestc.put(cs.getUri(), cs); - } - } - for (COORDINATES cs : latestc.values()) - { - DasSequenceSource ds; - /* - * 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(ds = new DasSequenceSource( - getTitle() + " (" + cs.getAuthority() + " " - + cs.getSource() - + (cs.getVersion() != null ? " " + cs.getVersion() - : "") - + ")", - cs.getAuthority(), source, v, cs, connprov)); - if (seqsources.size() > 1) - { - System.err.println("Added another sequence DB source for " - + getTitle() + " (" + ds.getDbName() + ")"); - } - } 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(getTitle(), getTitle(), source, - getVersion(), null, connprov)); - } catch (Exception e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - if (seqsources.size() > 1) - { - // sort by name - DbSourceProxy[] tsort = seqsources.toArray(new DasSequenceSource[0]); - String[] nm = new String[tsort.length]; - for (int i = 0; i < nm.length; i++) - { - nm[i] = tsort[i].getDbName().toLowerCase(); - } - jalview.util.QuickSort.sort(nm, tsort); - seqsources.clear(); - for (DbSourceProxy ssrc : tsort) - { - seqsources.add(ssrc); - } - } - return seqsources; - } - - @Override - public String getSourceURL() - { - try - { - // kind of dumb, since - // org.biodas.jdas.dassources.utils.VersionAdapter.getSourceUriFromQueryUri() - // does this, - // but this way, we can access non DAS 1.6 compliant sources (which have - // to have a URL like /das/ and cause a validation exception) - - for (CAPABILITY cap : getVersion().getCAPABILITY()) - { - String capname = cap.getType() - .substring(cap.getType().indexOf(":") + 1); - int p = cap.getQueryUri().lastIndexOf(capname); - if (p < -1) - { - throw new Exception(MessageManager.formatMessage( - "exception.invalid_das_source", new String[] - { source.getUri() })); - } - if (cap.getQueryUri().charAt(p) == '/') - { - p--; - } - return cap.getQueryUri().substring(0, p); - } - } catch (Exception x) - { - System.err.println("Serious: Couldn't get the URL for source " - + source.getTitle()); - x.printStackTrace(); - } - return null; - } - - @Override - public boolean isNewerThan(jalviewSourceI other) - { - return isLaterThan(getVersion().getCreated(), - other.getVersion().getCreated()); - } - - @Override - public boolean isReferenceSource() - { - // TODO check source object for indication that we are the primary for a DAS - // coordinate system - return false; - } -} diff --git a/test/jalview/analysis/CrossRefTest.java b/test/jalview/analysis/CrossRefTest.java index 0265af3..b3c78be 100644 --- a/test/jalview/analysis/CrossRefTest.java +++ b/test/jalview/analysis/CrossRefTest.java @@ -427,7 +427,7 @@ public class CrossRefTest * argument false suppresses adding DAS sources * todo: define an interface type SequenceFetcherI and mock that */ - SequenceFetcher mockFetcher = new SequenceFetcher(false) + SequenceFetcher mockFetcher = new SequenceFetcher() { @Override public boolean isFetchable(String source) @@ -505,7 +505,7 @@ public class CrossRefTest * argument false suppresses adding DAS sources * todo: define an interface type SequenceFetcherI and mock that */ - SequenceFetcher mockFetcher = new SequenceFetcher(false) + SequenceFetcher mockFetcher = new SequenceFetcher() { @Override public boolean isFetchable(String source) @@ -651,7 +651,7 @@ public class CrossRefTest * passed in calls to getSequences() - important to verify that * duplicate sequence fetches are not requested */ - SequenceFetcher mockFetcher = new SequenceFetcher(false) + SequenceFetcher mockFetcher = new SequenceFetcher() { int call = 0; diff --git a/test/jalview/ws/PDBSequenceFetcherTest.java b/test/jalview/ws/PDBSequenceFetcherTest.java index cc3dca8..d1e32b9 100644 --- a/test/jalview/ws/PDBSequenceFetcherTest.java +++ b/test/jalview/ws/PDBSequenceFetcherTest.java @@ -62,7 +62,7 @@ public class PDBSequenceFetcherTest Cache.applicationProperties.setProperty("ADD_SS_ANN", Boolean.TRUE.toString()); - sf = new SequenceFetcher(false); + sf = new SequenceFetcher(); } /** diff --git a/test/jalview/ws/SequenceFetcherTest.java b/test/jalview/ws/SequenceFetcherTest.java index 32afd5f..0b501ee 100644 --- a/test/jalview/ws/SequenceFetcherTest.java +++ b/test/jalview/ws/SequenceFetcherTest.java @@ -52,26 +52,24 @@ public class SequenceFetcherTest */ public static void main(String[] argv) { - // TODO: extracted from SequenceFetcher - convert to proper unit test with + // TODO: extracted from SequenceFetcher - convert to network dependent + // functional integration test with // assertions String usage = "SequenceFetcher.main [-nodas] [ []]\n" + "With no arguments, all DbSources will be queried with their test Accession number.\n" + "With one argument, the argument will be resolved to one or more db sources and each will be queried with their test accession only.\n" - + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to and retrieve from it.\n" - + "The -nodas option will exclude DAS sources from the database fetchers Jalview will try to use."; - boolean withDas = true; - if (argv != null && argv.length > 0 - && argv[0].toLowerCase().startsWith("-nodas")) + + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to and retrieve from it."; + + if (argv != null && argv.length > 0) { - withDas = false; String targs[] = new String[argv.length - 1]; System.arraycopy(argv, 1, targs, 0, targs.length); argv = targs; } if (argv != null && argv.length > 0) { - List sps = new SequenceFetcher(withDas) + List sps = new SequenceFetcher() .getSourceProxy(argv[0]); if (sps != null) @@ -102,7 +100,7 @@ public class SequenceFetcherTest System.out.println(usage); return; } - ASequenceFetcher sfetcher = new SequenceFetcher(withDas); + ASequenceFetcher sfetcher = new SequenceFetcher(); String[] dbSources = sfetcher.getSupportedDb(); for (int dbsource = 0; dbsource < dbSources.length; dbsource++) { @@ -124,7 +122,7 @@ public class SequenceFetcherTest String testQuery) { AlignmentI ds = null; - Vector noProds = new Vector(); + Vector noProds = new Vector<>(); System.out.println("Source: " + sp.getDbName() + " (" + db + "): retrieving test:" + sp.getTestQuery()); { diff --git a/test/jalview/ws/dbsources/RemoteFormatTest.java b/test/jalview/ws/dbsources/RemoteFormatTest.java index 90d4472..e04d195 100644 --- a/test/jalview/ws/dbsources/RemoteFormatTest.java +++ b/test/jalview/ws/dbsources/RemoteFormatTest.java @@ -51,7 +51,7 @@ public class RemoteFormatTest Cache.applicationProperties.setProperty("ADD_SS_ANN", Boolean.TRUE.toString()); - sf = new SequenceFetcher(false); + sf = new SequenceFetcher(); } @DataProvider(name = "AccessionData") @@ -92,7 +92,7 @@ public class RemoteFormatTest @Test(groups = { "Network" }) public void testUniprotFreeTextSearch() throws Exception { - List wantedFields = new ArrayList(); + List wantedFields = new ArrayList<>(); FTSRestClientI client = UniProtFTSRestClient.getInstance(); wantedFields.add(client.getDataColumnByNameOrCode("id")); wantedFields.add(client.getDataColumnByNameOrCode("entry name")); diff --git a/test/jalview/ws/seqfetcher/DasSequenceFetcher.java b/test/jalview/ws/seqfetcher/DasSequenceFetcher.java deleted file mode 100644 index f1dafcb..0000000 --- a/test/jalview/ws/seqfetcher/DasSequenceFetcher.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ -package jalview.ws.seqfetcher; - -import static org.testng.Assert.assertTrue; - -import jalview.bin.Cache; -import jalview.gui.JvOptionPane; - -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -public class DasSequenceFetcher -{ - - @BeforeClass(alwaysRun = true) - public void setUpJvOptionPane() - { - JvOptionPane.setInteractiveMode(false); - JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); - } - - @Test(groups = { "Network" }) - public void testDasRegistryContact() - { - Cache.getDasSourceRegistry().refreshSources(); - assertTrue(Cache.getDasSourceRegistry().getSources().isEmpty(), - "Expected to find no DAS sources at the registry. Check config."); - } - -}