Skip to content
chmille4 edited this page Aug 9, 2011 · 19 revisions

Placeholder

New to Version 0.4

Changes: The way Scribl::Track (link to annotated code?) behaves has changed to more closely replicate genome browsers. A track now contains multiple Scribl::Lanes. A Track relates to a specific entity (e.g. UCSC Build HG18 SNPs Chromosome1) but can contain many Lanes so that features do not overlap.

Scribl::Lanes - behave in much the same was as Scribl::Track did in previous version

  • Finer Track Control
  • Lane Control
  • Chart.slice()
  • Major Performance Increase
    • Large chart are much faster now
    • Mouse Events only require redrawing of the track the event was associated with
  • API Consolidation
    • The way you set the default text attributes (for all features) and individual features has been unified with the deprecated API being removed
    • The way attributes are retrieved has been simplified by the addition of a glyph.getAttr('attr') method, which greatly simplifies the internals of how attributes work. getAttr bubbles through the correct order to determine the correct value for the attribute. For example glyph.getAttr('color') would first checks to see if the color attribute has a value with the glyph itself (i.e. glyph.color) then it checks if it is part of a complex glyph and it's parent has a value (i.e. glyph.parent.color) then it checks if its type has a value (glyph.chart.type.color) and if none of those are set then it returns the default set at the top of Scribl.js (scribl.glyph.color).

Quick Start - Create a simple chart

// Get Canvas and Create Chart
var canvas = document.getElementById(canvasName);  		
// Create Chart
var chart = new Scribl(canvas, 500);
// Add Gene      position, length, orientation
var gene = chart.addGene( 900,    750 , '-');
// Draw Chart
chart.draw();

##Glyphs Glyphs are the symbols that can be added to a chart. There are currently 4 glyphs: BlockArrow, Arrow, Rect, and Line

###Common Attributes###

glyph.roundness = 1 // in pixels
glyph.color = 'rgb(120,0,255)'
glyph.text.align = 'left'; // aligns to the left side of the gene
glyph.text.align = 'center'; // aligns in the center
glyph.text.align = 'right'; // align to the right side
// relative positioning - based on the strand the gene in on
glyph.text.align = 'start'; // aligned at the start of the gene - left for '+' strand genes and right for '-' strand genes
glyph.text.align = 'end'; // aligned at the end of the gene - opposite of start 
glyph.text.font = 'arial';
glyph.text.size = '15'; // in pixels 
glyph.text.color = 'black';

###Common Events###

// open website
glyph.onClick = "http://www.google.com"
// Execute Function
glyph.onClick = function() {alert("I've been clicked");}
glyph.onMouseover = "Moused Over"

###BlockArrow Glyph### blockarrow glyph javascript BlockArrow( type, start, length, strand, {opts} )


