Newer
Older
tjc
committed
* created: 2009
tjc
committed
* Copyright (C) 2009 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.
*
*/
package uk.ac.sanger.artemis.components;
tjc
committed
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Enumeration;
import java.util.Hashtable;
tjc
committed
import java.util.Iterator;
tjc
committed
import java.util.Set;
tjc
committed
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
tjc
committed
import javax.swing.JTextArea;
tjc
committed
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import uk.ac.sanger.artemis.EntryGroup;
import uk.ac.sanger.artemis.Feature;
import uk.ac.sanger.artemis.FeaturePredicate;
import uk.ac.sanger.artemis.FeatureVector;
import uk.ac.sanger.artemis.SimpleEntryGroup;
import uk.ac.sanger.artemis.chado.ChadoTransactionManager;
import uk.ac.sanger.artemis.components.genebuilder.GeneEdit;
import uk.ac.sanger.artemis.components.genebuilder.GeneUtils;
import uk.ac.sanger.artemis.io.ChadoCanonicalGene;
import uk.ac.sanger.artemis.io.InvalidRelationException;
import uk.ac.sanger.artemis.io.Qualifier;
import uk.ac.sanger.artemis.io.QualifierVector;
import uk.ac.sanger.artemis.util.StringVector;
{
private static final long serialVersionUID = 1L;
private static String[] NON_TRANSFERABLE_QUALIFIERS =
{
"ID",
"feature_id",
"Derives_from",
"feature_relationship_rank",
"Parent",
"isObsolete",
"isFminPartial",
"isFmaxPartial",
"cytoplasm_location",
"non_cytoplasm_location",
"PlasmoAP_score",
"polypeptide_domain",
"transmembrane",
tjc
committed
private static org.apache.log4j.Logger logger4j =
org.apache.log4j.Logger.getLogger(TransferAnnotationTool.class);
protected static Color STEEL_BLUE = new Color(25, 25, 112);
tjc
committed
/**
* Tool for transferring annotation from one feature to other feature(s)
* @param feature
* @param entryGroup
* @param geneNames
*/
tjc
committed
final EntryGroup entryGroup,
final List geneNames)
{
super("Transfer Annotation Tool :: "
+ feature.getIDString());
FlowLayout flow = new FlowLayout(FlowLayout.LEFT);
JPanel panel = new JPanel(flow);
JPanel pane = new JPanel(new GridBagLayout());
JScrollPane jsp = new JScrollPane(panel);
tjc
committed
panel.setBackground(Color.white);
pane.setBackground(Color.white);
panel.add(pane);
JPanel framePanel = (JPanel)getContentPane();
framePanel.add(jsp, BorderLayout.CENTER);
framePanel.setPreferredSize(new Dimension(600,600));
tjc
committed
final Vector geneNameCheckBoxes = new Vector();
tjc
committed
final Vector qualifierPanels = new Vector();
tjc
committed
tjc
committed
addMainPanel(feature, pane, qualifierPanels,
tjc
committed
geneNameCheckBoxes, geneNames);
tjc
committed
addBottomButtons(qualifierPanels, geneNameCheckBoxes,
framePanel, entryGroup);
tjc
committed
pack();
setVisible(true);
}
/**
* Construct the panel for setting up the gene list and the
* list of qualifiers to transfer.
* @param feature
* @param pane
* @param qualifierCheckBoxes
* @param geneNameCheckBoxes
* @param geneNames
*/
private void addMainPanel(final Feature feature,
final JPanel pane,
tjc
committed
final Vector qualifierPanels,
tjc
committed
final Vector geneNameCheckBoxes,
final List geneNames)
{
GridBagConstraints c = new GridBagConstraints();
int nrows = 0;
c.anchor = GridBagConstraints.NORTHWEST;
c.gridx = 2;
tjc
committed
tjc
committed
JLabel geneLabel = new JLabel("Qualifier(s)");
geneLabel.setFont(geneLabel.getFont().deriveFont(Font.BOLD));
pane.add(geneLabel, c);
tjc
committed
c.gridy = 0;
JLabel label = new JLabel("Gene List");
label.setFont(label.getFont().deriveFont(Font.BOLD));
pane.add(label, c);
tjc
committed
c.gridx = 2;
c.gridy = ++nrows;
c.anchor = GridBagConstraints.WEST;
tjc
committed
addQualifierPanel(feature, qualifierPanels, c, nrows, pane);
nrows+=2;
if(feature.getEmblFeature() instanceof GFFStreamFeature)
tjc
committed
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
GFFStreamFeature gffFeature =
((GFFStreamFeature) feature.getEmblFeature());
if (gffFeature.getChadoGene() != null)
{
String id = GeneUtils.getUniqueName(gffFeature);
ChadoCanonicalGene chadoGene = gffFeature.getChadoGene();
Feature gene = (Feature) chadoGene.getGene().getUserData();
if(!id.equals( GeneUtils.getUniqueName(((GFFStreamFeature)chadoGene.getGene())) ))
addQualifierPanel(gene, qualifierPanels, c, nrows, pane);
nrows+=2;
String transcriptName =
chadoGene.getTranscriptFromName(GeneUtils.getUniqueName(gffFeature));
if(transcriptName != null)
{
GFFStreamFeature transcript =
(GFFStreamFeature) chadoGene.getFeatureFromId(transcriptName);
addQualifierPanel((Feature)transcript.getUserData(),
qualifierPanels, c, nrows, pane);
nrows+=2;
Set children = chadoGene.getChildren(transcript);
Iterator it = children.iterator();
while(it.hasNext())
{
GFFStreamFeature kid = (GFFStreamFeature)it.next();
if(id.equals( GeneUtils.getUniqueName(((GFFStreamFeature)kid)) ))
continue;
addQualifierPanel((Feature)kid.getUserData(), qualifierPanels,
c, nrows, pane);
nrows+=2;
}
}
}
tjc
committed
c.gridheight = nrows;
c.fill = GridBagConstraints.BOTH;
final Box geneNameBox = Box.createVerticalBox();
pane.add(geneNameBox, c);
for(int i = 0; i < geneNames.size(); i++)
{
JCheckBox cb = new JCheckBox((String) geneNames.get(i),true);
geneNameBox.add(cb);
geneNameCheckBoxes.add(cb);
}
c.gridx = 2;
final JButton toggle = new JButton("Toggle");
toggle.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tjc
committed
for(int i=0; i<qualifierPanels.size(); i++)
tjc
committed
QualifierPanel qP = (QualifierPanel)qualifierPanels.get(i);
Enumeration enumQualifiers = qP.getQualifierCheckBoxes().keys();
while(enumQualifiers.hasMoreElements())
{
JCheckBox cb = (JCheckBox) enumQualifiers.nextElement();
cb.setSelected(!cb.isSelected());
}
tjc
committed
Box xBox = Box.createHorizontalBox();
final JButton toggleGeneList = new JButton("Toggle");
toggleGeneList.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
for(int i = 0; i < geneNameCheckBoxes.size(); i++)
{
JCheckBox cb = (JCheckBox) geneNameCheckBoxes.get(i);
cb.setSelected(!cb.isSelected());
}
}
});
tjc
committed
xBox.add(toggleGeneList);
tjc
committed
final JButton addGenes = new JButton("Add");
addGenes.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JTextArea geneNameTextArea = new JTextArea();
geneNameTextArea.setEditable(true);
JScrollPane jsp = new JScrollPane(geneNameTextArea);
int res = JOptionPane.showConfirmDialog(TransferAnnotationTool.this,
tjc
committed
JOptionPane.OK_CANCEL_OPTION);
if(res == JOptionPane.CANCEL_OPTION)
return;
String geneNames[] = geneNameTextArea.getText().split("\\s");
for(int i=0;i<geneNames.length; i++)
{
if(geneNames[i] == null || geneNames[i].equals(""))
continue;
JCheckBox cb = new JCheckBox(geneNames[i],true);
geneNameBox.add(cb);
geneNameCheckBoxes.add(cb);
}
pane.revalidate();
}
});
xBox.add(addGenes);
c.gridx = 0;
pane.add(xBox, c);
}
tjc
committed
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/**
* Add a panel to display a given features qualifiers.
* @param f
* @param qualifierPanels
* @param c
* @param nrows
* @param pane
*/
private void addQualifierPanel(Feature f,
Vector qualifierPanels,
GridBagConstraints c,
int nrows,
JPanel pane)
{
QualifierPanel qPanel = new QualifierPanel(f,f.getKey().getKeyString());
if(qPanel.nrows == 0)
return;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.WEST;
c.weightx = 100;
qualifierPanels.add(qPanel);
c.gridy = ++nrows;
JLabel l = new JLabel(f.getIDString());
l.setFont(l.getFont().deriveFont(Font.BOLD));
l.setForeground(STEEL_BLUE);
pane.add(l, c);
c.gridy = ++nrows;
pane.add(qPanel, c);
c.weightx = 0.d;
}
tjc
committed
/**
* Add panel for the transfer and close button.
* @param qualifierCheckBoxes
* @param geneNameCheckBoxes
* @param framePanel
* @param feature
* @param entryGroup
*/
tjc
committed
private void addBottomButtons(final Vector qualifierPanels,
tjc
committed
final Vector geneNameCheckBoxes,
tjc
committed
final JPanel framePanel,
tjc
committed
final EntryGroup entryGroup)
{
final JCheckBox sameKeyCheckBox = new JCheckBox("Add to feature of same key", true);
tjc
committed
final JCheckBox overwriteCheckBox = new JCheckBox("Overwrite", false);
overwriteCheckBox.setToolTipText("overwrite rather than append values");
Box buttonBox = Box.createHorizontalBox();
tjc
committed
transfer.setToolTipText("transfer annotation");
transfer.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tjc
committed
if(overwriteCheckBox.isSelected())
{
int res = JOptionPane.showConfirmDialog(TransferAnnotationTool.this,
"Overwrite selected annotation?",
"Overwrite", JOptionPane.OK_CANCEL_OPTION);
if(res == JOptionPane.CANCEL_OPTION)
return;
}
StringBuffer buff = new StringBuffer();
StringBuffer summary = new StringBuffer();
tjc
committed
for(int i = 0; i < qualifierPanels.size(); i++)
{
QualifierPanel qP = (QualifierPanel) qualifierPanels.get(i);
tjc
committed
geneNameCheckBoxes, qP.getFeature(), entryGroup,
sameKeyCheckBox.isSelected(),
overwriteCheckBox.isSelected(), buff, summary);
tjc
committed
}
if(buff.length() > 0)
logger4j.debug("TRANSFERRED ANNOTATION SUMMARY:\n"+buff.toString());
if(summary.length()>0)
{
final JTextArea list = new JTextArea(summary.toString());
final JScrollPane jsp = new JScrollPane(list);
jsp.setPreferredSize(new Dimension(300,200));
JOptionPane.showMessageDialog(
TransferAnnotationTool.this, jsp,
"Summary of Genes Changed",
JOptionPane.INFORMATION_MESSAGE);
}
Box yBox = Box.createVerticalBox();
yBox.add(transfer);
yBox.add(sameKeyCheckBox);
tjc
committed
yBox.add(overwriteCheckBox);
final JButton close = new JButton("CLOSE");
close.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
});
yBox = Box.createVerticalBox();
yBox.add(close);
yBox.add(Box.createVerticalGlue());
buttonBox.add(yBox);
buttonBox.add(Box.createHorizontalGlue());
framePanel.add(buttonBox, BorderLayout.SOUTH);
tjc
committed
/**
* Returns true if this qualifier is non-transferable
* @param qualifierName
* @return
*/
protected static boolean isNonTransferable(String qualifierName)
{
for(int i=0; i<NON_TRANSFERABLE_QUALIFIERS.length; i++)
{
if(NON_TRANSFERABLE_QUALIFIERS[i].equals(qualifierName))
return true;
}
return false;
}
/**
* Transfer selected qualifiers to the list of features defined
tjc
committed
* by the selected names.
* @param qualifierCheckBoxes - list of qualifier check boxes
* @param geneNameTextArea - text with a list of feature names to transfer to
* @param feature - feature to copy from
* @param entryGroup
tjc
committed
* @param sameKey
* @param overwrite
protected static int transferAnnotation(
final Hashtable qualifierCheckBoxes,
final Vector geneNameCheckBoxes,
final Feature orginatingFeature,
final EntryGroup entryGroup,
final boolean sameKey,
final boolean overwrite,
final StringBuffer buff,
final StringBuffer genesUpdated)
final QualifierVector qualifiers = orginatingFeature.getQualifiers();
final QualifierVector qualifiersToTransfer = new QualifierVector();
Enumeration enumQualifiers = qualifierCheckBoxes.keys();
while(enumQualifiers.hasMoreElements())
JCheckBox cb = (JCheckBox) enumQualifiers.nextElement();
if (cb.isSelected())
{
Vector qualifierValuesCheckBox = (Vector)qualifierCheckBoxes.get(cb);
StringVector values = qualifiers.getQualifierByName(cb.getText()).getValues();
StringVector valuesToTransfer = new StringVector(values);
logger4j.debug("TRANSFER "+cb.getText());
for(int i=0; i<qualifierValuesCheckBox.size(); i++)
{
JCheckBox valuesCb = (JCheckBox) qualifierValuesCheckBox.get(i);
if(!valuesCb.isSelected())
{
valuesToTransfer.remove(valuesCb.getText());
logger4j.debug("NOT TRANSFERING "+valuesCb.getText());
}
}
if(valuesToTransfer.size() < 1)
continue;
qualifiersToTransfer.addElement(new Qualifier(cb.getText(), valuesToTransfer));
}
int count = 0;
for(int i =0; i<geneNameCheckBoxes.size(); i++)
{
if( ((JCheckBox)geneNameCheckBoxes.get(i)).isSelected() )
count++;
}
"No genes selected.",
"Warning", JOptionPane.WARNING_MESSAGE);
tjc
committed
}
String geneNames[] = new String[count];
count = 0;
for(int i =0; i<geneNameCheckBoxes.size(); i++)
{
JCheckBox cb = (JCheckBox)geneNameCheckBoxes.get(i);
if( cb.isSelected() )
{
geneNames[count] = cb.getText();
logger4j.debug("TRANSFER ANNOTATION TO "+geneNames[count]);
count++;
}
}
final FeatureVector features = entryGroup.getAllFeatures();
// transfer selected annotation
entryGroup.getActionController().startAction();
geneNames = transfer(features, qualifiersToTransfer, key, sameKey, overwrite,
GeneUtils.isDatabaseEntry(entryGroup), geneNames, genesUpdated);
entryGroup.getActionController().endAction();
//
// Commit changes to genes not in Artemis but in the database
//
if (orginatingFeature.getEntry().getEMBLEntry() instanceof DatabaseDocumentEntry)
DatabaseDocumentEntry db_entry =
(DatabaseDocumentEntry) orginatingFeature.getEntry().getEMBLEntry();
DatabaseDocument doc = (DatabaseDocument) db_entry.getDocument();
DatabaseDocumentEntry newDbEntry = GeneEdit.makeGeneEntry(null,
geneNames[i], doc, null);
if (newDbEntry == null)
{
if (genesNotFound == null)
genesNotFound = new Vector();
genesNotFound.add(geneNames[i]);
continue;
}
char[] c = new char[1];
PartialSequence ps = new PartialSequence(c, 100, 0, null, null);
newDbEntry.setPartialSequence(ps);
Entry entry = null;
try
{
entry = new Entry(newDbEntry);
}
catch (Exception e)
{
e.printStackTrace();
}
SimpleEntryGroup entry_group = new SimpleEntryGroup();
entry_group.addElement(entry);
ChadoTransactionManager ctm = new ChadoTransactionManager();
entry_group.addFeatureChangeListener(ctm);
entry_group.addEntryChangeListener(ctm);
ctm.setEntryGroup(entry_group);
overwrite, true, geneNames, genesUpdated);
for(int j=0; j<ctm.getTransactionCount(); j++)
buff.append(ctm.getTransactionAt(j).getLogComment()+"\n");
ChadoTransactionManager.commit((DatabaseDocument) newDbEntry
.getDocument(), false, ctm);
entry_group.removeFeatureChangeListener(ctm);
entry_group.removeEntryChangeListener(ctm);
// if(newDbEntry != null)
// GeneEdit.showGeneEditor(null, geneNames[i], newDbEntry);
}
"Gene(s) Not Found:\n"+genesNotFound.toString(),
"Gene(s) Not Found", JOptionPane.WARNING_MESSAGE);
}
/**
*
* @param features
* @param qualifiersToTransfer
* @param key
* @param sameKey
* @param isDatabaseEntry
* @param geneNames
* @return
*/
private static String[] transfer(final FeatureVector features,
final QualifierVector qualifiersToTransfer,
final String key,
tjc
committed
final boolean sameKey,
final boolean overwrite,
final boolean isDatabaseEntry,
String[] geneNames,
final StringBuffer genesUpdated)
{
final TransferFeaturePredicate predicate = new TransferFeaturePredicate(
key, sameKey, isDatabaseEntry, geneNames);
for (int i = 0; i < features.size(); i++)
{
Feature thisFeature = features.elementAt(i);
if (predicate.testPredicate(thisFeature))
{
StringBuffer qualifierBuffer = new StringBuffer();
for (int j = 0; j < qualifiersToTransfer.size(); j++)
{
Qualifier newQualifier = (Qualifier) qualifiersToTransfer.elementAt(j);
String qualifierName = newQualifier.getName();
tjc
committed
if(overwrite)
tjc
committed
thisFeature.setQualifier(newQualifier);
qualifierBuffer.append(" "+qualifierName+" (overwritten)\n"+
parseStringVector(newQualifier.getValues()));
}
tjc
committed
else
{
final StringVector oldValues;
if (thisFeature.getQualifierByName(newQualifier.getName()) == null)
oldValues = null;
else
oldValues = thisFeature.getQualifierByName(
newQualifier.getName()).getValues();
final Qualifier newQualifierTmp = getQualifierWithoutDuplicateValues(
newQualifier, oldValues);
if (newQualifierTmp == null)
continue;
thisFeature.addQualifierValues(newQualifierTmp);
qualifierBuffer.append(" "+qualifierName+" (added)\n"+
parseStringVector(newQualifier.getValues()));
tjc
committed
}
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
geneNames = removeArrayElement(geneNames, predicate.getGeneName());
if(qualifierBuffer.length() > 0)
genesUpdated.append(thisFeature.getSystematicName()+
" ("+key+")\n"+qualifierBuffer);
}
}
return geneNames;
}
/**
* Get a StringBuffer representation of the values in a StringVector
* @param v
* @return
*/
private static StringBuffer parseStringVector(final StringVector v)
{
StringBuffer buff = new StringBuffer();
for(int i=0; i<v.size(); i++)
buff.append(" "+v.elementAt(i)+"\n");
return buff;
}
/**
* Return a qualifier copy of the qualifier provided that does not contain
* any of the values in the StringVector.
* @param newQualifier
* @param oldValues
* @return
* @throws InvalidRelationException
*/
private static Qualifier getQualifierWithoutDuplicateValues(
final Qualifier qualifier,
final StringVector values) throws InvalidRelationException
{
final Qualifier newQualifier;
if (values == null || values.size() < 1)
newQualifier = qualifier;
else
{
StringVector newValues = qualifier.getValues();
StringVector valuesToAdd = new StringVector();
for (int k = 0; k < newValues.size(); k++)
{
if(!values.contains(newValues.get(k)))
valuesToAdd.add(newValues.get(k));
}
if(valuesToAdd.size() == 0)
return null;
newQualifier = new Qualifier(qualifier.getName(), valuesToAdd);
}
return newQualifier;
}
/**
* Remove a string from an array of strings. If the string appears multiple
* times in the array this method will delete all occurrences.
* @param strArr
* @param str
* @return
*/
private static String[] removeArrayElement(final String strArr[], final String str)
String[] newarray = new String[strArr.length - 1];
int count = 0;
for (int i = 0; i < strArr.length; i++)
{
if (strArr[i].equals(str))
continue;
// not found str return original array
if (count >= newarray.length)
return strArr;
newarray[count] = strArr[i];
count++;
}
if (count < newarray.length)
{
String[] tmparray = new String[count];
System.arraycopy(newarray, 0, tmparray, 0, count);
newarray = tmparray;
}
}
class QualifierPanel extends JPanel
{
private Hashtable qualifierCheckBoxes = new Hashtable();
private Feature feature;
protected int nrows = 0;
public QualifierPanel(Feature feature, String title)
tjc
committed
{
super(new GridBagLayout());
this.feature = feature;
TitledBorder titleBorder = BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), title);
titleBorder.setTitleJustification(TitledBorder.LEFT);
titleBorder.setTitleColor(TransferAnnotationTool.STEEL_BLUE);
setBorder(titleBorder);
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.WEST;
c.ipadx = 0;
final QualifierVector qualifiers = feature.getQualifiers();
tjc
committed
tjc
committed
{
nrows =
addQualifierComponents((Qualifier) qualifiers.get(i),
qualifierCheckBoxes, c, nrows);
tjc
committed
}
setMinimumSize(new Dimension(
titleBorder.getMinimumSize(this).width,
getMinimumSize().height));
}
/**
* Add a qualifier to the list of transferable annotation
* @param pane
* @param qualifier
* @param qualifierCheckBoxes
* @param c
* @param nrows
* @return
*/
private int addQualifierComponents(final Qualifier qualifier,
final Hashtable qualifierCheckBoxes,
final GridBagConstraints c,
int nrows)
{
if(TransferAnnotationTool.isNonTransferable(qualifier.getName()))
tjc
committed
return nrows;
final JCheckBox qualifierNameCheckBox = new JCheckBox(qualifier.getName(), false);
c.gridx = 1;
c.fill = GridBagConstraints.NONE;
c.weightx = 0.d;
Box qualifierValueBox = Box.createVerticalBox();
JButton detailsShowHide = new JButton("+");
final Vector qualifierValuesCheckBox = setExpanderButton(detailsShowHide,
qualifier, qualifierValueBox, qualifierNameCheckBox);
qualifierNameCheckBox.addItemListener(new ItemListener()
tjc
committed
{
tjc
committed
{
if(qualifierNameCheckBox.isSelected())
{
for(int i=0; i<qualifierValuesCheckBox.size(); i++)
{
JCheckBox cb = (JCheckBox) qualifierValuesCheckBox.get(i);
if(cb.isSelected())
return;
}
}
tjc
committed
{
JCheckBox cb = (JCheckBox) qualifierValuesCheckBox.get(i);
cb.setSelected(qualifierNameCheckBox.isSelected());
tjc
committed
}
tjc
committed
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 100;
c.gridx = 2;
add(qualifierNameCheckBox, c);
qualifierCheckBoxes.put(qualifierNameCheckBox, qualifierValuesCheckBox);
c.gridy = ++nrows;
add(qualifierValueBox, c);
c.gridy = ++nrows;
return nrows;
tjc
committed
}
* Set up the expander button to display qualifier values.
* @param butt - expander button
* @param qualifier - the qualifer that is being displayed
* @param qualifierValueBox - Box containing the values
* @param qualifierNameCheckBox - JCheckBox for the given qualifier
* @param pane
* @return
private Vector setExpanderButton(final JButton butt,
final Qualifier qualifier,
final Box qualifierValueBox,
final JCheckBox qualifierNameCheckBox)
butt.setMargin(new Insets(0, 0, 0, 0));
butt.setHorizontalAlignment(SwingConstants.RIGHT);
butt.setHorizontalTextPosition(SwingConstants.RIGHT);
butt.setBorderPainted(false);
butt.setFont(butt.getFont().deriveFont(Font.BOLD));
butt.setForeground(TransferAnnotationTool.STEEL_BLUE);
butt.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
{
if (butt.getText().equals("+"))
butt.setText("-");
else
butt.setText("+");
qualifierValueBox.setVisible(butt.getText().equals("-"));
revalidate();
}
});
// set-up qualifier values list
qualifierValueBox.setVisible(false);
Vector qualifierValuesCheckBox = new Vector();
StringVector values = qualifier.getValues();
for (int i = 0; i < values.size(); i++)
JCheckBox cb = new JCheckBox((String) values.get(i),
qualifierNameCheckBox.isSelected());
cb.setFont(cb.getFont().deriveFont(Font.ITALIC));
qualifierValueBox.add(cb);
qualifierValuesCheckBox.add(cb);
}
return qualifierValuesCheckBox;
}
protected Hashtable getQualifierCheckBoxes()
{
return qualifierCheckBoxes;
}
protected Feature getFeature()
{
return feature;
}
}
/**
* Test if the feature is nominated to have annotation transferred
* to it. For genes in a chado database it looks at the gene name
* and transcript name.
*/
class TransferFeaturePredicate implements FeaturePredicate
{
private String geneName;
private String key;
private boolean sameKey;
private boolean isDatabaseEntry;
private String[] geneNames;
public TransferFeaturePredicate(final String key,
final boolean sameKey,
final boolean isDatabaseEntry,
final String[] geneNames)
{
this.key = key;
this.sameKey = sameKey;
this.isDatabaseEntry = isDatabaseEntry;
this.geneNames = geneNames;
}
public boolean testPredicate(Feature targetFeature)
{
String targetKey = targetFeature.getKey().getKeyString();
if (sameKey && !targetKey.equals(key))
return false;
Vector chadoNames = null;
if (isDatabaseEntry)
{
GFFStreamFeature gffFeature =
((GFFStreamFeature) targetFeature.getEmblFeature());
if (gffFeature.getChadoGene() != null)
chadoNames = new Vector();
ChadoCanonicalGene chadoGene = gffFeature.getChadoGene();
chadoNames.add(chadoGene.getGeneUniqueName());
List transcripts = chadoGene.getTranscripts();
for(int i=0;i<transcripts.size();i++)
GFFStreamFeature feature = (GFFStreamFeature) transcripts.get(i);
chadoNames.add(GeneUtils.getUniqueName(feature));
String thisFeatureSystematicName = targetFeature.getSystematicName();
for (int i = 0; i < geneNames.length; i++)
if(geneNames[i].equals(thisFeatureSystematicName) ||
(chadoNames != null && chadoNames.contains(geneNames[i])))
{
geneName = geneNames[i];
return true;
}
return false;
}
protected String getGeneName()
{
return geneName;