/* OrthologPanel.java * This file is part of Artemis * * Copyright (C) 2007 Genome Research Limited * * This program 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 2 * of the License, or (at your option) any later version. * * This program 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 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/genebuilder/ortholog/MatchPanel.java,v 1.31 2009-05-27 15:00:10 tjc Exp $ */ package uk.ac.sanger.artemis.components.genebuilder.ortholog; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Vector; import javax.swing.Box; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTable; import javax.swing.JTextField; import org.gmod.schema.cv.CvTerm; import org.gmod.schema.sequence.FeatureCvTerm; import uk.ac.sanger.artemis.Entry; import uk.ac.sanger.artemis.FeatureChangeEvent; import uk.ac.sanger.artemis.FeatureChangeListener; import uk.ac.sanger.artemis.Feature; import uk.ac.sanger.artemis.FeatureVector; import uk.ac.sanger.artemis.SimpleEntryGroup; import uk.ac.sanger.artemis.io.DatabaseDocumentEntry; import uk.ac.sanger.artemis.io.DocumentEntry; import uk.ac.sanger.artemis.io.EntryInformationException; import uk.ac.sanger.artemis.io.GFFStreamFeature; import uk.ac.sanger.artemis.io.PartialSequence; import uk.ac.sanger.artemis.io.Qualifier; import uk.ac.sanger.artemis.io.QualifierLazyLoading; import uk.ac.sanger.artemis.io.QualifierVector; import uk.ac.sanger.artemis.util.DatabaseDocument; import uk.ac.sanger.artemis.util.ReadOnlyException; import uk.ac.sanger.artemis.util.StringVector; import uk.ac.sanger.artemis.chado.ChadoTransactionManager; import uk.ac.sanger.artemis.components.SwingWorker; import uk.ac.sanger.artemis.components.genebuilder.GeneEdit; import uk.ac.sanger.artemis.components.genebuilder.GeneEditorPanel; import uk.ac.sanger.artemis.components.genebuilder.GeneUtils; import uk.ac.sanger.artemis.components.genebuilder.JExtendedComboBox; /** * For similarity, orthologue, paralogue qualifiers */ public class MatchPanel extends JPanel implements FeatureChangeListener { private static final long serialVersionUID = 1L; private QualifierVector matchQualifiers; private static Vector databases; private SimilarityTable similarityTable; private OrthoParalogTable orthoparaLogTable; private OrthoParalogTable clusterTable; private Vector editableComponents; private JButton hide_show_ortho; private JButton hide_show_cluster; private JButton hide_show_sim; public static String ORTHOLOG = "orthologous_to"; public static String PARALOG = "paralogous_to"; //public static String CLUSTER = "cluster"; public static String SIMILARITY = "similarity"; private static String[] SO_CLUSTER_NAMES = { ORTHOLOG, PARALOG, // CLUSTER, SIMILARITY }; private DocumentEntry entry; // used to test if match panel has contents private boolean empty = true; private static boolean LOADING = false; private Feature feature; public MatchPanel(final Feature feature, final DocumentEntry entry) { super(new BorderLayout()); this.entry = entry; this.feature = feature; } /** * Return true if this is a Ortholog qualifier * @param qualifier * @return */ public static boolean isMatchTag(final Qualifier qualifier) { return isMatchTag(qualifier.getName()); } /** * Return true if this is a match qualifier * @param qualifierName * @return */ public static boolean isMatchTag(final String qualifierName) { for(int i=0; i 0) { addHideShowButton(orthoparaLogTable.getTable(), hide_show_ortho); xBox.add(hide_show_ortho); editableComponents.add(orthoparaLogTable); Box horizontalBox = Box.createHorizontalBox(); horizontalBox.add(orthoparaLogTable.getTable().getTableHeader()); horizontalBox.add(Box.createHorizontalGlue()); matchVerticalBox.add(horizontalBox); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(orthoparaLogTable.getTable()); horizontalBox.add(Box.createHorizontalGlue()); matchVerticalBox.add(horizontalBox); } } // // clusters // if(OrthoParalogTable.hasCluster(orthoQualifier, paraQualifier, (GFFStreamFeature)feature.getEmblFeature())) { empty = false; if(OrthoParalogTable.hasOrthoParlaog(orthoQualifier, paraQualifier, (GFFStreamFeature)feature.getEmblFeature())) GeneEditorPanel.addLightSeparator(matchVerticalBox); if(hide_show_cluster == null) hide_show_cluster = new JButton("-"); clusterTable = new OrthoParalogTable(doc, orthoQualifier, paraQualifier, feature, true); addHideShowButton(clusterTable.getTable(), hide_show_cluster); Box horizontalBox = Box.createHorizontalBox(); horizontalBox.add(Box.createHorizontalGlue()); horizontalBox.add(hide_show_cluster); matchVerticalBox.add(horizontalBox); editableComponents.add(clusterTable); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(clusterTable.getTable().getTableHeader()); horizontalBox.add(Box.createHorizontalGlue()); matchVerticalBox.add(horizontalBox); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(clusterTable.getTable()); horizontalBox.add(Box.createHorizontalGlue()); matchVerticalBox.add(horizontalBox); } } // // similarity GeneEditorPanel.addLightSeparator(matchVerticalBox); /* JButton addSimButton = new JButton("ADD SIMILARITY"); addSimButton.setOpaque(false); addSimButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JTextField accession = new JTextField(15); Box yBox = Box.createHorizontalBox(); yBox.add(accession); int select = JOptionPane.showConfirmDialog(null, yBox, "Add Similarity", JOptionPane.OK_CANCEL_OPTION); if(select == JOptionPane.CANCEL_OPTION) return; add(SIMILARITY, accession.getText().trim(), feature); } }); */ if(simQualifier != null) { xBox = Box.createHorizontalBox(); final JLabel simLabel = new JLabel("Similarity:"); simLabel.setFont( simLabel.getFont().deriveFont(Font.BOLD )); xBox.add(simLabel); xBox.add(Box.createHorizontalGlue()); matchVerticalBox.add(xBox); empty = false; if(simQualifier instanceof QualifierLazyLoading) ((QualifierLazyLoading)simQualifier).setForceLoad(true); similarityTable = new SimilarityTable(simQualifier,doc); if(hide_show_sim == null) hide_show_sim = new JButton("-"); addHideShowButton(similarityTable.getTable(), hide_show_sim); editableComponents.add(similarityTable); xBox.add(similarityTable.getInfoLevelButton()); xBox.add(hide_show_sim); matchVerticalBox.add(xBox); matchVerticalBox.add(similarityTable.getTable().getTableHeader()); matchVerticalBox.add(similarityTable.getTable()); } return matchVerticalBox; } /** * Add an ortholog or paralog to the table * @param feature */ private void addOrthoParalog(final Feature feature, final DatabaseDocument doc) { JExtendedComboBox dbs = new JExtendedComboBox(databases); JTextField geneField = new JTextField(15); JRadioButton ortho = new JRadioButton(ORTHOLOG, true); JRadioButton para = new JRadioButton(PARALOG, false); ButtonGroup group = new ButtonGroup(); group.add(ortho); group.add(para); Box xBox = Box.createVerticalBox(); Box yBoxRef = Box.createHorizontalBox(); yBoxRef.add(dbs); yBoxRef.add(geneField); yBoxRef.add(Box.createHorizontalGlue()); xBox.add(yBoxRef); Box yBoxType = Box.createHorizontalBox(); yBoxType.add(ortho); yBoxType.add(para); yBoxType.add(Box.createHorizontalGlue()); xBox.add(yBoxType); boolean found = false; JComboBox polypepList = null; String uniqueName = null; String label = "Add Ortholog/Paralog"; int select; Vector polypeptides = new Vector(); while(!found) { select = JOptionPane.showConfirmDialog(null, xBox, label, JOptionPane.OK_CANCEL_OPTION); if(select == JOptionPane.CANCEL_OPTION) return; try { uniqueName = geneField.getText().trim(); polypeptides = doc.getPolypeptideFeatures(uniqueName); if(polypeptides == null || polypeptides.size() == 0) polypeptides = doc.getPartOfFeatures(uniqueName); final Vector polypeptideNames = new Vector(); for(int i=0; i -1) { matchQualifiers.remove(index); matchQualifiers.add(index, qualifier); } else matchQualifiers.add(qualifier); removeAll(); add(createMatchQualifiersComponent(feature)); repaint(); revalidate(); } /** * Get the latest (edited) controlled vocab qualifiers * @return */ public QualifierVector getMatchQualifiers() { if(editableComponents != null) { for(int i=0; i getGeneNameList() { return getGeneNameList(false); } /** * Get a list of the gene names from the ortholog table or cluster table. * @param cluster if true then retrieve names from the cluster table * @return */ public List getGeneNameList(boolean cluster) { final OrthoParalogTable table; if(orthoparaLogTable == null || orthoparaLogTable.getTable().getRowCount()<1 || cluster) { if(clusterTable == null || clusterTable.getTable().getRowCount()<1) return null; table = clusterTable; } else table = orthoparaLogTable; int columnIndex = table.getColumnIndex(OrthoParalogTable.GENE_COL); List geneNames = new Vector(table.getTable().getRowCount()); for(int row=0; row