schneebergerlab/plotsr

How is track height determined?

KewinOgink opened this issue · 4 comments

Hello, I noticed that I have a region with several SNP tracks, where I know the amount of SNPs per track (written here for 2.3-2.4Mb and I use the same bin width of 1kb for all tracks. However, the number/sum of variants is not matching the visualization:
image.

I then made a dummy file to investigate using bin width 4 and 3 tracks with different densities

%%writefile ../tmp/plotsr/fake_1_per_10.bed
chrA01	0	1
chrA01	10	11
chrA01	20	21
chrA01	30	31
chrA01	40	41
chrA01	50	51

%%writefile ../tmp/plotsr/fake_2_per_10.bed
chrA01	1	2
chrA01	2	3
chrA01	10	11
chrA01	11	12
chrA01	20	21
chrA01	21	22
chrA01	30	31
chrA01	31	32
chrA01	40	41
chrA01	41	42
chrA01	50	51
chrA01	51	52

%%writefile ../tmp/plotsr/fake_10_per_10.bed
chrA01	0	10
chrA01	21	30
chrA01	41	50

%%writefile ../tmp/plotsr/fake.out
chrA01	0	1000	-	-	chrA01	0	1000	SYN1	-	SYN	-

%%writefile ../tmp/plotsr/fake_w4.track
#file	name	tags
../tmp/plotsr/fake_1_per_10.bed	fake_1_per_10	ft:bed;bw:4;nc:black;ns:8;nf:DejaVu Sans;lc:sienna;lw:0.25;bc:lightblue;ba:0.5;tt:f;ti:1
../tmp/plotsr/fake_2_per_10.bed	fake_2_per_10	ft:bed;bw:4;nc:black;ns:8;nf:DejaVu Sans;lc:sienna;lw:0.25;bc:lightblue;ba:0.5;tt:f;ti:2
../tmp/plotsr/fake_10_per_10.bed	fake_10_per_10	ft:bed;bw:4;nc:black;ns:8;nf:DejaVu Sans;lc:sienna;lw:0.25;bc:lightblue;ba:0.5;tt:f;ti:3

and ran plotsr like this

min_sv_size=0
chrom=chrA01
track_window_size=4
ml plotsr

plotsr \
    --sr ${wd}/fake.out \
    --genomes ${wd}/../${sample}.genomes.txt \
    --tracks ${wd}/fake_w${track_window_size}.track \
    --reg ref:$chrom:1-60 \
    -S 0.4 -o R7 -W 10 -H 5 -f 8 -s ${min_sv_size} \
    -o $wd/plot_test_${chrom}:1-60_s${min_sv_size}_tracks_w${track_window_size}_h.png

result:
image

Given the snp density of track 2 is 2x that of track 1, why is the pattern the same? And why does track 3 not show a full brown block, as no matter where the bin starts, it 10 bp spans the bin 2.5x.

I then ran it with bin widht 1 and then I do get this:
image

This result that looks correct. However, this is not feasible for the entire genome. Any suggestions? I was not sure how/if this relates to #34

Many thanks!

For each track, the height is normalised by the maximum value in that track, i.e., the y-axis for the tracks are on different scales. Fake1 and fake2 have same apparent pattern for BW=4 because the relative distribution along the chromosome is same.

Regarding fake3, consider the row ChrA01:21-30, the corresponding bins of interest would be [20, 21, 22, 23] , [24, 25,26, 27], and [28, 29, 30, 31] and for them the bin value (for the given range in BED file) would be 0.75, 1, and 0.5 respectively (note: in BED file, the start position is included but the end position is not). Therefore, the tracks for ChrA01:21-30 and ChrA01:41-50 are correct. The track for ChrA01:0-10 is wrong and corresponds to ChrA01:1-10. Could you please recheck that the plot that you shared corresponds to the given tracks.

Thanks for the explanation. It makes sense. So if in fake1 1/4 is the highest relative value, this will be ymax, whereas if for fake2 it is 2/4 this will be ymax.

For me it is relevant to have the tracks sharing the same y axis. Therefore, one working (though not ideal) solution is to add a fake full window. I tested it to be both outside (100-110bp) and inside (51-60bp) the plotting range (0-60bp), and found that only if I have the fake full window within the plotting range it works, like this:

%%writefile ../tmp/plotsr/fake_1_per_10.bed
chrA01	1	2
chrA01	11	12
chrA01	21	22
chrA01	31	32
chrA01	41	42
chrA01	51	60  

%%writefile ../tmp/plotsr/fake_2_per_10.bed
chrA01	1	2
chrA01	2	3
chrA01	11	12
chrA01	12	13
chrA01	21	22
chrA01	22	23
chrA01	31	32
chrA01	32	33
chrA01	41	42
chrA01	42	43
chrA01	51	60

%%writefile ../tmp/plotsr/fake_10_per_10.bed
chrA01	0	10
chrA01	20	30
chrA01	51	60

image

And indeed I think perhaps one coordinate was wrong as you pointed out.

I agree, that there is merit in having same yaxis across different tracks. Might be possible to add this feature in future updates.

The commit adds norm config option for base.cfg that allows to toggle track height normalisation.