Skip to content
Snippets Groups Projects
Commit ec0bfc5c authored by tjc's avatar tjc
Browse files

use organism schema

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@3835 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent aef96652
No related branches found
No related tags found
No related merge requests found
......@@ -44,35 +44,42 @@ import uk.ac.sanger.artemis.io.InvalidKeyException;
import uk.ac.sanger.artemis.io.EntryInformationException;
/**
*
* This is an EntrySource that reads Entry objects from a relational
* database.
*
**/
*
* This is an EntrySource that reads Entry objects from a relational database.
*
*/
public class DatabaseEntrySource implements EntrySource
{
private String location;
private JPasswordField pfield;
private Hashtable entries;
private Hashtable schemas;
private boolean splitGFFEntry;
/**
* Create a new DatabaseEntrySource.
**/
public DatabaseEntrySource()
* Create a new DatabaseEntrySource.
*/
public DatabaseEntrySource()
{
}
/**
* @param bases The Bases object to pass to the Entry constructor.
* @param show_progress If true a InputStreamProgressDialog will be shown
* while loading. (Not implemented)
* @exception OutOfRangeException Thrown if one of the features in
* the Entry is out of range of the Bases object.
* @return null if and only if the read is cancelled by the user or if the
* read fails.
**/
* @param bases
* The Bases object to pass to the Entry constructor.
* @param show_progress
* If true a InputStreamProgressDialog will be shown while loading.
* (Not implemented)
* @exception OutOfRangeException
* Thrown if one of the features in the Entry is out of range of
* the Bases object.
* @return null if and only if the read is cancelled by the user or if the
* read fails.
*/
public Entry getEntry(final Bases bases, final boolean show_progress)
throws OutOfRangeException, IOException
{
......@@ -86,49 +93,51 @@ public class DatabaseEntrySource implements EntrySource
}
/**
* Get an Entry object from this source.
* @param id Feature ID to read in.
* @exception OutOfRangeException Thrown if one of the features in
* the Entry is out of range of the Bases object.
* @exception NoSequenceException Thrown if the entry that we read has no
* sequence.
* @return null if and only if the user cancels the read or if the read
* fails.
**/
public Entry getEntry(String id, InputStreamProgressListener progress_listener)
* Get an Entry object from this source.
*
* @param id
* Feature ID to read in.
* @exception OutOfRangeException
* Thrown if one of the features in the Entry is out of range of
* the Bases object.
* @exception NoSequenceException
* Thrown if the entry that we read has no sequence.
* @return null if and only if the user cancels the read or if the read fails.
*/
public Entry getEntry(String id, String schema,
InputStreamProgressListener progress_listener)
throws OutOfRangeException, NoSequenceException, IOException
{
return makeFromID(null,id,false,progress_listener);
return makeFromID(null, id, schema, false, progress_listener);
}
/**
* Returns true if and only if this EntrySource always returns "full"
* entries. ie. entries that contain features and sequence.
**/
* Returns true if and only if this EntrySource always returns "full" entries.
* ie. entries that contain features and sequence.
*/
public boolean isFullEntrySource()
{
return true;
}
/**
* Return the name of this source (for display to the user in menus).
**/
* Return the name of this source (for display to the user in menus).
*/
public String getSourceName()
{
return "Database";
}
/**
*
* Set the database location as:
* jdbc:postgresql://localhost:13001/chadoCVS?user=es2
*
*/
*
* Set the database location as:
* jdbc:postgresql://localhost:13001/chadoCVS?user=es2
*
*/
protected boolean setLocation(final boolean prompt_user)
{
Container bacross = new Container();
bacross.setLayout(new GridLayout(6,2,5,5));
bacross.setLayout(new GridLayout(6, 2, 5, 5));
JLabel lServer = new JLabel("Server : ");
bacross.add(lServer);
......@@ -162,97 +171,95 @@ public class DatabaseEntrySource implements EntrySource
int index;
if((index = db_url.indexOf(":")) > -1)
{
inServer.setText(db_url.substring(0,index));
inServer.setText(db_url.substring(0, index));
int index2;
if((index2 = db_url.indexOf("/")) > -1)
{
inPort.setText(db_url.substring(index+1,index2));
inPort.setText(db_url.substring(index + 1, index2));
int index3;
if((index3 = db_url.indexOf("?")) > -1)
{
inDB.setText(db_url.substring(index2+1,index3));
inUser.setText(db_url.substring(index3+1));
/*
if(!prompt_user)
{
location = "jdbc:postgresql://"
+inServer.getText().trim()+ ":"
+inPort.getText().trim()+ "/"
+inDB.getText().trim()+ "?user="
+inUser.getText().trim();
return true;
}
*/
inDB.setText(db_url.substring(index2 + 1, index3));
inUser.setText(db_url.substring(index3 + 1));
/*
* if(!prompt_user) { location = "jdbc:postgresql://"
* +inServer.getText().trim()+ ":" +inPort.getText().trim()+ "/"
* +inDB.getText().trim()+ "?user=" +inUser.getText().trim(); return
* true; }
*/
}
}
}
}
int n = JOptionPane.showConfirmDialog(null, bacross,
"Enter Database Address",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
"Enter Database Address",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(n == JOptionPane.CANCEL_OPTION)
return false;
location = "jdbc:postgresql://"
+inServer.getText().trim()+ ":"
+inPort.getText().trim()+ "/"
+inDB.getText().trim()+ "?user="
+inUser.getText().trim();
location = "jdbc:postgresql://" +
inServer.getText().trim() + ":" +
inPort.getText().trim() + "/" +
inDB.getText().trim() + "?user=" +
inUser.getText().trim();
return true;
return true;
}
/**
*
* Given the entry name get the seq feature_id
*
*/
*
* Given the entry name get the seq feature_id
*
*/
protected String getEntryID(String name)
{
return (String)entries.get(name);
}
/**
*
* Create database organism JTree.
*
*/
*
* Create database organism JTree.
*
*/
protected JTree getDatabaseTree()
{
DatabaseDocument doc = new DatabaseDocument(location, pfield);
entries = doc.getDatabaseEntries();
Vector organism = doc.getOrganism();
schemas = doc.getSchemaEntries();
DefaultMutableTreeNode top =
new DefaultMutableTreeNode("PSU Organism List");
createNodes(top,organism,entries);
DefaultMutableTreeNode top = new DefaultMutableTreeNode("PSU Organism List");
createNodes(top, organism, entries);
final JTree tree = new JTree(top);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
return tree;
}
/**
*
* Get DefaultMutableTreeNode of selected node
* @return node that is currently selected
*
*/
*
* Get DefaultMutableTreeNode of selected node
*
* @return node that is currently selected
*
*/
protected String getSelectedNode(JTree tree)
{
TreePath path = tree.getLeadSelectionPath();
if(path == null)
if (path == null)
return null;
DefaultMutableTreeNode seq_node = (DefaultMutableTreeNode)path.getLastPathComponent();
DefaultMutableTreeNode type_node = (DefaultMutableTreeNode)seq_node.getParent();
DefaultMutableTreeNode org_node = (DefaultMutableTreeNode)type_node.getParent();
DefaultMutableTreeNode seq_node =
(DefaultMutableTreeNode)path.getLastPathComponent();
DefaultMutableTreeNode type_node =
(DefaultMutableTreeNode)seq_node.getParent();
DefaultMutableTreeNode org_node =
(DefaultMutableTreeNode)type_node.getParent();
return (String)org_node.getUserObject() + " - " +
(String)type_node.getUserObject() + " - " +
......@@ -260,13 +267,44 @@ public class DatabaseEntrySource implements EntrySource
}
/**
*
* Create the nodes of the organism JTree
* @param top root node
* @param org organism collection
* @param organism sequences collection
*
*/
*
* Get Organism of selected node
*
* @return name of Organism that is top level of selected node
*
*/
protected String getSchemaOfSelectedNode(JTree tree)
{
TreePath path = tree.getLeadSelectionPath();
if(path == null)
return null;
DefaultMutableTreeNode seq_node =
(DefaultMutableTreeNode)path.getLastPathComponent();
DefaultMutableTreeNode type_node =
(DefaultMutableTreeNode)seq_node.getParent();
DefaultMutableTreeNode org_node =
(DefaultMutableTreeNode)type_node.getParent();
String org = (String)org_node.getUserObject();
if(schemas.containsKey(org))
return (String) schemas.get(org);
else
return null;
}
/**
*
* Create the nodes of the organism JTree
*
* @param top
* root node
* @param org
* organism collection
* @param organism
* sequences collection
*
*/
private void createNodes(DefaultMutableTreeNode top, Vector org,
Hashtable organism)
{
......@@ -280,33 +318,33 @@ public class DatabaseEntrySource implements EntrySource
Arrays.sort(v_organism);
while(enum_org.hasMoreElements())
{
{
String name = (String)enum_org.nextElement();
org_node = new DefaultMutableTreeNode(name);
top.add(org_node);
Hashtable seq_type_node = new Hashtable();
for(int i=0; i<v_organism_size; i++)
for(int i = 0; i < v_organism_size; i++)
{
String seq_name = (String)v_organism[i];
if(seq_name.startsWith(name))
{
int ind1 = seq_name.indexOf( "- ");
int ind1 = seq_name.indexOf("- ");
int ind2 = seq_name.lastIndexOf("- ");
String type = seq_name.substring(ind1+2,ind2-1);
seq_name = seq_name.substring(ind2+2);
String type = seq_name.substring(ind1 + 2, ind2 - 1);
seq_name = seq_name.substring(ind2 + 2);
if(!seq_type_node.containsKey(type))
{
{
typ_node = new DefaultMutableTreeNode(type);
seq_type_node.put(type,typ_node);
org_node.add(typ_node);
seq_type_node.put(type, typ_node);
org_node.add(typ_node);
}
else
typ_node= (DefaultMutableTreeNode)seq_type_node.get(type);
typ_node = (DefaultMutableTreeNode) seq_type_node.get(type);
seq_node = new DefaultMutableTreeNode(seq_name);
typ_node.add(seq_node);
}
......@@ -320,36 +358,42 @@ public class DatabaseEntrySource implements EntrySource
}
/**
*
* Given an accession number and the handle of an EMBL corba server, this
* method will ask the user (using a TextRequester) for the id of a entry
* in the server and will then attempt to get it.
* @param bases If this is null a new Bases object will be created for the
* Entry once it has been read from the server. If not null then it will
* be passed to the Entry constructor.
* @param corba_id The id of the entry in the database
* @param read_only true if and only if a read-only Entry should be created
* (some are always read only).
* @exception OutOfRangeException Thrown if one of the features in
* the Entry is out of range of the Bases object.
**/
protected Entry makeFromID(final Bases bases,
final String id,
final boolean read_only,
*
* Given an accession number and the handle of an EMBL corba server, this
* method will ask the user (using a TextRequester) for the id of a entry in
* the server and will then attempt to get it.
*
* @param bases
* If this is null a new Bases object will be created for the Entry
* once it has been read from the server. If not null then it will be
* passed to the Entry constructor.
* @param id
* The id of the entry in the database
* @param schema
* The schema of the entry in the database
* @param read_only
* true if and only if a read-only Entry should be created (some are
* always read only).
* @exception OutOfRangeException
* Thrown if one of the features in the Entry is out of range of
* the Bases object.
*/
protected Entry makeFromID(final Bases bases, final String id,
final String schema, final boolean read_only,
InputStreamProgressListener progress_listener)
throws OutOfRangeException, IOException
throws OutOfRangeException, IOException
{
try
try
{
DatabaseDocumentEntry db_entry = null;
if(read_only)
if(read_only)
{
}
else
}
else
{
DatabaseDocument doc = new DatabaseDocument(location, pfield, id,
splitGFFEntry, progress_listener);
DatabaseDocument doc = new DatabaseDocument(location, pfield, id,
schema, splitGFFEntry, progress_listener);
db_entry = new DatabaseDocumentEntry(doc);
}
......@@ -357,61 +401,60 @@ public class DatabaseEntrySource implements EntrySource
if(bases == null)
{
if(db_entry.getSequence() == null)
if (db_entry.getSequence() == null)
{
JOptionPane.showMessageDialog(null,
"The selected entry contains no sequence: " + id,
"No Sequence",
JOptionPane.ERROR_MESSAGE);
"The selected entry contains no sequence: " + id, "No Sequence",
JOptionPane.ERROR_MESSAGE);
return null;
return null;
}
real_bases = new Bases(db_entry.getSequence());
}
}
else
real_bases = bases;
return new Entry(real_bases, db_entry);
}
catch(InvalidKeyException e)
}
catch(InvalidKeyException e)
{
JOptionPane.showMessageDialog(null,
"Unexpected error while accessing " + id + ": " + e,
"Invalid Key",
JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,
"Unexpected error while accessing " +
id + ": " + e,
"Invalid Key", JOptionPane.ERROR_MESSAGE);
}
catch(EntryInformationException e)
catch(EntryInformationException e)
{
JOptionPane.showMessageDialog(null,
"Failed to get entry: " + e,
"Entry Information Exception",
JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,
"Failed to get entry: " + e,
"Entry Information Exception",
JOptionPane.ERROR_MESSAGE);
}
return null;
}
protected DatabaseDocumentEntry[]
makeFromGff(final DatabaseDocument doc, String id)
throws OutOfRangeException, IOException
protected DatabaseDocumentEntry[] makeFromGff(final DatabaseDocument doc,
String id, String schema)
throws OutOfRangeException, IOException
{
DatabaseDocumentEntry[] db_entry = null;
try
{
DatabaseDocument[] new_docs = doc.getGffDocuments(location, id);
DatabaseDocument[] new_docs = doc.getGffDocuments(location, id, schema);
db_entry = new DatabaseDocumentEntry[new_docs.length];
for(int i=0; i<new_docs.length; i++)
for(int i = 0; i < new_docs.length; i++)
db_entry[i] = new DatabaseDocumentEntry(new_docs[i]);
}
catch(EntryInformationException e)
catch (EntryInformationException e)
{
JOptionPane.showMessageDialog(null,
"Failed to get entry: " + e,
"Entry Information Exception",
JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,
"Failed to get entry: " + e,
"Entry Information Exception",
JOptionPane.ERROR_MESSAGE);
}
return db_entry;
......
......@@ -20,7 +20,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/DatabaseJFrame.java,v 1.6 2005-11-08 20:12:27 tjc Exp $
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/DatabaseJFrame.java,v 1.7 2005-11-22 11:02:31 tjc Exp $
*/
package uk.ac.sanger.artemis.components;
......@@ -56,25 +56,27 @@ import java.awt.Cursor;
import java.awt.FontMetrics;
import java.io.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
public class DatabaseJFrame extends JFrame
{
private JLabel status_line = new JLabel("");
private boolean splitGFFEntry = true;
public DatabaseJFrame(final DatabaseEntrySource entry_source,
final ArtemisMain art_main)
final ArtemisMain art_main)
{
super("PSU Organism");
final JTree tree = entry_source.getDatabaseTree();
//Listen for when the selection changes.
// Listen for when the selection changes.
MouseListener mouseListener = new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if(e.getClickCount() == 2 && !e.isPopupTrigger())
showSelected(entry_source,tree,art_main);
showSelected(entry_source, tree, art_main);
}
};
tree.addMouseListener(mouseListener);
......@@ -82,24 +84,25 @@ public class DatabaseJFrame extends JFrame
JScrollPane scroll = new JScrollPane(tree);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension dim_frame = new Dimension(screen.width*2 / 10, screen.height*6 / 10);
Dimension dim_frame = new Dimension(screen.width * 2 / 10,
screen.height * 6 / 10);
scroll.setPreferredSize(dim_frame);
setJMenuBar(makeMenuBar(entry_source,tree,art_main));
setJMenuBar(makeMenuBar(entry_source, tree, art_main));
JPanel pane = (JPanel)getContentPane();
pane.add(scroll, BorderLayout.CENTER);
final FontMetrics fm =
this.getFontMetrics(status_line.getFont());
final FontMetrics fm = this.getFontMetrics(status_line.getFont());
final int font_height = fm.getHeight()+10;
final int font_height = fm.getHeight() + 10;
status_line.setMinimumSize(new Dimension(100, font_height));
status_line.setPreferredSize(new Dimension(100, font_height));
Border loweredbevel = BorderFactory.createLoweredBevelBorder();
Border raisedbevel = BorderFactory.createRaisedBevelBorder();
Border compound = BorderFactory.createCompoundBorder(raisedbevel,loweredbevel);
Border compound = BorderFactory.createCompoundBorder(raisedbevel,
loweredbevel);
status_line.setBorder(compound);
pane.add(status_line, BorderLayout.SOUTH);
......@@ -107,14 +110,13 @@ public class DatabaseJFrame extends JFrame
Utilities.rightJustifyFrame(this);
}
/**
*
* Show the selected sequence in the tree
*
*/
*
* Show the selected sequence in the tree
*
*/
private void showSelected(final DatabaseEntrySource entry_source,
final JTree tree, final ArtemisMain art_main)
final JTree tree, final ArtemisMain art_main)
{
Cursor cbusy = new Cursor(Cursor.WAIT_CURSOR);
Cursor cdone = new Cursor(Cursor.DEFAULT_CURSOR);
......@@ -124,23 +126,23 @@ public class DatabaseJFrame extends JFrame
try
{
node_name = entry_source.getSelectedNode(tree);
String id = entry_source.getEntryID(node_name);
String id = entry_source.getEntryID(node_name);
if(id != null)
getEntryEditFromDatabase(id, entry_source, tree, art_main);
}
catch(NullPointerException npe){}
catch(NullPointerException npe)
{
}
}
/**
*
* Retrieve a database entry.
*
*/
*
* Retrieve a database entry.
*
*/
private void getEntryEditFromDatabase(final String id,
final DatabaseEntrySource entry_source,
final JTree tree,
final ArtemisMain art_main)
final DatabaseEntrySource entry_source, final JTree tree,
final ArtemisMain art_main)
{
SwingWorker entryWorker = new SwingWorker()
{
......@@ -153,11 +155,15 @@ public class DatabaseJFrame extends JFrame
tree.setCursor(cbusy);
try
{
final InputStreamProgressListener progress_listener =
art_main.getInputStreamProgressListener();
final InputStreamProgressListener progress_listener =
art_main.getInputStreamProgressListener();
entry_source.setSplitGFF(splitGFFEntry);
final Entry entry = entry_source.getEntry(id, progress_listener);
String schema = entry_source.getSchemaOfSelectedNode(tree);
final Entry entry = entry_source.getEntry(id, schema,
progress_listener);
if(entry == null)
{
tree.setCursor(cdone);
......@@ -170,16 +176,18 @@ public class DatabaseJFrame extends JFrame
// add gff entries
if(splitGFFEntry)
{
DatabaseDocumentEntry db_entry = (DatabaseDocumentEntry)entry.getEMBLEntry();
final DatabaseDocumentEntry[] entries =
entry_source.makeFromGff((DatabaseDocument)db_entry.getDocument(), id);
for(int i=0; i< entries.length; i++)
DatabaseDocumentEntry db_entry =
(DatabaseDocumentEntry)entry.getEMBLEntry();
final DatabaseDocumentEntry[] entries = entry_source.makeFromGff(
(DatabaseDocument)db_entry.getDocument(), id, schema);
for(int i = 0; i < entries.length; i++)
{
if(entries[i] == null)
continue;
final Entry new_entry = new Entry(new_entry_edit.getEntryGroup().getBases(), entries[i]);
final Entry new_entry = new Entry(new_entry_edit.getEntryGroup().getBases(),
entries[i]);
new_entry_edit.getEntryGroup().add(new_entry);
}
}
......@@ -189,9 +197,9 @@ public class DatabaseJFrame extends JFrame
}
catch(OutOfRangeException e)
{
new MessageDialog(art_main, "read failed: one of the features in " +
" the entry has an out of range " +
"location: " + e.getMessage());
new MessageDialog(art_main, "read failed: one of the features in "
+ " the entry has an out of range " + "location: "
+ e.getMessage());
}
catch(NoSequenceException e)
{
......@@ -211,7 +219,7 @@ public class DatabaseJFrame extends JFrame
}
private JMenuBar makeMenuBar(final DatabaseEntrySource entry_source,
final JTree tree, final ArtemisMain art_main)
final JTree tree, final ArtemisMain art_main)
{
JMenuBar mBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
......@@ -222,7 +230,7 @@ public class DatabaseJFrame extends JFrame
{
public void actionPerformed(ActionEvent e)
{
showSelected(entry_source,tree,art_main);
showSelected(entry_source, tree, art_main);
}
});
fileMenu.add(fileShow);
......@@ -241,8 +249,8 @@ public class DatabaseJFrame extends JFrame
JMenu optionMenu = new JMenu("Options");
mBar.add(optionMenu);
final JCheckBoxMenuItem splitGFF = new JCheckBoxMenuItem("Split GFF into entries",
splitGFFEntry);
final JCheckBoxMenuItem splitGFF = new JCheckBoxMenuItem(
"Split GFF into entries", splitGFFEntry);
splitGFF.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment