import jalview.analysis.AlignSeq;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenColumns;
import jalview.datamodel.RnaViewerModel;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import javax.swing.JInternalFrame;
import javax.swing.JSplitPane;
import fr.orsay.lri.varna.models.rna.ModeleBase;
import fr.orsay.lri.varna.models.rna.RNA;
-public class AppVarna extends JInternalFrame implements SelectionListener,
- SecondaryStructureListener, InterfaceVARNASelectionListener,
- VamsasSource
+public class AppVarna extends JInternalFrame
+ implements SelectionListener, SecondaryStructureListener,
+ InterfaceVARNASelectionListener, VamsasSource
{
- private static final Pattern PAIRS_PATTERN = Pattern
- .compile("[^([{<>}])]");
+ private static final byte[] PAIRS = new byte[] { '(', ')', '[', ']', '{',
+ '}', '<', '>' };
private AppVarnaBinding vab;
{
this(ap);
- String sname = aa.sequenceRef == null ? "secondary structure (alignment)"
+ String sname = aa.sequenceRef == null
+ ? "secondary structure (alignment)"
: seq.getName() + " structure";
String theTitle = sname
- + (aa.sequenceRef == null ? " trimmed to " + seq.getName() : "");
+ + (aa.sequenceRef == null ? " trimmed to " + seq.getName()
+ : "");
theTitle = MessageManager.formatMessage("label.varna_params",
new String[]
{ theTitle });
addModel(gappedModel, gappedTitle);
String trimmedTitle = "trimmed " + sname;
- RnaModel trimmedModel = new RnaModel(trimmedTitle, aa, seq, null, false);
+ RnaModel trimmedModel = new RnaModel(trimmedTitle, aa, seq, null,
+ false);
addModel(trimmedModel, trimmedTitle);
vab.setSelectedIndex(0);
}
-
/**
* Constructor that links the viewer to a parent panel (but has no structures
* yet - use addModel to add them)
showPanel(true);
}
- public String replaceOddGaps(String oldStr)
- {
- Matcher matcher = PAIRS_PATTERN.matcher(oldStr);
- String newStr = matcher.replaceAll(".");
- return newStr;
- }
-
/**
* Constructs a new RNA model from the given one, without gaps. Also
* calculates and saves a 'shift list'
RNA rnaTrim = new RNA(name);
try
{
- rnaTrim.setRNA(rna.getSeq(), replaceOddGaps(rna.getStructDBN()));
+ String structDBN = rna.getStructDBN(true);
+ rnaTrim.setRNA(rna.getSeq(), replaceOddGaps(structDBN));
} catch (ExceptionUnmatchedClosingParentheses e2)
{
e2.printStackTrace();
String seq = rnaTrim.getSeq();
StringBuilder struc = new StringBuilder(256);
- struc.append(rnaTrim.getStructDBN());
+ struc.append(rnaTrim.getStructDBN(true));
int ofstart = -1;
int sleng = seq.length();
ofstart = i;
}
/*
- * mark base or base pair in the structure with *
+ * mark base or base & pair in the structure with *
*/
if (!rnaTrim.findPair(i).isEmpty())
{
@Override
public void selection(SequenceGroup seqsel, ColumnSelection colsel,
- SelectionSource source)
+ HiddenColumns hidden, SelectionSource source)
{
if (source != ap.av)
{
end = shift.shift(end);
}
selectionHighlighter.highlightRegion(rna, start, end);
- selectionHighlighter.getLastHighlight().setOutlineColor(
- seqsel.getOutlineColour());
+ selectionHighlighter.getLastHighlight()
+ .setOutlineColor(seqsel.getOutlineColour());
// TODO - translate column markings to positions on structure if present.
vab.updateSelectedRNA(rna);
}
}
@Override
- public void onSelectionChanged(BaseList arg0, BaseList arg1, BaseList arg2)
+ public void onSelectionChanged(BaseList arg0, BaseList arg1,
+ BaseList arg2)
{
// TODO translate selected regions in VARNA to a selection on the
// alignpanel.
{
if (!model.ann.isValidStruc())
{
- throw new IllegalArgumentException("Invalid RNA structure annotation");
+ throw new IllegalArgumentException(
+ "Invalid RNA structure annotation");
}
/*
ShiftList offset = new ShiftList();
int ofstart = -1;
int sleng = seq.getLength();
- char[] seqChars = seq.getSequence();
for (int i = 0; i < sleng; i++)
{
- if (Comparison.isGap(seqChars[i]))
+ if (Comparison.isGap(seq.getCharAt(i)))
{
if (ofstart == -1)
{
vab.setSelectedIndex(selectedIndex);
}
-
/**
* Add a model with associated Varna session file
*
{
if (!model.ann.isValidStruc())
{
- throw new IllegalArgumentException("Invalid RNA structure annotation");
+ throw new IllegalArgumentException(
+ "Invalid RNA structure annotation");
}
try
return null;
}
}
+
+ /**
+ * Replace everything except RNA secondary structure characters with a period
+ *
+ * @param s
+ * @return
+ */
+ public static String replaceOddGaps(String s)
+ {
+ if (s == null)
+ {
+ return null;
+ }
+
+ // this is measured to be 10 times faster than a regex replace
+ boolean changed = false;
+ byte[] bytes = s.getBytes();
+ for (int i = 0; i < bytes.length; i++)
+ {
+ boolean ok = false;
+ // todo check for ((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z')) if
+ // wanted also
+ for (int j = 0; !ok && (j < PAIRS.length); j++)
+ {
+ if (bytes[i] == PAIRS[j])
+ {
+ ok = true;
+ }
+ }
+ if (!ok)
+ {
+ bytes[i] = '.';
+ changed = true;
+ }
+ }
+ return changed ? new String(bytes) : s;
+ }
}