import java.awt.BorderLayout;
import java.awt.Color;
+import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Hashtable;
import java.util.LinkedHashMap;
/**
* Constructor
*
- * @param sname
- * a descriptive name
* @param seq
* the RNA sequence
* @param aa
* @param ap
* the AlignmentPanel creating this object
*/
- public AppVarna(String sname, SequenceI seq, AlignmentAnnotation aa,
- AlignmentPanel ap)
+ public AppVarna(SequenceI seq, AlignmentAnnotation aa, AlignmentPanel ap)
{
this(ap);
- String name = sname + " trimmed to " + seq.getName();
- String fullName = MessageManager.formatMessage("label.varna_params",
+ String sname = aa.sequenceRef == null ? "secondary structure (alignment)"
+ : seq.getName() + " structure";
+ String theTitle = sname
+ + (aa.sequenceRef == null ? " trimmed to " + seq.getName() : "");
+ theTitle = MessageManager.formatMessage("label.varna_params",
new String[]
- { name });
- setTitle(fullName);
-
- /*
- * if (!aa.isValidStruc()) { throw new
- * IllegalArgumentException("Invalid RNA structure annotation"); } final
- * String struc = aa.getRNAStruc();
- *
- * String strucseq = seq.getSequenceAsString();
- *
- * String gappedTitle = sname + " (with gaps)"; String rnaTitle =
- * gappedTitle; RNA gapped = new RNA(rnaTitle); try {
- * gapped.setRNA(strucseq, replaceOddGaps(struc)); } catch
- * (ExceptionUnmatchedClosingParentheses e2) { e2.printStackTrace(); } catch
- * (ExceptionFileFormatOrSyntax e3) { e3.printStackTrace(); }
- * models.put(gapped, new RnaModel(rnaTitle, aa, seq, gapped, true, null));
- *
- * String trimmedTitle = "trimmed " + sname; rnaTitle = trimmedTitle; RNA
- * trimmed = trimRNA(gapped, rnaTitle); models.put(trimmed, new
- * RnaModel(rnaTitle, aa, seq, trimmed, false, null));
- */
- // vab = new AppVarnaBinding(Arrays.asList(new RNA[]
- // { trimmed, gapped }));
- // vab = new AppVarnaBinding();
- // // String seqName = seq.getName();
- // // String name = sname + " trimmed to " + seqName;
- // initVarna(name);
+ { theTitle });
+ setTitle(theTitle);
String gappedTitle = sname + " (with gaps)";
RnaModel gappedModel = new RnaModel(gappedTitle, aa, seq, null, true,
* selected RNA in the VARNA window is highlighted at the specific position.
* To be able to remove it before the next highlight it is saved in
* _lastHighlight
+ *
+ * @param sequence
+ * @param index
+ * the aligned sequence position (base 0)
+ * @param position
+ * the dataset sequence position (base 1)
*/
@Override
- public void mouseOverSequence(SequenceI sequence, int index)
+ public void mouseOverSequence(SequenceI sequence, final int index,
+ final int position)
{
RNA rna = vab.getSelectedRNA();
if (rna == null)
{
return;
}
- if (models.get(rna).seq == sequence)
- {
- ShiftList shift = offsets.get(rna);
- if (shift != null)
- {
- // System.err.print("Orig pos:"+index);
- index = shift.shift(index);
- // System.err.println("\nFinal pos:"+index);
- }
- mouseOverHighlighter.highlightRegion(rna, index, index);
+ RnaModel rnaModel = models.get(rna);
+ if (rnaModel.seq == sequence)
+ {
+ int highlightPos = rnaModel.gapped ? index : position - 1;
+ // int highlightPos = index;
+ // ShiftList shift = offsets.get(rna);
+ // if (shift != null)
+ // {
+ // System.err.print("Orig pos:" + index);
+ // highlightPos = shift.shift(index);
+ // System.err.println("\nFinal pos:" + index);
+ // }
+ mouseOverHighlighter.highlightRegion(rna, highlightPos, highlightPos);
vab.updateSelectedRNA(rna);
}
}
{
registerOffset(rna, buildOffset(model.seq));
}
- // TODO and add mapping (offsets)
models.put(rna, newModel);
// capture rna selection state when saved
selectionHighlighter = new VarnaHighlighter(rna);
protected ShiftList buildOffset(SequenceI seq)
{
// TODO refactor to avoid duplication with trimRNA()
+ // TODO JAL-1789 bugs in use of ShiftList here
ShiftList offset = new ShiftList();
int ofstart = -1;
int sleng = seq.getLength();
/**
* Set the selected index in the model selection list
*
- * @param selectedRna
+ * @param selectedR
*/
- public void setSelectedIndex(int selectedRna)
+ public void setInitialSelection(final int selectedIndex)
{
- vab.setSelectedIndex(selectedRna);
+ vab.setSelectedIndex(selectedIndex);
}
}
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
-import java.awt.Font;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import fr.orsay.lri.varna.VARNAPanel;
import fr.orsay.lri.varna.components.ReorderableJList;
import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
+import fr.orsay.lri.varna.exceptions.ExceptionNAViewAlgorithm;
import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength;
import fr.orsay.lri.varna.models.FullBackup;
import fr.orsay.lri.varna.models.VARNAConfig;
vp.setBackground(_backgroundColor);
- Font textFieldsFont = Font.decode("MonoSpaced-PLAIN-12");
-
// MC commented out stuff not added to panel - remove?
+ // Font textFieldsFont = Font.decode("MonoSpaced-PLAIN-12");
+ //
// _seq.setFont(textFieldsFont);
// if (!rnaList.isEmpty())
// {
}
/*
- * switch display if not already shown
+ * switch display
*/
- if (sel.rna != rna)
- {
- vp.showRNA(model.rna, model.config);
- }
+ vp.showRNA(model.rna, model.config);
try
{
vp.toXML(filePath);
/*
- * restore the previous display if needed
+ * restore the previous display
*/
- if (sel.rna != rna)
- {
- vp.showRNA(sel.rna, sel.config);
- }
+ vp.showRNA(sel.rna, sel.config);
return filePath;
} catch (IOException e)
*
* @param selectedRna
*/
- public void setSelectedIndex(int selectedRna)
+ public void setSelectedIndex(final int selectedRna)
{
/*
* note this does nothing if, say, selecting item 3 when only 1 has been
*/
_sideList.setSelectedIndex(selectedRna);
// TODO ? need a worker thread to get this to happen properly
- showSelectedStructure();
}
/**
* @param rna
* @param config
*/
- protected void addStructure(RNA rna, VARNAConfig config)
+ protected void addStructure(final RNA rna, final VARNAConfig config)
{
- rna.drawRNARadiate(config);
+ drawRna(rna, config);
_rnaList.add(config, rna, rna.getName());
}
+
+ /**
+ * @param rna
+ * @param config
+ */
+ protected void drawRna(final RNA rna, final VARNAConfig config)
+ {
+ try
+ {
+ rna.drawRNA(rna.getDrawMode(), config);
+ } catch (ExceptionNAViewAlgorithm e)
+ {
+ // only throwable for draw mode = 3 NAView
+ System.err.println("Error drawing RNA: " + e.getMessage());
+ }
+ }
}
/*
* valid alignment RNA secondary structure annotation
*/
- final String structureLine = aa.label + " (alignment)";
menuItem = new JMenuItem();
menuItem.setText(MessageManager.formatMessage(
"label.2d_rna_structure_line", new Object[]
- { structureLine }));
+ { aa.label }));
menuItem.addActionListener(new java.awt.event.ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- new AppVarna(structureLine, seq, aa, ap);
+ new AppVarna(seq, aa, ap);
}
});
rnaStructureMenu.add(menuItem);
}
}
-
if (seq.getAnnotation() != null)
{
AlignmentAnnotation seqAnns[] = seq.getAnnotation();
public void actionPerformed(ActionEvent e)
{
// TODO: VARNA does'nt print gaps in the sequence
-
- new AppVarna(seq.getName() + " structure", seq, aa,
- ap);
+ new AppVarna(seq, aa, ap);
}
});
rnaStructureMenu.add(menuItem);