[Biojava-l] Sequence Range Question
Ethan Cerami
ecerami@yahoo.com
Tue, 14 Jan 2003 05:50:52 -0800 (PST)
Ok, based on the feedback I got yesterday, I have made
much progress :-) Right now, I am trying to create a
bare bones gene viewer that can render gene features
via a SequencePanel object. For example, the code
below renders the Adam2 gene on chromosome 8.
Adam2 is located at: Chromosome 8: 38997645 -
39047541 bp. To render it, I have a 1MB dummy
sequence that starts at 1. How do I create a dummy
sequence that starts at 38995000 so that I can show
the correct location? Is there some way to create a
virtual offset?
Sample code is below. Thanks again for any help!
Ethan
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.biojava.bio.*;
import org.biojava.bio.gui.sequence.*;
import org.biojava.bio.seq.*;
import org.biojava.bio.seq.impl.SimpleSequence;
import org.biojava.bio.seq.genomic.Gene;
import org.biojava.bio.symbol.*;
import org.biojava.utils.ChangeVetoException;
/**
* Simple Gene Browser
*/
public class FeatureView extends JFrame {
private final static int WINDOW = 1000000; // 1
Million BP
private Sequence sequence;
private JPanel panel = new JPanel ();
private MultiLineRenderer mlr = new MultiLineRenderer
();
private RectangularBeadRenderer featr = new
RectangularBeadRenderer ();
private RulerRenderer ruler = new RulerRenderer ();
private SequencePanel seqPanel = new SequencePanel
();
private FeatureBlockSequenceRenderer fbr =
new FeatureBlockSequenceRenderer ();
/**
* Constructor
*/
public FeatureView () throws Exception {
sequence = createSequence ();
addGenes (sequence);
createGUI ();
}
/**
* Creates a Dummy Sequence
*/
private Sequence createSequence () {
SymbolList dummyList = new DummySymbolList
(DNATools.getDNA (),
WINDOW);
Sequence sequence = new SimpleSequence (dummyList,
"ensembl", "ensembl",
Annotation.EMPTY_ANNOTATION);
return sequence;
}
/**
* Creates Multiple Genes
*/
private void addGenes (Sequence sequence)
throws BioException, ChangeVetoException {
// Add Adam2 Gene
// Location: Chromosome 8: 38997645 - 39047541 bp
// int adam2_start = 38997645; this doesn't work
b/c
// it's out of range
int adam2_start = 20000;
int adam2_length = 49896;
Gene.Template gene = new Gene.Template ();
gene.type = "gene";
gene.source = "ensembl";
gene.location = new RangeLocation (adam2_start,
adam2_start
+ adam2_length);
gene.annotation = Annotation.EMPTY_ANNOTATION;
gene.strand = StrandedFeature.POSITIVE;
sequence.createFeature (gene);
}
/**
* Create the User Interface
*/
private void createGUI () throws Exception {
this.setTitle ("Gene Viewer");
Container contentPane = this.getContentPane ();
contentPane.add (panel, BorderLayout.CENTER);
panel.add (seqPanel);
// Register the FeatureRenderer with the
FeatureBlockSequenceRenderer
fbr.setFeatureRenderer (featr);
// Add Renderers to the MultiLineRenderer
mlr.addRenderer (fbr);
mlr.addRenderer (ruler);
seqPanel.setRenderer (mlr);
// Set the Sequence to Render
seqPanel.setSequence (sequence);
seqPanel.setRange (new RangeLocation (1, WINDOW));
seqPanel.setScale (.0007);
}
/**
* Overridden so program terminates when window
closes
*/
protected void processWindowEvent (WindowEvent we) {
if (we.getID () == WindowEvent.WINDOW_CLOSING) {
System.exit (0);
} else {
super.processWindowEvent (we);
}
}
/**
* Main Method
*/
public static void main (String[] args) throws
Exception {
FeatureView featureView = new FeatureView ();
featureView.pack ();
featureView.show ();
}
}
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com