mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Trackster: better drawing of deletions in variant tracks. Initial parsing of insertions.
This commit is contained in:
@@ -1402,32 +1402,38 @@ _.extend(VariantPainter.prototype, Painter.prototype, {
|
||||
draw: function(ctx, width, height, w_scale) {
|
||||
ctx.save();
|
||||
|
||||
// Functions for detection insertions (TODO) and deletions.
|
||||
|
||||
/** Returns dictionary of information about a deletion; returns null if there no deletion.
|
||||
var
|
||||
/**
|
||||
* Returns dictionary of information about an indel; returns empty if there no indel. Assumes indel is left-aligned.
|
||||
* Dict attributes:
|
||||
* -type: 'insertion' or 'deletion'
|
||||
* -start: where the deletion starts relative to reference start
|
||||
* -len: how long the deletion is
|
||||
*/
|
||||
var get_deletion_info = function(ref, alt) {
|
||||
var ref_len = ref.length,
|
||||
alt_len = alt.length,
|
||||
start = 0,
|
||||
len = 1,
|
||||
is_delete = false;
|
||||
if (alt === '-') {
|
||||
is_delete = true;
|
||||
len = ref.length;
|
||||
}
|
||||
else if (ref.indexOf(alt) === 0 && ref_len > alt_len) {
|
||||
is_delete = true;
|
||||
len = ref_len = alt_len;
|
||||
start += alt_len;
|
||||
}
|
||||
|
||||
return ( is_delete ? { start: start, len: len } : null );
|
||||
};
|
||||
get_indel_info = function(ref, alt) {
|
||||
var ref_len = ref.length,
|
||||
alt_len = alt.length,
|
||||
start = 0,
|
||||
len = 1,
|
||||
type = null;
|
||||
if (alt === '-') {
|
||||
type = 'deletion';
|
||||
len = ref.length;
|
||||
}
|
||||
else if (ref.indexOf(alt) === 0 && ref_len > alt_len) {
|
||||
type = 'deletion';
|
||||
len = ref_len - alt_len;
|
||||
start = alt_len;
|
||||
}
|
||||
else if (alt.indexOf(ref) === 0 && ref_len < alt_len) {
|
||||
// Insertion.
|
||||
type = 'insertion';
|
||||
len = alt_len - ref_len;
|
||||
start = alt_len;
|
||||
}
|
||||
|
||||
return ( type !== null ? { type: type, start: start, len: len } : {} );
|
||||
};
|
||||
|
||||
// Draw.
|
||||
var locus_data,
|
||||
@@ -1488,22 +1494,14 @@ _.extend(VariantPainter.prototype, Painter.prototype, {
|
||||
|
||||
// Process alterate values to derive information about each alt.
|
||||
alt = _.map(_.flatten(alt), function(a) {
|
||||
var type,
|
||||
alt_info = {},
|
||||
delete_info = get_deletion_info(ref, a);
|
||||
if (delete_info) {
|
||||
type = 'deletion';
|
||||
_.extend(alt_info, delete_info);
|
||||
}
|
||||
// TODO: test for insertion.
|
||||
else { // SNP.
|
||||
type = 'snp';
|
||||
}
|
||||
|
||||
return _.extend(alt_info, {
|
||||
type: type,
|
||||
value: a,
|
||||
});
|
||||
var alt_info = {
|
||||
type: 'snp',
|
||||
value: a,
|
||||
start: 0
|
||||
},
|
||||
indel_info = get_indel_info(ref, a);
|
||||
|
||||
return _.extend(alt_info, indel_info);
|
||||
});
|
||||
|
||||
// Only draw locus data if it's in viewing region.
|
||||
@@ -1511,7 +1509,7 @@ _.extend(VariantPainter.prototype, Painter.prototype, {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Compute start for drawing variants marker, text.
|
||||
// Compute start for drawing variants marker, text.
|
||||
draw_x_start = Math.floor( Math.max(-0.5 * w_scale, (pos - this.view_start - 0.5) * w_scale) );
|
||||
char_x_start = Math.floor( Math.max(0, (pos - this.view_start) * w_scale) );
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1402,32 +1402,38 @@ _.extend(VariantPainter.prototype, Painter.prototype, {
|
||||
draw: function(ctx, width, height, w_scale) {
|
||||
ctx.save();
|
||||
|
||||
// Functions for detection insertions (TODO) and deletions.
|
||||
|
||||
/** Returns dictionary of information about a deletion; returns null if there no deletion.
|
||||
var
|
||||
/**
|
||||
* Returns dictionary of information about an indel; returns empty if there no indel. Assumes indel is left-aligned.
|
||||
* Dict attributes:
|
||||
* -type: 'insertion' or 'deletion'
|
||||
* -start: where the deletion starts relative to reference start
|
||||
* -len: how long the deletion is
|
||||
*/
|
||||
var get_deletion_info = function(ref, alt) {
|
||||
var ref_len = ref.length,
|
||||
alt_len = alt.length,
|
||||
start = 0,
|
||||
len = 1,
|
||||
is_delete = false;
|
||||
if (alt === '-') {
|
||||
is_delete = true;
|
||||
len = ref.length;
|
||||
}
|
||||
else if (ref.indexOf(alt) === 0 && ref_len > alt_len) {
|
||||
is_delete = true;
|
||||
len = ref_len = alt_len;
|
||||
start += alt_len;
|
||||
}
|
||||
|
||||
return ( is_delete ? { start: start, len: len } : null );
|
||||
};
|
||||
get_indel_info = function(ref, alt) {
|
||||
var ref_len = ref.length,
|
||||
alt_len = alt.length,
|
||||
start = 0,
|
||||
len = 1,
|
||||
type = null;
|
||||
if (alt === '-') {
|
||||
type = 'deletion';
|
||||
len = ref.length;
|
||||
}
|
||||
else if (ref.indexOf(alt) === 0 && ref_len > alt_len) {
|
||||
type = 'deletion';
|
||||
len = ref_len - alt_len;
|
||||
start = alt_len;
|
||||
}
|
||||
else if (alt.indexOf(ref) === 0 && ref_len < alt_len) {
|
||||
// Insertion.
|
||||
type = 'insertion';
|
||||
len = alt_len - ref_len;
|
||||
start = alt_len;
|
||||
}
|
||||
|
||||
return ( type !== null ? { type: type, start: start, len: len } : {} );
|
||||
};
|
||||
|
||||
// Draw.
|
||||
var locus_data,
|
||||
@@ -1488,22 +1494,14 @@ _.extend(VariantPainter.prototype, Painter.prototype, {
|
||||
|
||||
// Process alterate values to derive information about each alt.
|
||||
alt = _.map(_.flatten(alt), function(a) {
|
||||
var type,
|
||||
alt_info = {},
|
||||
delete_info = get_deletion_info(ref, a);
|
||||
if (delete_info) {
|
||||
type = 'deletion';
|
||||
_.extend(alt_info, delete_info);
|
||||
}
|
||||
// TODO: test for insertion.
|
||||
else { // SNP.
|
||||
type = 'snp';
|
||||
}
|
||||
|
||||
return _.extend(alt_info, {
|
||||
type: type,
|
||||
value: a,
|
||||
});
|
||||
var alt_info = {
|
||||
type: 'snp',
|
||||
value: a,
|
||||
start: 0
|
||||
},
|
||||
indel_info = get_indel_info(ref, a);
|
||||
|
||||
return _.extend(alt_info, indel_info);
|
||||
});
|
||||
|
||||
// Only draw locus data if it's in viewing region.
|
||||
@@ -1511,7 +1509,7 @@ _.extend(VariantPainter.prototype, Painter.prototype, {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Compute start for drawing variants marker, text.
|
||||
// Compute start for drawing variants marker, text.
|
||||
draw_x_start = Math.floor( Math.max(-0.5 * w_scale, (pos - this.view_start - 0.5) * w_scale) );
|
||||
char_x_start = Math.floor( Math.max(0, (pos - this.view_start) * w_scale) );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user