[Biojava-l] Multiple alignment display issues
Russ Kepler
russ at kepler-eng.com
Mon Nov 28 11:43:20 EST 2005
Further in my efforts in using the FlexibleAlignment class in conjunction with
the display the alignments I have created some test code, reproduced below.
The sequences are all displaying, but not in the alignment range. Am I
simply missing something simple here, like a symbol renderer that handles a
range? Or should someone be rewriting the context before the renderer is
called?
(Apologies for the form - I've had to maintain this in a development
environment to use my modified BioJava ).
import java.awt.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
import org.biojava.bio.alignment.*;
import org.biojava.bio.gui.sequence.*;
import org.biojava.bio.seq.*;
import org.biojava.bio.symbol.*;
public class MultiAlignViewerDemo {
public static void main(String[] args) {
//MultiAlignViewer multialignviewer = new MultiAlignViewer();
try {
MultiLineRenderer mlr = new MultiLineRenderer();
SequenceRenderer subSeqRend = new SymbolSequenceRenderer();
GappedRenderer seqRend = new GappedRenderer(subSeqRend);
// make three random sequences
SymbolList res1 = createSymbolList(10);
SymbolList res2 = createSymbolList(10);
SymbolList res3 = createSymbolList(10);
// think of three names
String name1 = "pigs";
String name2 = "dogs";
String name3 = "cats";
// create list with reference sequence
ArrayList list = new ArrayList(1);
SymbolList refSeq = createSymbolList(30);
list.add(new SimpleAlignmentElement("reference", refSeq, new
RangeLocation(1, 30)));
// create the alignment with the reference sequence
FlexibleAlignment alignment = new FlexibleAlignment(list);
list = new ArrayList(3);
// add the sequences as alignments
alignment.addSequence(new SimpleAlignmentElement(name1, res1, new
RangeLocation(1, 10)));
AlignmentRenderer ar1 = new AlignmentRenderer();
ar1.setLabel("pigs");
ar1.setRenderer(seqRend);
mlr.addRenderer(ar1);
alignment.addSequence(new SimpleAlignmentElement(name2, res2, new
RangeLocation(11, 20)));
AlignmentRenderer ar2 = new AlignmentRenderer();
ar2.setLabel("dogs");
ar2.setRenderer(seqRend);
mlr.addRenderer(ar2);
alignment.addSequence(new SimpleAlignmentElement(name3, res3, new
RangeLocation(21, 30)));
AlignmentRenderer ar3 = new AlignmentRenderer();
ar3.setLabel("cats");
ar3.setRenderer(seqRend);
mlr.addRenderer(ar3);
// add the reference sequence to the render list
AlignmentRenderer arRef = new AlignmentRenderer();
arRef.setLabel("reference");
arRef.setRenderer(seqRend);
mlr.addRenderer(arRef);
mlr.addRenderer(new RulerRenderer());
// we will display this in a window
JFrame frame = new JFrame("Multialign Viewer Demo");
frame.setSize(400, 300);
TranslatedSequencePanel sp = new TranslatedSequencePanel();
sp.setSequence(alignment);
sp.setScale(7.0);
sp.setDirection(TranslatedSequencePanel.HORIZONTAL);
sp.setRenderer(mlr);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(sp, BorderLayout.CENTER);
frame.setVisible(true);
} catch (Exception ex) {
ex.printStackTrace(System.err);
System.exit(1);
}
}
/**
* Common stuff that the demos rely on.
*
* @author Matthew Pocock
*/
public static SymbolList createSymbolList(int length) throws
IllegalSymbolException {
List l = new ArrayList(length);
for (int i = 0; i < length; i++) {
l.add(DNATools.forIndex((int) (4.0 * Math.random())));
}
return new SimpleSymbolList(DNATools.getDNA(), l);
}
}
More information about the Biojava-l
mailing list