<a name="line_glyph"></a>
###[Line Glyph](#line_glyph)###
![line glyph](https://github.com/chmille4/Scribl/raw/gh-pages/images/line.png)
```javascript```
Line( type, start, length, {opts} )
var line = chart1.addFeature( new Line('arrow', 0, 500));
line.thickness = 2;

###Rect Glyph### rect glyph

Rect( type, start, length, {opts} )
rect1 = chart1.addFeature( new Rect('gene', 0, 1000, '+'));

###Arrow Glyph### arrow glyph The arrow glyph sits at a single point and shows direction javascript Arrow( type, position, strand, {opts} )


* <a name="arrow_glyph_attributes"></a>[Arrow Specific Attributes](#arrow_glyph_attributes) - 
  * <a name="arrow_glyph_thickness">[Thickness](#arrow_glyph_thickness)
```javascript
arrow1 = chart1.addFeature( new Arrow('arrow', 500, '+'));
arrow1.thickness = 2;

###Complex Glyph### complex glyph javascript Complex( type, start, length, strand, [subfeatures], {opts} )

The complex glyph is made up of multiple subglyphs: ```Line``` (connecting line) and one or more other Exon glyphs (```Arrow```, ```Rect```, ... ). Exon glyph's start values are relative to the start value of the parent complex glyph. So if the parent complex glyph has a start value of 1500 and an exon glyph has a start value of 10, the exon glyph will start at 1500 + 10 or 1510
```javascript
// Add Complex Gene                type, position, length, orientation, array of exons glyphs
gene1 = chart1.addFeature(
  new Complex('gene', 1500, 8000, '+', [
    // add exons   type, relative-start, length ...
    new BlockArrow('gene',0, 500, '+'),
    new Rect('gene',3500, 2000), 
    new Arrow('gene',8000, '+')
  ])
);
// Add complex Gene                type, position, length, orientation, array of exons glyphs
gene1 = chart1.addFeature(
  new Complex('gene', 1500, 8000, '+', [
    new BlockArrow('exon',0, 500, '+'),
    new Rect('exon',3500, 2000), 
    new Arrow('exon',8000, '+')
  ])
);
// set all exons' color
gene1.color = "red";
// override the parent color and set the second exon's color
gene1.subfeatures[1].color = "green";
gene1 = chart1.addFeature( new Complex('gene', 1500, 8000, '+', [ new Arrow('exon',8000, '+') ]));
gene1.line.thickness = 2;
gene1 = chart1.addFeature( new Complex('gene', 1500, 8000, '+', [ new Arrow('exon',8000, '+') ]));
gene1.line.color = "black";

###Setting Attributes/Events

// the last parameter for all glyphs is the opts hash {}, which can take 1 or more optional attributes
gene1 = chart1.addFeature( new Rect('gene',0,500, {'color':'black', 'onMouseover': 'Start 0'}) );
gene1 = chart1.addFeature( new Rect('gene',0,500) );
gene1.color = 'black';
gene1.onMouseover = 'Start 0';

The default values for any of the common attributes can be set for all glyphs. Set the default the same way that you would for a single glyph, but apply it to the chart.glyph object. For example:

var chart = new Scribl(canvas, 500);
chart.glyph.color = "black";

##Types Types are a way of grouping glyphs so their attributes can be easily changed at once. Change any of the common attributes of all glyphs that share a type the same way that you would for a single glyph but apply it to the chart.<insert type> object. For example:

var gene1 = chart.addFeature( new Rect('human', 0, 1000, '+' );
var gene2 = chart.addFeature( new Rect('human', 0, 1000, '+' );
// set all glyphs of the 'human' type to black
chart.human.color = "black";

##Supported Formats Although not the best way to input data into scribl, for convenience several formats are supported

For most cases it's easier to let Scribl automatically manage your tracks by adding genes to the chart itself as in the Quick Start example. However, you may find it necessary to manually manage your tracks. For example, putting all genes on one track and proteins on another

// create tracks
var geneTrack = chart.addTrack();
var proteinTrack = chart.addTrack();
// add genes
var gene1 = geneTrack.addGene(0, 1000, '+');
// add proteins
var protein1 = proteinTrack.addProtein(10, 480, '+');
var protein2 = proteinTrack.addProtein(500, 480, '+');

Scribl automagically determines an appropriate scale, but you can set the scale manually or turn it off completely

// Turn off pretty scale, which turns off all intelligent scaling
chart.scale.pretty = false;
// No scale
chart.scale.off = true;

// create some genes
gene1 = chart.addGene( 7000,    1000 , '-');
gene2 = chart.addGene( 3500, 1500, '+');
gene3 = chart.addGene( 6000,  1000, '-');

// force scale to different min and max
chart.scale.min = 0;
chart.scale.max = 12000;

// change tick distance and color
chart.tick.major.size = 1000;
chart.tick.major.color = "red";

// change scale font color and size
chart.scale.font.color = "white";
chart.scale.font.size = 26;
// change size of tick marks
chart.scale.size = 7;

Clone this wiki locally