Skip to content

Commit

Permalink
Add Mb units for large chromosomes
Browse files Browse the repository at this point in the history
  • Loading branch information
John Davey committed May 21, 2019
1 parent 11af33d commit 206d062
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions tapestry/report/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ <h2><a name="information">Information</a></h2>
}
})

var unit = 'bp';
if (max_contig_length > 2000000) {
unit = "Mb";
}

var contig_links = {};
for (var contig_name_long in contig_alignments) {
contig_name_short = contig_names[contig_name_long];
Expand Down Expand Up @@ -403,7 +408,7 @@ <h2><a name="information">Information</a></h2>
reads.svg.selectAll("text.alignment.text").remove()
}

function build_assembly_plot(contigs, dim, windowsize) {
function build_assembly_plot(contigs, dim, windowsize, xaxis, unit) {

var assembly = {};
assembly.dim = {height: contigs.length * 29};
Expand Down Expand Up @@ -441,7 +446,7 @@ <h2><a name="information">Information</a></h2>
.attr("transform", "translate(" + (dim.width/2) + " ," + (assembly.dim.height + 45) + ")")
.style("text-anchor", "middle")
.attr("fill", "black")
.text("Position (bp)");
.text("Position (" + unit + ")");

assembly.svg.selectAll("g.contig")
.data(contigs, function(d) { return d.name })
Expand All @@ -456,7 +461,7 @@ <h2><a name="information">Information</a></h2>
return assembly;
}

function build_reads_plot(read_alignments, dim, max_read_depth, assembly, ploidy_depths) {
function build_reads_plot(read_alignments, dim, max_read_depth, assembly, ploidy_depths, xaxis) {

var reads = {};

Expand Down Expand Up @@ -527,7 +532,7 @@ <h2><a name="information">Information</a></h2>
return reads;
}

function plot_read_alignments(alignments, dim, reads, contig) {
function plot_read_alignments(alignments, dim, reads, contig, unit) {

// contig_read_alignments:
// 0 read start including left clip
Expand All @@ -548,7 +553,7 @@ <h2><a name="information">Information</a></h2>
.attr("transform", "translate(" + (dim.width/2) + " ," + (reads.dim.height + 45) + ")")
.style("text-anchor", "middle")
.attr("fill", "black")
.text(contig + " Position (bp)");
.text(contig + " Position (" + unit + ")");

reads.svg.selectAll("line.contig_boundary").remove()

Expand Down Expand Up @@ -845,11 +850,18 @@ <h2><a name="information">Information</a></h2>
.domain([min_x_pos-leftpad, max_x_pos])
.range([0, dim.width]);

var xaxis = d3.axisBottom(dim.xscale);

assembly = build_assembly_plot(contigs, dim, windowsize);
var xaxis = d3.axisBottom(dim.xscale)
.tickFormat(function (d) {
if (max_x_pos > 2000000) {
return d3.format(",.1f")(d/1000000)
}
return d3.format(",.0f")(d)
});

assembly = build_assembly_plot(contigs, dim, windowsize, xaxis, unit);

reads = build_reads_plot(read_alignments, dim, max_read_depth, assembly, ploidy_depths);
reads = build_reads_plot(read_alignments, dim, max_read_depth, assembly, ploidy_depths, xaxis);

$.fn.editable.defaults.mode = 'inline';
$('#options_table').bootstrapTable({data: options});
Expand All @@ -865,7 +877,7 @@ <h2><a name="information">Information</a></h2>
data: contigs,
onPostBody: function() { update_assembly() },
onCheck: function(row) {
plot_read_alignments(read_alignments[row.longname], dim, reads, contig_names[row.longname]);
plot_read_alignments(read_alignments[row.longname], dim, reads, contig_names[row.longname], unit);
},
onClickCell: function(field, value, row, $element) {
if (field === 'included') {
Expand Down

0 comments on commit 206d062

Please sign in to comment.