diff --git a/docs/content/all_default_properties.csv b/docs/content/all_default_properties.csv index c5f65aed..197a77f1 100644 --- a/docs/content/all_default_properties.csv +++ b/docs/content/all_default_properties.csv @@ -1,76 +1,87 @@ -parameter,x_axis,epilogos,links,domains,bed,gtf,narrow_peak,bigwig,bedgraph,bedgraph_matrix,hlines,hic_matrix,hic_matrix_square,maf,scalebar,vlines,vhighlight -overlay_previous,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,, -where,bottom,,,,,,,,,,,,,,left,, -fontsize,15,,,,12,12,,,,,,,,,12,, -categories_file,,not set,,,,,,,,,,,,,,, -orientation,,not set,not set,not set,not set,not set,not set,not set,not set,not set,not set,not set,not set,not set,,, -links_type,,,arcs,,,,,,,,,,,,,, -line_width,,,not set,0.5,0.5,0.5,1,,,,0.5,,,0.5,0.5,0.5,0.5 -line_style,,,solid,,,,,,,,solid,,,,,dashed, -color,,,blue,#1f78b4,#1f78b4,#1f78b4,#FF000080,#33a02c,#a6cee3,,black,,,,black,black,yellow -alpha,,,0.8,,,,,1,1,,1,,,,1,0.7,0.5 -max_value,,,not set,not set,not set,,not set,not set,not set,not set,not set,not set,not set,,,, -min_value,,,not set,not set,not set,,,not set,not set,not set,not set,not set,not set,,,, -ylim,,,not set,,,,,,,,,,,,,, -compact_arcs_level,,,0,,,,,,,,,,,,,, -use_middle,,,false,,,,,,false,,,,,,,, -region2,,,not set,,,,,,,,,,not set,,,, -border_color,,,,black,black,black,,,,,,,,,,,none -prefered_name,,,,transcript_name,transcript_name,transcript_name,,,,,,,,,,, -merge_transcripts,,,,false,false,false,,,,,,,,,,, -labels,,,,,true,true,,,,,,,,,,, -style,,,,,flybase,flybase,,,,,,,,,,, -display,,,,,stacked,stacked,,,,,,,,,,, -max_labels,,,,,60,60,,,,,,,,,,, -merge_overlapping_exons,,,,,false,false,,,,,,,,,,, -global_max_row,,,,,false,false,,,,,,,,,,, -gene_rows,,,,,not set,not set,,,,,,,,,,, -arrow_interval,,,,,2,2,,,,,,,,,,, -arrowhead_included,,,,,false,false,,,,,,,,,,, -arrowhead_fraction,,,,,0.004,0.004,,,,,,,,,,, -color_utr,,,,,grey,grey,,,,,,,,,,, -color_backbone,,,,,black,black,,,,,,,,,,, -height_utr,,,,,1,1,,,,,,,,,,, -arrow_length,,,,,not set,not set,,,,,,,,,,, -height_intron,,,,,0.5,0.5,,,,,,,,,,, -all_labels_inside,,,,,false,false,,,,,,,,,,, -labels_in_margin,,,,,false,false,,,,,,,,,,, -fontstyle,,,,,normal,normal,,,,,,,,,,, -color_arrow,,,,,black,black,,,,,,,,,,, -show_data_range,,,,,,,true,true,true,true,true,,,,,, -show_labels,,,,,,,true,,,,,,,,,, -use_summit,,,,,,,true,,,,,,,,,, -width_adjust,,,,,,,1.5,,,,,,,,,, -type,,,,,,,peak,fill,fill,matrix,,,,,,, -negative_color,,,,,,,,not set,not set,,,,,,,, -nans_to_zeros,,,,,,,,false,false,,,,,,,, -summary_method,,,,,,,,mean,not set,,,,,,,, -number_of_bins,,,,,,,,700,700,,,,,,,, -transform,,,,,,,,no,no,,,no,no,,,, -log_pseudocount,,,,,,,,0,0,,,,,,,, -y_axis_values,,,,,,,,transformed,transformed,,,,,,,, -second_file*,,,,,,,,not set,not set,,,,,,,, -operation*,,,,,,,,file,file,,,,,,,, -grid,,,,,,,,false,false,,,,,,,, -rasterize,,,,,,,,,false,true,,true,true,false,,, -pos_score_in_bin,,,,,,,,,,center,,,,,,, -plot_horizontal_lines,,,,,,,,,,false,,,,,,, -colormap,,,,,,,,,,viridis,,RdYlBu_r,RdYlBu_r,,,, -individual_color,,,,,,,,,,grey,,,,,,, -summary_color,,,,,,,,,,#1f77b4,,,,,,, -depth,,,,,,,,,,,,100000,,,,, -show_masked_bins,,,,,,,,,,,,false,false,,,, -scale_factor,,,,,,,,,,,,1,1,,,, -file_index,,,,,,,,,,,,,,not set,,, -color_identical,,,,,,,,,,,,,,black,,, -color_mismatch,,,,,,,,,,,,,,grey,,, -color_gap,,,,,,,,,,,,,,lightgrey,,, -species_order,,,,,,,,,,,,,,not set,,, -species_labels,,,,,,,,,,,,,,not set,,, -species_order_only,,,,,,,,,,,,,,false,,, -display_ref_seq,,,,,,,,,,,,,,false,,, -x_center,,,,,,,,,,,,,,,not set,, -size,,,,,,,,,,,,,,,not set,, -scalebar_start_position,,,,,,,,,,,,,,,not set,, -scalebar_end_position,,,,,,,,,,,,,,,not set,, -zorder,,,,,,,,,,,,,,,,10,-100 +parameter,x_axis,epilogos,links,domains,bed,gtf,narrow_peak,bigwig,bedgraph,bedgraph_matrix,hlines,hic_matrix,hic_matrix_square,maf,scalebar,sashimiBigWig,vlines,vhighlight +overlay_previous,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,, +where,bottom,,,,,,,,,,,,,,left,,, +fontsize,15,,,,12,12,,,,,,,,,12,,, +categories_file,,not set,,,,,,,,,,,,,,,, +orientation,,not set,not set,not set,not set,not set,not set,not set,not set,not set,not set,not set,not set,not set,,not set,, +links_type,,,arcs,,,,,,,,,,,,,,, +line_width,,,not set,0.5,0.5,0.5,1,,,,0.5,,,0.5,0.5,,0.5,0.5 +line_style,,,solid,,,,,,,,solid,,,,,,dashed, +color,,,blue,#1f78b4,#1f78b4,#1f78b4,#FF000080,#33a02c,#a6cee3,,black,,,,black,,black,yellow +alpha,,,0.8,,,,,1,1,,1,,,,1,1,0.7,0.5 +max_value,,,not set,not set,not set,,not set,not set,not set,not set,not set,not set,not set,,,not set,, +min_value,,,not set,not set,not set,,,not set,not set,not set,not set,not set,not set,,,not set,, +ylim,,,not set,,,,,,,,,,,,,,, +compact_arcs_level,,,0,,,,,,,,,,,,,,, +use_middle,,,false,,,,,,false,,,,,,,,, +region2,,,not set,,,,,,,,,,not set,,,,, +border_color,,,,black,black,black,,,,,,,,,,,,none +prefered_name,,,,transcript_name,transcript_name,transcript_name,,,,,,,,,,,, +merge_transcripts,,,,false,false,false,,,,,,,,,,,, +labels,,,,,true,true,,,,,,,,,,,, +style,,,,,flybase,flybase,,,,,,,,,,,, +display,,,,,stacked,stacked,,,,,,,,,,,, +max_labels,,,,,60,60,,,,,,,,,,,, +merge_overlapping_exons,,,,,false,false,,,,,,,,,,,, +global_max_row,,,,,false,false,,,,,,,,,,,, +gene_rows,,,,,not set,not set,,,,,,,,,,,, +arrow_interval,,,,,2,2,,,,,,,,,,,, +arrowhead_included,,,,,false,false,,,,,,,,,,,, +arrowhead_fraction,,,,,0.004,0.004,,,,,,,,,,,, +color_utr,,,,,grey,grey,,,,,,,,,,,, +color_backbone,,,,,black,black,,,,,,,,,,,, +height_utr,,,,,1,1,,,,,,,,,,,, +arrow_length,,,,,not set,not set,,,,,,,,,,,, +height_intron,,,,,0.5,0.5,,,,,,,,,,,, +all_labels_inside,,,,,false,false,,,,,,,,,,,, +labels_in_margin,,,,,false,false,,,,,,,,,,,, +fontstyle,,,,,normal,normal,,,,,,,,,,,, +color_arrow,,,,,black,black,,,,,,,,,,,, +show_data_range,,,,,,,true,true,true,true,true,,,,,true,, +show_labels,,,,,,,true,,,,,,,,,,, +use_summit,,,,,,,true,,,,,,,,,,, +width_adjust,,,,,,,1.5,,,,,,,,,,, +type,,,,,,,peak,fill,fill,matrix,,,,,,fill,, +negative_color,,,,,,,,not set,not set,,,,,,,not set,, +nans_to_zeros,,,,,,,,false,false,,,,,,,false,, +summary_method,,,,,,,,mean,not set,,,,,,,mean,, +number_of_bins,,,,,,,,700,700,,,,,,,700,, +transform,,,,,,,,no,no,,,no,no,,,no,, +log_pseudocount,,,,,,,,0,0,,,,,,,0,, +y_axis_values,,,,,,,,transformed,transformed,,,,,,,transformed,, +second_file*,,,,,,,,not set,not set,,,,,,,,, +operation*,,,,,,,,file,file,,,,,,,,, +grid,,,,,,,,false,false,,,,,,,false,, +rasterize,,,,,,,,,false,true,,true,true,false,,,, +pos_score_in_bin,,,,,,,,,,center,,,,,,,, +plot_horizontal_lines,,,,,,,,,,false,,,,,,,, +colormap,,,,,,,,,,viridis,,RdYlBu_r,RdYlBu_r,,,,, +individual_color,,,,,,,,,,grey,,,,,,,, +summary_color,,,,,,,,,,#1f77b4,,,,,,,, +depth,,,,,,,,,,,,100000,,,,,, +show_masked_bins,,,,,,,,,,,,false,false,,,,, +scale_factor,,,,,,,,,,,,1,1,,,,, +file_index,,,,,,,,,,,,,,not set,,,, +color_identical,,,,,,,,,,,,,,black,,,, +color_mismatch,,,,,,,,,,,,,,grey,,,, +color_gap,,,,,,,,,,,,,,lightgrey,,,, +species_order,,,,,,,,,,,,,,not set,,,, +species_labels,,,,,,,,,,,,,,not set,,,, +species_order_only,,,,,,,,,,,,,,false,,,, +display_ref_seq,,,,,,,,,,,,,,false,,,, +x_center,,,,,,,,,,,,,,,not set,,, +size,,,,,,,,,,,,,,,not set,,, +scalebar_start_position,,,,,,,,,,,,,,,not set,,, +scalebar_end_position,,,,,,,,,,,,,,,not set,,, +bw_color,,,,,,,,,,,,,,,,#33a02c,, +link_color,,,,,,,,,,,,,,,,blue,, +link_alpha,,,,,,,,,,,,,,,,1,, +link_line_width,,,,,,,,,,,,,,,,not set,, +link_line_style,,,,,,,,,,,,,,,,solid,, +link_max_value,,,,,,,,,,,,,,,,not set,, +link_min_value,,,,,,,,,,,,,,,,not set,, +link_scale_height,,,,,,,,,,,,,,,,1,, +link_scale_line_width,,,,,,,,,,,,,,,,2,, +link_labels,,,,,,,,,,,,,,,,true,, +link_fontsize,,,,,,,,,,,,,,,,not set,, +zorder,,,,,,,,,,,,,,,,,10,-100 diff --git a/docs/content/all_default_properties_rst.txt b/docs/content/all_default_properties_rst.txt index c5705aa3..a59a8a3a 100644 --- a/docs/content/all_default_properties_rst.txt +++ b/docs/content/all_default_properties_rst.txt @@ -1,82 +1,93 @@ -=============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== -parameter :doc:`tracks/x_axis` :doc:`tracks/epilogos` :doc:`tracks/links` :doc:`tracks/domains` :doc:`tracks/bed` :doc:`tracks/gtf` :doc:`tracks/narrow_peak` :doc:`tracks/bigwig` :doc:`tracks/bedgraph` :doc:`tracks/bedgraph_matrix` :doc:`tracks/hlines` :doc:`tracks/hic_matrix` :doc:`tracks/hic_matrix_square` :doc:`tracks/maf` :doc:`tracks/scalebar` :doc:`tracks/vlines` :doc:`tracks/vhighlight` -=============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== -overlay_previous no no no no no no no no no no no no no no no -where bottom left -fontsize 15 12 12 12 -categories_file not set -orientation not set not set not set not set not set not set not set not set not set not set not set not set not set -links_type arcs -line_width not set 0.5 0.5 0.5 1 0.5 0.5 0.5 0.5 0.5 -line_style solid solid dashed -color blue #1f78b4 #1f78b4 #1f78b4 #FF000080 #33a02c #a6cee3 black black black yellow -alpha 0.8 1 1 1 1 0.7 0.5 -max_value not set not set not set not set not set not set not set not set not set not set -min_value not set not set not set not set not set not set not set not set not set -ylim not set -compact_arcs_level 0 -use_middle false false -region2 not set not set -border_color black black black none -prefered_name transcript_name transcript_name transcript_name -merge_transcripts false false false -labels true true -style flybase flybase -display stacked stacked -max_labels 60 60 -merge_overlapping_exons false false -global_max_row false false -gene_rows not set not set -arrow_interval 2 2 -arrowhead_included false false -arrowhead_fraction 0.004 0.004 -color_utr grey grey -color_backbone black black -height_utr 1 1 -arrow_length not set not set -height_intron 0.5 0.5 -all_labels_inside false false -labels_in_margin false false -fontstyle normal normal -color_arrow black black -show_data_range true true true true true -show_labels true -use_summit true -width_adjust 1.5 -type peak fill fill matrix -negative_color not set not set -nans_to_zeros false false -summary_method mean not set -number_of_bins 700 700 -transform no no no no -log_pseudocount 0 0 -y_axis_values transformed transformed -second_file* not set not set -operation* file file -grid false false -rasterize false true true true false -pos_score_in_bin center -plot_horizontal_lines false -colormap viridis RdYlBu_r RdYlBu_r -individual_color grey -summary_color #1f77b4 -depth 100000 -show_masked_bins false false -scale_factor 1 1 -file_index not set -color_identical black -color_mismatch grey -color_gap lightgrey -species_order not set -species_labels not set -species_order_only false -display_ref_seq false -x_center not set -size not set -scalebar_start_position not set -scalebar_end_position not set -zorder 10 -100 -=============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== +=============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== +parameter :doc:`tracks/x_axis` :doc:`tracks/epilogos` :doc:`tracks/links` :doc:`tracks/domains` :doc:`tracks/bed` :doc:`tracks/gtf` :doc:`tracks/narrow_peak` :doc:`tracks/bigwig` :doc:`tracks/bedgraph` :doc:`tracks/bedgraph_matrix` :doc:`tracks/hlines` :doc:`tracks/hic_matrix` :doc:`tracks/hic_matrix_square` :doc:`tracks/maf` :doc:`tracks/scalebar` :doc:`tracks/sashimiBigWig` :doc:`tracks/vlines` :doc:`tracks/vhighlight` +=============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== +overlay_previous no no no no no no no no no no no no no no no no +where bottom left +fontsize 15 12 12 12 +categories_file not set +orientation not set not set not set not set not set not set not set not set not set not set not set not set not set not set +links_type arcs +line_width not set 0.5 0.5 0.5 1 0.5 0.5 0.5 0.5 0.5 +line_style solid solid dashed +color blue #1f78b4 #1f78b4 #1f78b4 #FF000080 #33a02c #a6cee3 black black black yellow +alpha 0.8 1 1 1 1 1 0.7 0.5 +max_value not set not set not set not set not set not set not set not set not set not set not set +min_value not set not set not set not set not set not set not set not set not set not set +ylim not set +compact_arcs_level 0 +use_middle false false +region2 not set not set +border_color black black black none +prefered_name transcript_name transcript_name transcript_name +merge_transcripts false false false +labels true true +style flybase flybase +display stacked stacked +max_labels 60 60 +merge_overlapping_exons false false +global_max_row false false +gene_rows not set not set +arrow_interval 2 2 +arrowhead_included false false +arrowhead_fraction 0.004 0.004 +color_utr grey grey +color_backbone black black +height_utr 1 1 +arrow_length not set not set +height_intron 0.5 0.5 +all_labels_inside false false +labels_in_margin false false +fontstyle normal normal +color_arrow black black +show_data_range true true true true true true +show_labels true +use_summit true +width_adjust 1.5 +type peak fill fill matrix fill +negative_color not set not set not set +nans_to_zeros false false false +summary_method mean not set mean +number_of_bins 700 700 700 +transform no no no no no +log_pseudocount 0 0 0 +y_axis_values transformed transformed transformed +second_file* not set not set +operation* file file +grid false false false +rasterize false true true true false +pos_score_in_bin center +plot_horizontal_lines false +colormap viridis RdYlBu_r RdYlBu_r +individual_color grey +summary_color #1f77b4 +depth 100000 +show_masked_bins false false +scale_factor 1 1 +file_index not set +color_identical black +color_mismatch grey +color_gap lightgrey +species_order not set +species_labels not set +species_order_only false +display_ref_seq false +x_center not set +size not set +scalebar_start_position not set +scalebar_end_position not set +bw_color #33a02c +link_color blue +link_alpha 1 +link_line_width not set +link_line_style solid +link_max_value not set +link_min_value not set +link_scale_height 1 +link_scale_line_width 2 +link_labels true +link_fontsize not set +zorder 10 -100 +=============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== =============================== \* While pyGenomeTracks can convert coverage tracks on the fly, this might be a time-consuming step, especially on large files and if you want to replot many times. In this situation, we recommend using the deepTools suite to convert your files in advance. For example `bamCoverage `_ or `bamCompare `_ \ No newline at end of file diff --git a/docs/content/all_possible_properties.txt b/docs/content/all_possible_properties.txt index d5d4976c..3c0f5ea2 100644 --- a/docs/content/all_possible_properties.txt +++ b/docs/content/all_possible_properties.txt @@ -1,6 +1,6 @@ - **overlay_previous**: - - for *x_axis, epilogos, links, domains, bed, gtf, narrow_peak, bigwig, bedgraph, bedgraph_matrix, hlines, hic_matrix, hic_matrix_square, maf, scalebar, spacer, fasta*: no, yes, share-y + - for *x_axis, epilogos, links, domains, bed, gtf, narrow_peak, bigwig, bedgraph, bedgraph_matrix, hlines, hic_matrix, hic_matrix_square, maf, scalebar, spacer, sashimiBigWig, fasta*: no, yes, share-y - **where**: @@ -10,7 +10,7 @@ - **orientation**: - - for *epilogos, links, domains, bed, gtf, narrow_peak, bigwig, bedgraph, bedgraph_matrix, hlines, hic_matrix, hic_matrix_square, maf*: inverted, not set + - for *epilogos, links, domains, bed, gtf, narrow_peak, bigwig, bedgraph, bedgraph_matrix, hlines, hic_matrix, hic_matrix_square, maf, sashimiBigWig*: inverted, not set - **links_type**: @@ -76,7 +76,7 @@ - **show_data_range**: - - for *narrow_peak, bigwig, bedgraph, bedgraph_matrix, hlines*: true, false + - for *narrow_peak, bigwig, bedgraph, bedgraph_matrix, hlines, sashimiBigWig*: true, false - **show_labels**: @@ -88,27 +88,27 @@ - **summary_method**: - - for *bigwig*: mean, average, max, min, stdev, dev, coverage, cov, sum - - for *bedgraph*: mean, average, max, min, stdev, dev, coverage, cov, sum, not set -- **transform**: + - for *bigwig, sashimiBigWig*: mean, average, max, min, stdev, dev, coverage, cov, sum - - for *bigwig, bedgraph*: no, log, log1p, -log, log2, log10 +- **transform**: - for *hic_matrix, hic_matrix_square*: no, log, log1p, -log + - for *bigwig, bedgraph, sashimiBigWig*: no, log, log1p, -log, log2, log10 + - **y_axis_values**: - - for *bigwig, bedgraph*: original, transformed + - for *bigwig, bedgraph, sashimiBigWig*: original, transformed - **nans_to_zeros**: - - for *bigwig, bedgraph*: true, false + - for *bigwig, bedgraph, sashimiBigWig*: true, false - **grid**: - - for *bigwig, bedgraph*: true, false + - for *bigwig, bedgraph, sashimiBigWig*: true, false - **rasterize**: @@ -134,3 +134,11 @@ - for *maf*: true, false +- **link_line_style**: + + - for *sashimiBigWig*: solid, dashed, dotted, dashdot + +- **link_labels**: + + - for *sashimiBigWig*: true, false + diff --git a/docs/content/all_tracks.rst b/docs/content/all_tracks.rst index b70235b6..f5965e88 100644 --- a/docs/content/all_tracks.rst +++ b/docs/content/all_tracks.rst @@ -18,6 +18,7 @@ All available tracks and types tracks/links tracks/maf tracks/narrow_peak + tracks/sashimiBigWig tracks/scalebar tracks/spacer tracks/vhighlight diff --git a/docs/content/tracks/auto/sashimiBigWig_deduced_from_code.txt b/docs/content/tracks/auto/sashimiBigWig_deduced_from_code.txt new file mode 100644 index 00000000..34f20f9e --- /dev/null +++ b/docs/content/tracks/auto/sashimiBigWig_deduced_from_code.txt @@ -0,0 +1,64 @@ +Necessary: +^^^^^^^^^^ +- **file** + +- **link_file** + +Optional: +^^^^^^^^^ +- **title**: Put here a title which will apprear on the right. + +- **height**: `0.5` (default) or float above 0. + +- **overlay_previous**: `no` (default) or yes or share-y. + +- **orientation**: by default this option is not set but you can also put: inverted. + +- **alpha**: `1` (default) or any float above 0 below 1 + +- **max_value**: by default this option is not set but you can also put: any float + +- **min_value**: by default this option is not set but you can also put: any float + +- **show_data_range**: `true` (default) or false. + +- **type**: `fill` (default) + +- **negative_color**: by default this option is not set + +- **nans_to_zeros**: `false` (default) or true. + +- **summary_method**: `mean` (default) or average, max, min, stdev, dev, coverage, cov or sum. + +- **number_of_bins**: `700` (default) or any integer above 1 + +- **transform**: `no` (default) or log, log1p, -log, log2 or log10. + +- **log_pseudocount**: `0` (default) or any float + +- **y_axis_values**: `transformed` (default) or original. + +- **grid**: `false` (default) or true. + +- **bw_color**: `#33a02c` (default) + +- **link_color**: `blue` (default) + +- **link_alpha**: `1` (default) or any float above 0 below 1 + +- **link_line_width**: by default this option is not set but you can also put: any float above 0 + +- **link_line_style**: `solid` (default) or dashed, dotted or dashdot. + +- **link_max_value**: by default this option is not set but you can also put: any float + +- **link_min_value**: by default this option is not set but you can also put: any float + +- **link_scale_height**: `1` (default) or any float above 0 + +- **link_scale_line_width**: `2` (default) or any float above 0 + +- **link_labels**: `true` (default) or false. + +- **link_fontsize**: by default this option is not set but you can also put: any float above 0 + diff --git a/docs/content/tracks/auto/sashimiBigWig_options_text.txt b/docs/content/tracks/auto/sashimiBigWig_options_text.txt new file mode 100644 index 00000000..742dc0eb --- /dev/null +++ b/docs/content/tracks/auto/sashimiBigWig_options_text.txt @@ -0,0 +1,97 @@ + +# title of track (plotted on the right side) +title = +# height of track in cm (ignored if the track is overlay on top the previous track) +height = 2 +# if you want to plot the track upside-down: +# orientation = inverted +# if you want to plot the track on top of the previous track. Options are 'yes' or 'share-y'. +# For the 'share-y' option the y axis values is shared between this plot and the overlay plot. +# Otherwise, each plot use its own scale +#overlay_previous = yes + +bw_color = #666666 +# To use a different color for negative values +#negative_color = red +# To use transparency, you can use alpha +# default is 1 +#alpha = 0.5 +# the default for min_value and max_value is 'auto' which means that the scale will go +# roughly from the minimum value found in the region plotted to the maximum value found. +min_value = 0 +#max_value = auto +# The number of bins takes the region to be plotted and divides it +# into the number of bins specified +# Then, at each bin the bigwig mean value is computed and plotted. +# A lower number of bins produces a coarser tracks +number_of_bins = 700 +# to convert missing data (NaNs) into zeros. Otherwise, missing data is not plotted. +nans_to_zeros = true +# The possible summary methods are given by pyBigWig: +# mean/average/stdev/dev/max/min/cov/coverage/sum +# default is mean +summary_method = mean +# for type, the options are: line, points, fill. Default is fill +# to add the preferred line width or point size use: +# type = line:lw where lw (linewidth) is float +# similarly points:ms sets the point size (markersize (ms) to the given float +#type = line:0.5 +#type = points:0.5 +# set show_data_range to false to hide the text on the left showing the data range +show_data_range = true +# To log transform your data you can also use transform and log_pseudocount: +# For the transform values: +# 'log1p': transformed_values = log(1 + initial_values) +# 'log': transformed_values = log(log_pseudocount + initial_values) +# 'log2': transformed_values = log2(log_pseudocount + initial_values) +# 'log10': transformed_values = log10(log_pseudocount + initial_values) +# '-log': transformed_values = - log(log_pseudocount + initial_values) +# For example: +#tranform = log +#log_pseudocount = 2 +# When a transformation is applied, by default the y axis +# gives the transformed values, if you prefer to see +# the original values: +#y_axis_values = original +# If you want to have a grid on the y-axis +#grid = true +## Links customization +# The link file should be a BED file where the score +# is in the 5th column +#link_file = +# If the bed file contains a column for color (column 9), then this color can be used by +# setting: +#link_color = bed_rgb +# if link_color is a valid colormap name (like RbBlGn), then the score (column 5) is mapped +# to the colormap. +# In this case, the the link_min_value and link_max_value for the score can be provided, otherwise +# the maximum score and minimum score found are used. +#link_color = RdYlBu +#link_min_value=0 +#link_max_value=100 +# If the link_color is simply a color name, then this link_color is used and the score is not considered for the color. +link_color = darkblue +# To use transparency, you can use link_alpha +# default is 1 +#link_alpha = 0.5 +# options for link_line_style are 'solid', 'dashed', 'dotted', and 'dashdot' +link_line_style = solid +# The link in Sashimi plot is a Bezier curve. +# The height of the curve is calculated from the length of the intron. +# When the y-axis in bigwig track is different, the height of curve needs to be scaled. +link_scale_height = 1 +# The line width for links is proportion to the numbers in the fifth column of the BED file (PSI). +# But the absolute width is calculated from the supplied numbers, which can look too thin or too wide sometimes. +# Use link_scale_line_width to scale the absolute line widths. +# You may need to try several values to get a satisfying result. +# Use this to scale Sashimi line width if the links are too thin or too wide. +#link_scale_line_width = 3 +# Set link_line_width if you do not want width of links to scale with score (PSI). +# This overwrites link_scale_line_width. +#link_line_width = 2 +# Set this to true to label scores (PSI) on links +link_labels = true +# optional: font size can be given to override the default size +#link_fontsize = 10 +file_type = sashimiBigWig + \ No newline at end of file diff --git a/docs/content/tracks/sashimiBigWig.rst b/docs/content/tracks/sashimiBigWig.rst new file mode 100644 index 00000000..9d8f4a45 --- /dev/null +++ b/docs/content/tracks/sashimiBigWig.rst @@ -0,0 +1,18 @@ +sashimiBigWig +========== + +Description +----------- + +Parameters +---------- + +.. include:: auto/sashimiBigWig_deduced_from_code.txt + +Output of ``make_tracks_file``: +------------------------------- + +.. literalinclude:: auto/sashimiBigWig_options_text.txt + :language: INI + + diff --git a/examples/avg_chr2-231091223_231109786_231113600_0.bw b/examples/avg_chr2-231091223_231109786_231113600_0.bw new file mode 120000 index 00000000..b949c50d --- /dev/null +++ b/examples/avg_chr2-231091223_231109786_231113600_0.bw @@ -0,0 +1 @@ +../pygenometracks/tests/test_data/avg_chr2-231091223_231109786_231113600_0.bw \ No newline at end of file diff --git a/examples/avg_chr2-231091223_231109786_231113600_1.bw b/examples/avg_chr2-231091223_231109786_231113600_1.bw new file mode 100644 index 00000000..357fca5f Binary files /dev/null and b/examples/avg_chr2-231091223_231109786_231113600_1.bw differ diff --git a/examples/avg_chr2-231091223_231109786_231113600_2.bw b/examples/avg_chr2-231091223_231109786_231113600_2.bw new file mode 100644 index 00000000..bbb2d2e9 Binary files /dev/null and b/examples/avg_chr2-231091223_231109786_231113600_2.bw differ diff --git a/examples/chr2-231091223_231109786_231113600.ini b/examples/chr2-231091223_231109786_231113600.ini new file mode 100644 index 00000000..da581605 --- /dev/null +++ b/examples/chr2-231091223_231109786_231113600.ini @@ -0,0 +1,65 @@ + +[spacer] +height = 0.25 + +[scale] +title = +height = 0.1 +where = right +fontsize = 4 +file_type = scalebar + +[spacer] +height = 0.25 + +[avg_chr2-231091223_231109786_231113600_0] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = 0 +height = 1 +bw_color = darkblue +number_of_bins = 7000 +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_color = darkblue +link_fontsize = 4 +link_line_width = 0.5 +file_type = sashimiBigWig + +[spacer] +height = 0.1 + +[avg_chr2-231091223_231109786_231113600_1] +file = avg_chr2-231091223_231109786_231113600_1.bw +link_file = chr2-231091223_231109786_231113600_1.sashimi +title = 1 +height = 1 +bw_color = purple +number_of_bins = 7000 +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_color = purple +link_fontsize = 4 +link_scale_line_width = 10 +link_labels = false +file_type = sashimiBigWig + +[spacer] +height = 0.1 + +[avg_chr2-231091223_231109786_231113600_2] +file = avg_chr2-231091223_231109786_231113600_2.bw +link_file = chr2-231091223_231109786_231113600_2.sashimi +title = 2 +height = 1 +bw_color = orange +number_of_bins = 7000 +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_color = orange +link_fontsize = 4 +link_scale_line_width = 10 +file_type = sashimiBigWig diff --git a/examples/chr2-231091223_231109786_231113600_0.sashimi b/examples/chr2-231091223_231109786_231113600_0.sashimi new file mode 120000 index 00000000..008a6774 --- /dev/null +++ b/examples/chr2-231091223_231109786_231113600_0.sashimi @@ -0,0 +1 @@ +../pygenometracks/tests/test_data/chr2-231091223_231109786_231113600_0.sashimi \ No newline at end of file diff --git a/examples/chr2-231091223_231109786_231113600_1.sashimi b/examples/chr2-231091223_231109786_231113600_1.sashimi new file mode 100644 index 00000000..3627e2bd --- /dev/null +++ b/examples/chr2-231091223_231109786_231113600_1.sashimi @@ -0,0 +1,4 @@ +chr2 231109795 231110578 link1 0.206081805156302 + +chr2 231109795 231112631 link2 0.0787274425673936 + +chr2 231110655 231112631 link3 0.283893083093872 + +chr2 231112780 231113600 link4 0.337251461791404 + diff --git a/examples/chr2-231091223_231109786_231113600_2.sashimi b/examples/chr2-231091223_231109786_231113600_2.sashimi new file mode 100644 index 00000000..1ac03c48 --- /dev/null +++ b/examples/chr2-231091223_231109786_231113600_2.sashimi @@ -0,0 +1,4 @@ +chr2 231109795 231110578 link1 0.178226805210714 + +chr2 231109795 231112631 link2 0.126256827523686 + +chr2 231110655 231112631 linke3 0.195029646753571 + +chr2 231112780 231113600 link4 0.390030949667857 + diff --git a/examples/generateAllOutput.sh b/examples/generateAllOutput.sh index b55ad90b..b967a2c1 100644 --- a/examples/generateAllOutput.sh +++ b/examples/generateAllOutput.sh @@ -7,6 +7,7 @@ pgt --tracks ./examples/hic_track.ini -o hic_track.png --region chrX:2500000-350 pgt --tracks ./examples/epilogos_track.ini --region X:3100000-3150000 -o ./examples/epilogos_track.png pgt --tracks ./examples/epilogos_track2.ini --region X:3100000-3150000 -o ./examples/epilogos_track2.png pgt --tracks ./examples/bedgraph_matrix_lines.ini --region X:2000000-3500000 -o ./examples/bedgraph_matrix_lines.png +pgt --tracks ./examples/chr2-231091223_231109786_231113600.ini --region chr2:231107879-231115507 -t 'chr2:231109786-231113600 (sQTL = 2:231091223, ALT=G)' --width 9 --trackLabelFraction 0.01 -out ./examples/sashimi_example.pdf --fontSize 4 # The following examples require a modification of pygenometracks (adding a new track class) # cp examples/helloWorldTrack.py pygenometracks/tracks/ diff --git a/examples/sashimi_example.pdf b/examples/sashimi_example.pdf new file mode 100644 index 00000000..f33ce7cf Binary files /dev/null and b/examples/sashimi_example.pdf differ diff --git a/pygenometracks/tests/generateAllOutput.sh b/pygenometracks/tests/generateAllOutput.sh index 6e5055a3..194e4e71 100644 --- a/pygenometracks/tests/generateAllOutput.sh +++ b/pygenometracks/tests/generateAllOutput.sh @@ -184,3 +184,7 @@ pgt --tracks ./pygenometracks/tests/test_data/mcool_hic_matrix_square.ini --regi # demo pgt --tracks ./pygenometracks/tests/test_data/demo2.ini --region chrX:3320000-3370000 -o ./pygenometracks/tests/test_data/demo2.png pgt --tracks ./pygenometracks/tests/test_data/demo.ini --region chrX:3000000-3500000 -o ./pygenometracks/tests/test_data/demo.png + +# sashimi +pgt --tracks ./pygenometracks/tests/test_data/sashimi_tracks.ini --region chr2:231107879-231115507 --trackLabelFraction 0.23 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_sashimi.png +pgt --tracks ./pygenometracks/tests/test_data/sashimi_tracks.ini --region X:3000000-3500000 --trackLabelFraction 0.23 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_sashimi_X.png diff --git a/pygenometracks/tests/test_data/avg_chr2-231091223_231109786_231113600_0.bw b/pygenometracks/tests/test_data/avg_chr2-231091223_231109786_231113600_0.bw new file mode 100644 index 00000000..2de18aa9 Binary files /dev/null and b/pygenometracks/tests/test_data/avg_chr2-231091223_231109786_231113600_0.bw differ diff --git a/pygenometracks/tests/test_data/chr2-231091223_231109786_231113600_0.sashimi b/pygenometracks/tests/test_data/chr2-231091223_231109786_231113600_0.sashimi new file mode 100644 index 00000000..3d9d722f --- /dev/null +++ b/pygenometracks/tests/test_data/chr2-231091223_231109786_231113600_0.sashimi @@ -0,0 +1,4 @@ +chr2 231109795 231110578 link1 0.2372970970798 + +chr2 231109795 231112631 link2 0.023623129827603 + +chr2 231110655 231112631 link3 0.326657037385783 + +chr2 231112780 231113600 link4 0.313684195593452 + diff --git a/pygenometracks/tests/test_data/master_sashimi.png b/pygenometracks/tests/test_data/master_sashimi.png new file mode 100644 index 00000000..1c03a954 Binary files /dev/null and b/pygenometracks/tests/test_data/master_sashimi.png differ diff --git a/pygenometracks/tests/test_data/master_sashimi_X.png b/pygenometracks/tests/test_data/master_sashimi_X.png new file mode 100644 index 00000000..2f12c2bf Binary files /dev/null and b/pygenometracks/tests/test_data/master_sashimi_X.png differ diff --git a/pygenometracks/tests/test_data/sashimi_tracks.ini b/pygenometracks/tests/test_data/sashimi_tracks.ini new file mode 100644 index 00000000..352b5d71 --- /dev/null +++ b/pygenometracks/tests/test_data/sashimi_tracks.ini @@ -0,0 +1,123 @@ + +[fixed line width] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = fixed link_line_width to 0.5 link_fontsize = 10 orientation = inverted +height = 3 +bw_color = darkblue +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_color = darkblue +link_fontsize = 10 +link_line_width = 0.5 +orientation = inverted +file_type = sashimiBigWig + +[no label] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = link_labels = false; alpha = 0.1; link_scale_height = 10 +height = 3 +bw_color = purple +alpha = 0.1 +max_value = 110 +show_data_range = true +link_color = purple +link_labels = false +link_scale_height = 10 +file_type = sashimiBigWig + +[spacer] +height = 0.1 + +[scale line width] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = link_scale_line_width = 10; link_fontsize = 4; link_alpha = 0.5 +height = 3 +bw_color = orange +max_value = 110 +show_data_range = true +link_color = orange +link_fontsize = 4 +link_alpha = 0.5 +link_scale_line_width = 10 +file_type = sashimiBigWig + +[log transformed] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = transform = log; log_pseudocount = 1 +height = 3 +bw_color = black +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_color = black +transform = log +log_pseudocount = 1 +file_type = sashimiBigWig + +[log transformed min_value] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = transform = log; log_pseudocount = 1; min_value = 50 +height = 3 +bw_color = black +min_value = 50 +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_color = black +transform = log +log_pseudocount = 1 +file_type = sashimiBigWig + +[log transformed min_value original y_axis_values] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = transform = log; log_pseudocount = 1; min_value = 10; y_axis_values = original +height = 3 +bw_color = grey +min_value = 10 +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_color = grey +transform = log +log_pseudocount = 1 +y_axis_values = original +file_type = sashimiBigWig + + +[min_value grid] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = min_value = 10; grid = true; link_color = viridis; link_line_width = 2 +height = 3 +bw_color = cyan +min_value = 10 +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_line_width = 2 +link_color = viridis +grid = true +file_type = sashimiBigWig + +[colormap min_value max_value] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = link_color = viridis; link_line_width = 2; link_min_max_values to 0 1 +height = 3 +bw_color = pink +max_value = 110 +show_data_range = no +link_line_width = 2 +link_color = viridis +link_min_value = 0 +link_max_value = 1 +link_labels = false +link_scale_height = 10 +file_type = sashimiBigWig diff --git a/pygenometracks/tests/test_sashimi.py b/pygenometracks/tests/test_sashimi.py new file mode 100644 index 00000000..cdd479b8 --- /dev/null +++ b/pygenometracks/tests/test_sashimi.py @@ -0,0 +1,191 @@ +# -*- coding: utf-8 -*- +import os.path +from tempfile import NamedTemporaryFile + +import matplotlib as mpl +from get_matplotlib_CI_version import get_CI_mpl_version +from matplotlib.testing.compare import compare_images + +import pygenometracks.plotTracks + +mpl.use('agg') + +ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), + "test_data") + +browser_tracks = """ +[fixed line width] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = fixed link_line_width to 0.5 link_fontsize = 10 orientation = inverted +height = 3 +bw_color = darkblue +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_color = darkblue +link_fontsize = 10 +link_line_width = 0.5 +orientation = inverted +file_type = sashimiBigWig + +[no label] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = link_labels = false; alpha = 0.1; link_scale_height = 10 +height = 3 +bw_color = purple +alpha = 0.1 +max_value = 110 +show_data_range = true +link_color = purple +link_labels = false +link_scale_height = 10 +file_type = sashimiBigWig + +[spacer] +height = 0.1 + +[scale line width] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = link_scale_line_width = 10; link_fontsize = 4; link_alpha = 0.5 +height = 3 +bw_color = orange +max_value = 110 +show_data_range = true +link_color = orange +link_fontsize = 4 +link_alpha = 0.5 +link_scale_line_width = 10 +file_type = sashimiBigWig + +[log transformed] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = transform = log; log_pseudocount = 1 +height = 3 +bw_color = black +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_color = black +transform = log +log_pseudocount = 1 +file_type = sashimiBigWig + +[log transformed min_value] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = transform = log; log_pseudocount = 1; min_value = 50 +height = 3 +bw_color = black +min_value = 50 +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_color = black +transform = log +log_pseudocount = 1 +file_type = sashimiBigWig + +[log transformed min_value original y_axis_values] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = transform = log; log_pseudocount = 1; min_value = 10; y_axis_values = original +height = 3 +bw_color = grey +min_value = 10 +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_color = grey +transform = log +log_pseudocount = 1 +y_axis_values = original +file_type = sashimiBigWig + + +[min_value grid] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = min_value = 10; grid = true; link_color = viridis; link_line_width = 2 +height = 3 +bw_color = cyan +min_value = 10 +max_value = 110 +nans_to_zeros = true +show_data_range = true +link_line_width = 2 +link_color = viridis +grid = true +file_type = sashimiBigWig + +[colormap min_value max_value] +file = avg_chr2-231091223_231109786_231113600_0.bw +link_file = chr2-231091223_231109786_231113600_0.sashimi +title = link_color = viridis; link_line_width = 2; link_min_max_values to 0 1 +height = 3 +bw_color = pink +max_value = 110 +show_data_range = no +link_line_width = 2 +link_color = viridis +link_min_value = 0 +link_max_value = 1 +link_labels = false +link_scale_height = 10 +file_type = sashimiBigWig +""" + +with open(os.path.join(ROOT, "sashimi_tracks.ini"), 'w') as fh: + fh.write(browser_tracks) + +tolerance = 13 # default matplotlib pixed difference tolerance +default_mpl_version = get_CI_mpl_version() + + +def test_sashimi_main(): + + if mpl.__version__ != default_mpl_version: + my_tolerance = 29 + else: + my_tolerance = tolerance + + outfile = NamedTemporaryFile(suffix='.png', prefix='pyGenomeTracks_test_', + delete=False) + ini_file = os.path.join(ROOT, "sashimi_tracks.ini") + region = "chr2:231107879-231115507" + expected_file = os.path.join(ROOT, 'master_sashimi.png') + args = f"--tracks {ini_file} --region {region} "\ + "--trackLabelFraction 0.23 --width 38 --dpi 130 "\ + f"--outFileName {outfile.name}".split() + pygenometracks.plotTracks.main(args) + res = compare_images(expected_file, + outfile.name, my_tolerance) + assert res is None, res + + os.remove(outfile.name) + + +def test_sashimi_X(): + + if mpl.__version__ != default_mpl_version: + my_tolerance = 28 + else: + my_tolerance = tolerance + + outfile = NamedTemporaryFile(suffix='.png', prefix='pyGenomeTracks_test_', + delete=False) + ini_file = os.path.join(ROOT, "sashimi_tracks.ini") + region = "X:3000000-3500000" + expected_file = os.path.join(ROOT, 'master_sashimi_X.png') + args = f"--tracks {ini_file} --region {region} "\ + "--trackLabelFraction 0.23 --width 38 --dpi 130 "\ + f"--outFileName {outfile.name}".split() + pygenometracks.plotTracks.main(args) + res = compare_images(expected_file, + outfile.name, my_tolerance) + assert res is None, res + + os.remove(outfile.name) diff --git a/pygenometracks/tracks/BedTrack.py b/pygenometracks/tracks/BedTrack.py index 2ee02e3f..dda8984a 100644 --- a/pygenometracks/tracks/BedTrack.py +++ b/pygenometracks/tracks/BedTrack.py @@ -1,24 +1,16 @@ import matplotlib import numpy as np -from intervaltree import Interval, IntervalTree +from intervaltree import IntervalTree from matplotlib import font_manager from matplotlib.lines import Line2D from matplotlib.patches import FancyArrowPatch, Polygon, Rectangle -from tqdm import tqdm -from ..readBed import ReadBed -# To remove next 1.0 -from ..readGtf import ReadGtf -# End to remove -from ..utilities import (InputError, change_chrom_names, count_lines, - get_length_w, opener, temp_file_from_intersect) -from .GenomeTrack import GenomeTrack +from ..utilities import InputError, change_chrom_names, get_length_w +from .GenomeTrack import AROUND_REGION, DEFAULT_BED_COLOR, GenomeTrack -DEFAULT_BED_COLOR = '#1f78b4' DISPLAY_BED_VALID = ['collapsed', 'triangles', 'interleaved', 'stacked', 'squares', 'deletions', 'inversions'] DISPLAY_BED_SYNONYMOUS = {'interlaced': 'interleaved', 'domain': 'interleaved'} DEFAULT_DISPLAY_BED = 'stacked' -AROUND_REGION = 100000 EPSILON = 0.08 @@ -203,7 +195,7 @@ def __init__(self, *args, **kwarg): # this is bed3, bed4, bed5, bed6, bed8, bed9 or bed12 self.current_len_w = None # this is the length of the letter 'w' given the font size self.interval_tree = {} # interval tree of the bed regions - self.interval_tree, min_score, max_score = self.process_bed(self.properties['region']) + self.interval_tree, min_score, max_score = self.process_bed(DEFAULT_BED_COLOR, plot_regions=self.properties['region']) if self.colormap is not None: if self.properties['min_value'] is not None: min_score = self.properties['min_value'] @@ -267,76 +259,6 @@ def set_properties_defaults(self): # to set the distance between rows self.row_scale = 2.3 - def get_bed_handler(self, plot_regions=None): - if not self.properties['global_max_row']: - # I do the intersection: - file_to_open = temp_file_from_intersect(self.properties['file'], - plot_regions, AROUND_REGION) - else: - file_to_open = self.properties['file'] - # To remove in next 1.0 - if self.properties['file'].endswith('gtf') or \ - self.properties['file'].endswith('gtf.gz'): - self.log.warning("Deprecation Warning: " - f"In section {self.properties['section_name']}," - f" file_type was set to {self.TRACK_TYPE}" - " whereas it is a gtf file. In the future" - " only bed files will be accepted, please" - " use file_type = gtf.\n") - bed_file_h = ReadGtf(file_to_open, - self.properties['prefered_name'], - self.properties['merge_transcripts'], - self.properties['merge_overlapping_exons']) - total_length = bed_file_h.length - else: - # end of remove - total_length = count_lines(opener(file_to_open), - asBed=True) - bed_file_h = ReadBed(opener(file_to_open)) - - return bed_file_h, total_length - - def process_bed(self, plot_regions=None): - - bed_file_h, total_length = self.get_bed_handler(plot_regions) - self.bed_type = bed_file_h.file_type - - if self.properties['color'] == 'bed_rgb' and \ - self.bed_type not in ['bed12', 'bed9']: - self.log.warning("*WARNING* Color set to 'bed_rgb', " - "but bed file does not have the rgb field. " - f"The color has been set to {DEFAULT_BED_COLOR}.\n") - self.properties['color'] = DEFAULT_BED_COLOR - - valid_intervals = 0 - interval_tree = {} - - max_score = float('-inf') - min_score = float('inf') - for bed in tqdm(bed_file_h, total=total_length): - if bed.score < min_score: - min_score = bed.score - if bed.score > max_score: - max_score = bed.score - - if bed.chromosome not in interval_tree: - interval_tree[bed.chromosome] = IntervalTree() - - interval_tree[bed.chromosome].add(Interval(bed.start, - bed.end, bed)) - valid_intervals += 1 - - try: - bed_file_h.file_handle.close() - except AttributeError: - pass - - if valid_intervals == 0: - self.log.warning("No valid intervals were found in file " - f"{self.properties['file']}.\n") - - return interval_tree, min_score, max_score - def get_max_num_row(self, len_w, small_relative): ''' Process the whole bed regions at the given figure length and font size to @@ -698,32 +620,6 @@ def plot_y_axis(self, ax, plot_axis): self.colormap.set_array([]) GenomeTrack.plot_custom_cobar(self, ax, fraction=1) - def get_rgb(self, bed, param='color', default=DEFAULT_BED_COLOR): - """ - get the rgb value for the bed and the param given: - :param bed: - :param param: - :param default: the default value if it fails - :return: color - """ - rgb = self.properties[param] - - if self.colormap is not None and param in self.parametersUsingColormap: - # translate value field (in the example above is 0 or 0.2686...) - # into a color - rgb = self.colormap.to_rgba(bed.score) - elif self.properties[param] == 'bed_rgb': - # if rgb is set in the bed line, this overrides the previously - # defined colormap - if self.bed_type in ['bed9', 'bed12'] and len(bed.rgb) == 3: - try: - rgb = [float(x) / 255 for x in bed.rgb] - except IndexError: - rgb = default - else: - rgb = default - return rgb - def draw_gene_simple(self, ax, bed, ypos, rgb, edgecolor, linewidth): """ draws an interval with direction (if given) diff --git a/pygenometracks/tracks/BigWigTrack.py b/pygenometracks/tracks/BigWigTrack.py index 26417c0a..72074504 100644 --- a/pygenometracks/tracks/BigWigTrack.py +++ b/pygenometracks/tracks/BigWigTrack.py @@ -146,20 +146,19 @@ def set_properties_defaults(self): " It will be set as 'transformed'.\n") self.properties['y_axis_values'] = 'transformed' - def plot(self, ax, chrom_region, start_region, end_region): + def get_transformed_values(self, chrom_region, start_region, end_region): temp_end_region, temp_nbins, scores_per_bin = self.get_scores('self.bw', self.properties['file'], chrom_region, start_region, end_region) if scores_per_bin is None: - self.log.warning("Scores could not be computed. This will generate an empty track\n") - return + return [None, None] if self.properties['nans_to_zeros'] and np.any(np.isnan(scores_per_bin)): scores_per_bin[np.isnan(scores_per_bin)] = 0 x_values = np.linspace(start_region, temp_end_region, temp_nbins) # compute the operation - operation = self.properties['operation'] + operation = self.properties.get('operation', 'file') # Substitute log by np.log to make it evaluable: operation = operation.replace('log', 'np.log') if operation == 'file': @@ -206,6 +205,13 @@ def plot(self, ax, chrom_region, start_region, end_region): self.properties['transform'], self.properties['log_pseudocount'], self.properties['file']) + return x_values, transformed_scores + + def plot(self, ax, chrom_region, start_region, end_region): + x_values, transformed_scores = self.get_transformed_values(chrom_region, start_region, end_region) + if x_values is None: + self.log.warning("Scores could not be computed. This will generate an empty track\n") + return plot_coverage(ax, x_values, transformed_scores, self.plot_type, self.size, diff --git a/pygenometracks/tracks/GenomeTrack.py b/pygenometracks/tracks/GenomeTrack.py index 1f3b199b..1bb3ac16 100644 --- a/pygenometracks/tracks/GenomeTrack.py +++ b/pygenometracks/tracks/GenomeTrack.py @@ -6,10 +6,17 @@ import matplotlib.pyplot as plt import numpy as np +from intervaltree import Interval, IntervalTree from matplotlib import colors as mc from matplotlib.ticker import LogFormatter +from tqdm import tqdm -from ..utilities import InputError, transform +from ..readBed import ReadBed +# To remove next 1.0 +from ..readGtf import ReadGtf +# End to remove +from ..utilities import (InputError, count_lines, opener, + temp_file_from_intersect, transform) # This is a regex for float which would work for 11, 102.25, but also .2 float_regex = r'(?:\d+)?(?:\.\d+)?' @@ -21,6 +28,10 @@ DEFAULT_MAX_SIGNS = 4 +DEFAULT_BED_COLOR = '#1f78b4' +AROUND_REGION = 100000 +HUGE_NUMBER = int(1e9) # Which should be above any chromosome size + class GenomeTrack(object): """ @@ -84,7 +95,8 @@ def set_properties_defaults(self): self.properties[prop] = default_value def plot_y_axis(self, ax, plot_axis, transform='no', log_pseudocount=0, - y_axis='transformed', only_at_ticks=False): + y_axis='transformed', only_at_ticks=False, + forced_ymin=None, forced_ymax=None): """ Plot the scale of the y axis with respect to the plot_axis Args: @@ -214,6 +226,10 @@ def untransform(value, transform, log_pseudocount): return np.exp(- value) - log_pseudocount ymin, ymax = plot_axis.get_ylim() + if forced_ymin is not None: + ymin = forced_ymin + if forced_ymax is not None: + ymax = forced_ymax # If the ticks are closer than epsilon from the top or bottom # The vertical alignment of label is adjusted epsilon = (ymax - ymin) / 100 @@ -624,3 +640,100 @@ def adjust_ylim(self, axis): def __del__(self): return + + def get_bed_handler(self, file_key='file', plot_regions=None): + if not self.properties.get('global_max_row', False): + # I do the intersection: + file_to_open = temp_file_from_intersect(self.properties[file_key], + plot_regions, AROUND_REGION) + else: + file_to_open = self.properties[file_key] + is_gtf = self.TRACK_TYPE == "gtf" or self.properties[file_key].endswith('gtf') or self.properties[file_key].endswith('gtf.gz') + if is_gtf: + if self.TRACK_TYPE != "gtf": + # To remove in next 1.0 + self.log.warning("Deprecation Warning: " + f"In section {self.properties['section_name']}," + f" file_type was set to {self.TRACK_TYPE}" + " whereas it is a gtf file. In the future" + " only bed files will be accepted, please" + " use file_type = gtf.\n") + bed_file_h = ReadGtf(file_to_open, + self.properties['prefered_name'], + self.properties['merge_transcripts'], + self.properties['merge_overlapping_exons']) + total_length = bed_file_h.length + else: + # end of remove + total_length = count_lines(opener(file_to_open), + asBed=True) + bed_file_h = ReadBed(opener(file_to_open)) + + return bed_file_h, total_length + + def process_bed(self, default_color, file_key='file', color_key='color', plot_regions=None): + + bed_file_h, total_length = self.get_bed_handler(file_key, plot_regions) + self.bed_type = bed_file_h.file_type + + if self.properties[color_key] == 'bed_rgb' and \ + self.bed_type not in ['bed12', 'bed9']: + self.log.warning("*WARNING* Color set to 'bed_rgb', " + "but bed file does not have the rgb field. " + f"The color has been set to {default_color}.\n") + self.properties[color_key] = default_color + + valid_intervals = 0 + interval_tree = {} + + max_score = float('-inf') + min_score = float('inf') + for bed in tqdm(bed_file_h, total=total_length): + if bed.score < min_score: + min_score = bed.score + if bed.score > max_score: + max_score = bed.score + + if bed.chromosome not in interval_tree: + interval_tree[bed.chromosome] = IntervalTree() + + interval_tree[bed.chromosome].add(Interval(bed.start, + bed.end, bed)) + valid_intervals += 1 + + try: + bed_file_h.file_handle.close() + except AttributeError: + pass + + if valid_intervals == 0: + self.log.warning("No valid intervals were found in file " + f"{self.properties[file_key]}.\n") + + return interval_tree, min_score, max_score + + def get_rgb(self, bed, param='color', default=DEFAULT_BED_COLOR): + """ + get the rgb value for the bed and the param given: + :param bed: + :param param: + :param default: the default value if it fails + :return: color + """ + rgb = self.properties[param] + + if self.colormap is not None and param in self.parametersUsingColormap: + # translate value field (in the example above is 0 or 0.2686...) + # into a color + rgb = self.colormap.to_rgba(bed.score) + elif self.properties[param] == 'bed_rgb': + # if rgb is set in the bed line, this overrides the previously + # defined colormap + if self.bed_type in ['bed9', 'bed12'] and len(bed.rgb) == 3: + try: + rgb = [float(x) / 255 for x in bed.rgb] + except IndexError: + rgb = default + else: + rgb = default + return rgb diff --git a/pygenometracks/tracks/GtfTrack.py b/pygenometracks/tracks/GtfTrack.py index 5245c313..76c6dff4 100644 --- a/pygenometracks/tracks/GtfTrack.py +++ b/pygenometracks/tracks/GtfTrack.py @@ -1,16 +1,12 @@ import numpy as np from matplotlib import font_manager -from ..readGtf import ReadGtf -from ..utilities import temp_file_from_intersect from .BedTrack import BedTrack -from .GenomeTrack import GenomeTrack +from .GenomeTrack import DEFAULT_BED_COLOR, GenomeTrack -DEFAULT_BED_COLOR = '#1f78b4' DISPLAY_BED_VALID = ['collapsed', 'triangles', 'interleaved', 'stacked', 'squares', 'deletions', 'inversions'] DISPLAY_BED_SYNONYMOUS = {'interlaced': 'interleaved', 'domain': 'interleaved'} DEFAULT_DISPLAY_BED = 'stacked' -AROUND_REGION = 100000 class GtfTrack(BedTrack): @@ -190,18 +186,3 @@ def set_properties_defaults(self): # to set the distance between rows self.row_scale = 2.3 - - def get_bed_handler(self, plot_regions=None): - if not self.properties['global_max_row']: - # I do the intersection: - file_to_open = temp_file_from_intersect(self.properties['file'], - plot_regions, AROUND_REGION) - else: - file_to_open = self.properties['file'] - - bed_file_h = ReadGtf(file_to_open, - self.properties['prefered_name'], - self.properties['merge_transcripts'], - self.properties['merge_overlapping_exons']) - total_length = bed_file_h.length - return bed_file_h, total_length diff --git a/pygenometracks/tracks/LinksTrack.py b/pygenometracks/tracks/LinksTrack.py index 0e1e33aa..58b78ad5 100644 --- a/pygenometracks/tracks/LinksTrack.py +++ b/pygenometracks/tracks/LinksTrack.py @@ -8,10 +8,9 @@ from ..utilities import (change_chrom_names, get_region, opener, temp_file_from_intersect, to_string) -from .GenomeTrack import GenomeTrack +from .GenomeTrack import HUGE_NUMBER, GenomeTrack DEFAULT_LINKS_COLOR = 'blue' -HUGE_NUMBER = int(1e9) # Which should be above any chromosome size class LinksTrack(GenomeTrack): diff --git a/pygenometracks/tracks/SashimiBigWigTrack.py b/pygenometracks/tracks/SashimiBigWigTrack.py new file mode 100644 index 00000000..de591d6d --- /dev/null +++ b/pygenometracks/tracks/SashimiBigWigTrack.py @@ -0,0 +1,427 @@ +# Authors: Zepeng Mu (zmu@broadinstitute.org) and Yang I. Li (yangili1@uchicago.edu) +# Edits: Lucille Lopez-Delisle (lucille.delisle@unige.ch) + +import matplotlib +import matplotlib.patches as mpatches +import matplotlib.path as mpath +import numpy as np +import pyBigWig +from intervaltree import IntervalTree + +from ..utilities import change_chrom_names, plot_coverage, transform +from .BigWigTrack import BigWigTrack +from .GenomeTrack import GenomeTrack + +Path = mpath.Path + +DEFAULT_LINKS_COLOR = 'blue' +DEFAULT_BIGWIG_COLOR = '#33a02c' + + +class SashimiBigWigTrack(BigWigTrack): + SUPPORTED_ENDINGS = [] + TRACK_TYPE = 'sashimiBigWig' + OPTIONS_TXT = GenomeTrack.OPTIONS_TXT + f""" +bw_color = #666666 +# To use a different color for negative values +#negative_color = red +# To use transparency, you can use alpha +# default is 1 +#alpha = 0.5 +# the default for min_value and max_value is 'auto' which means that the scale will go +# roughly from the minimum value found in the region plotted to the maximum value found. +min_value = 0 +#max_value = auto +# The number of bins takes the region to be plotted and divides it +# into the number of bins specified +# Then, at each bin the bigwig mean value is computed and plotted. +# A lower number of bins produces a coarser tracks +number_of_bins = 700 +# to convert missing data (NaNs) into zeros. Otherwise, missing data is not plotted. +nans_to_zeros = true +# The possible summary methods are given by pyBigWig: +# mean/average/stdev/dev/max/min/cov/coverage/sum +# default is mean +summary_method = mean +# for type, the options are: line, points, fill. Default is fill +# to add the preferred line width or point size use: +# type = line:lw where lw (linewidth) is float +# similarly points:ms sets the point size (markersize (ms) to the given float +#type = line:0.5 +#type = points:0.5 +# set show_data_range to false to hide the text on the left showing the data range +show_data_range = true +# To log transform your data you can also use transform and log_pseudocount: +# For the transform values: +# 'log1p': transformed_values = log(1 + initial_values) +# 'log': transformed_values = log(log_pseudocount + initial_values) +# 'log2': transformed_values = log2(log_pseudocount + initial_values) +# 'log10': transformed_values = log10(log_pseudocount + initial_values) +# '-log': transformed_values = - log(log_pseudocount + initial_values) +# For example: +#tranform = log +#log_pseudocount = 2 +# When a transformation is applied, by default the y axis +# gives the transformed values, if you prefer to see +# the original values: +#y_axis_values = original +# If you want to have a grid on the y-axis +#grid = true +## Links customization +# The link file should be a BED file where the score +# is in the 5th column +#link_file = +# If the bed file contains a column for color (column 9), then this color can be used by +# setting: +#link_color = bed_rgb +# if link_color is a valid colormap name (like RbBlGn), then the score (column 5) is mapped +# to the colormap. +# In this case, the the link_min_value and link_max_value for the score can be provided, otherwise +# the maximum score and minimum score found are used. +#link_color = RdYlBu +#link_min_value=0 +#link_max_value=100 +# If the link_color is simply a color name, then this link_color is used and the score is not considered for the color. +link_color = darkblue +# To use transparency, you can use link_alpha +# default is 1 +#link_alpha = 0.5 +# options for link_line_style are 'solid', 'dashed', 'dotted', and 'dashdot' +link_line_style = solid +# The link in Sashimi plot is a Bezier curve. +# By default the height of the curve is 25% of the coverage height +# To increase or decrease this proportion you can adjust link_scale_height +link_scale_height = 1 +# The line width for links is proportional to the log(1 + PSI) where PSI is the fifth column of the BED file. +# Use link_scale_line_width to scale the line widths. +# You may need to try several values to get a satisfying result. +# Use this to scale Sashimi line width if the links are too thin or too wide. +#link_scale_line_width = 3 +# Set link_line_width if you do not want width of links to scale with score (PSI). +# This overwrites link_scale_line_width. +#link_line_width = 2 +# Set this to true to label scores (PSI) on links +link_labels = true +# optional: font size can be given to override the default size +#link_fontsize = 10 +file_type = {TRACK_TYPE} + """ + + DEFAULTS_PROPERTIES = { + # Bigwig related + 'max_value': None, + 'min_value': None, + 'show_data_range': True, + 'orientation': None, + 'bw_color': DEFAULT_BIGWIG_COLOR, + 'negative_color': None, + 'alpha': 1, + 'nans_to_zeros': False, + 'summary_method': 'mean', + 'number_of_bins': 700, + 'type': 'fill', + 'transform': 'no', + 'log_pseudocount': 0, + 'y_axis_values': 'transformed', + 'grid': False, + # Links related + 'link_color': DEFAULT_LINKS_COLOR, + 'link_alpha': 1, + 'link_line_width': None, + 'link_line_style': 'solid', + 'link_max_value': None, + 'link_min_value': None, + 'link_scale_height': 1, + 'link_scale_line_width': 2, + 'link_labels': True, + 'link_fontsize': None, + # General + 'region': None, # Cannot be set manually but is set by tracksClass + } + NECESSARY_PROPERTIES = ['file', 'link_file'] + SYNONYMOUS_PROPERTIES = { + 'max_value': { + 'auto': None + }, + 'min_value': { + 'auto': None + }, + 'link_max_value': { + 'auto': None + }, + 'link_min_value': { + 'auto': None + }, + } + POSSIBLE_PROPERTIES = { + 'orientation': [None, 'inverted'], + 'summary_method': [ + 'mean', 'average', 'max', 'min', 'stdev', 'dev', 'coverage', 'cov', + 'sum' + ], + 'transform': ['no', 'log', 'log1p', '-log', 'log2', 'log10'], + 'y_axis_values': ['original', 'transformed'], + 'link_line_style': ['solid', 'dashed', + 'dotted', 'dashdot'], + } + BOOLEAN_PROPERTIES = [ + 'nans_to_zeros', 'show_data_range', 'grid', 'link_labels' + ] + STRING_PROPERTIES = [ + 'file', 'file_type', 'overlay_previous', 'orientation', + 'summary_method', 'title', 'bw_color', 'negative_color', 'transform', + 'y_axis_values', 'type', 'link_file', + 'link_line_style', 'link_color' + ] + FLOAT_PROPERTIES = { + 'max_value': [-np.inf, np.inf], + 'min_value': [-np.inf, np.inf], + 'log_pseudocount': [-np.inf, np.inf], + 'alpha': [0, 1], + 'height': [0, np.inf], + 'link_fontsize': [0, np.inf], + 'link_alpha': [0, 1], + 'link_max_value': [-np.inf, np.inf], + 'link_min_value': [-np.inf, np.inf], + 'link_line_width': [0, np.inf], + 'link_scale_height': [0, np.inf], + 'link_scale_line_width': [0, np.inf] + } + INTEGER_PROPERTIES = {'number_of_bins': [1, np.inf]} + + # The bw_color can only be a color + # negative_color can only be a color or None + + def __init__(self, *args, **kwargs): + super(BigWigTrack, self).__init__(*args, **kwargs) + self.bw = pyBigWig.open(self.properties['file']) + self.show_number = self.properties['link_labels'] + + def set_properties_defaults(self): + super(BigWigTrack, self).set_properties_defaults() + super(BigWigTrack, self).process_type_for_coverage_track() + self.process_color('bw_color') + if self.properties['negative_color'] is None: + self.properties['negative_color'] = self.properties['bw_color'] + else: + self.process_color('negative_color') + # FOR LINK + is_colormap = self.process_color('link_color', colormap_possible=True, bed_rgb_possible=True, default_value_is_colormap=False) + self.interval_tree, min_score, max_score = self.process_bed(DEFAULT_LINKS_COLOR, file_key='link_file', color_key='link_color', + plot_regions=self.properties['region']) + # Initiate the colormap if needed + self.colormap = None + self.parametersUsingColormap = [] + if is_colormap: + if self.properties['link_min_value'] is not None: + min_score = self.properties['link_min_value'] + if self.properties['link_max_value'] is not None: + max_score = self.properties['link_max_value'] + + norm = matplotlib.colors.Normalize(vmin=min_score, + vmax=max_score) + + try: + # Matplotlib < 3.11.0 + cmap = matplotlib.cm.get_cmap(self.colormap) + except AttributeError: + # Matplotlib >= 3.11.0 + cmap = matplotlib.pyplot.get_cmap(self.colormap) + self.colormap = matplotlib.cm.ScalarMappable(norm=norm, cmap=cmap) + self.parametersUsingColormap.append('link_color') + + def plot(self, ax, chrom_region, start_region, end_region): + x_values, transformed_scores = self.get_transformed_values(chrom_region, start_region, end_region) + if x_values is None: + self.log.warning("Scores could not be computed. This will generate an empty track\n") + return + + count = 0 + + plot_coverage(ax, x_values, transformed_scores, self.plot_type, + self.size, self.properties['bw_color'], + self.properties['negative_color'], + self.properties['alpha'], self.properties['grid']) + + # Adjust ylim except for the inversion + real_orientation = self.properties['orientation'] + self.properties['orientation'] = None + + self.adjust_ylim(ax) + + plot_ymin, plot_ymax = ax.get_ylim() + + # If there is no transformation and only positive values and not min_value we put min_value to 0 + if self.properties['transform'] == 'no' and np.min(transformed_scores) > 0 and self.properties['min_value'] is None: + plot_ymin = 0 + + self.min_value = plot_ymin + self.max_value = plot_ymax + self.pos_height = plot_ymax + self.neg_height = plot_ymin + + # PLOT LINK + if chrom_region not in self.interval_tree.keys(): + chrom_region_before = chrom_region + chrom_region = change_chrom_names(chrom_region) + if chrom_region not in self.interval_tree.keys(): + self.log.warning("*Warning*\nNeither " + + chrom_region_before + " nor " + + chrom_region + " exists as a " + "chromosome name inside the link_file." + "No link will be plotted!!\n") + self.interval_tree[chrom_region] = IntervalTree() + arcs_in_region = sorted( + self.interval_tree[chrom_region][start_region:end_region]) + for idx, interval in enumerate(arcs_in_region): + # skip intervals whose start and end are outside the plotted region + if interval.begin < start_region and interval.end > end_region: + continue + score_start = float( + self.bw.values(chrom_region, interval.begin, + interval.begin + 1)[0]) + score_end = float( + self.bw.values(chrom_region, interval.end, + interval.end + 1)[0]) + # Transform the scores + score_start, score_end = \ + transform(np.array([score_start, score_end]), + self.properties['transform'], + self.properties['log_pseudocount'], + self.properties['file']) + + if self.properties['link_line_width'] is not None: + self.line_width = float(self.properties['link_line_width']) + else: + self.line_width = self.properties['link_scale_line_width'] * np.log( + interval.data.score + 1) * 1.5 + + self.plot_bezier(ax, interval, idx, score_start, score_end, + plot_ymin, plot_ymax) + count += 1 + + self.log.debug(f"{count} links plotted") + + # Adjust the ylim to include the potential links plotted + # and use orientation + if real_orientation == 'inverted': + self.properties['orientation'] = 'inverted' + ax.set_ylim(self.pos_height, self.neg_height) + else: + ax.set_ylim(self.neg_height, self.pos_height) + + return ax + + def plot_bezier(self, ax, interval, idx, start_height, end_height, ymin, ymax): + + def cubic_bezier(pts, t): + b_x = (1 - t)**3 * pts[0][0] + 3 * t * (1 - t)**2 * pts[1][ + 0] + 3 * t**2 * (1 - t) * pts[2][0] + t**3 * pts[3][0] + b_y = (1 - t)**3 * pts[0][1] + 3 * t * (1 - t)**2 * pts[1][ + 1] + 3 * t**2 * (1 - t) * pts[2][1] + t**3 * pts[3][1] + return ((b_x, b_y)) + + # width = (interval.end - interval.begin) + + height = (ymax - ymin) * 0.25 * self.properties['link_scale_height'] + epsilon = (ymax - ymin) * 0.05 + rgb = self.get_rgb(interval.data, param='link_color', default=DEFAULT_LINKS_COLOR) + + # Plot below x-axis + if idx % 2 != 0: + pts = [(interval.begin, ymin), (interval.begin, ymin - height), + (interval.end, ymin - height), (interval.end, ymin)] + midpt = cubic_bezier(pts, 0.5) + minpt = min( + [cubic_bezier(pts, x)[1] for x in np.arange(0, 1, 0.05)]) + if minpt < self.neg_height: + self.neg_height = minpt - epsilon + + pp1 = mpatches.PathPatch( + Path( + pts, [Path.MOVETO, Path.CURVE4, Path.CURVE4, Path.CURVE4] + ), + fc="none", + ec=rgb, + lw=self.line_width, + ls=self.properties['link_line_style'], + alpha=self.properties['link_alpha']) + ax.add_patch(pp1) + if self.show_number: + ax.text(midpt[0], + midpt[1], + round(interval.data.score, 3), + fontsize=self.properties['link_fontsize'], + horizontalalignment='center', + verticalalignment='center', + bbox=dict(facecolor='white', edgecolor='none', pad=0)) + # Plot above + else: + pts = [(interval.begin, start_height), + (interval.begin, height + start_height), + (interval.end, height + end_height), + (interval.end, end_height)] + + midpt = cubic_bezier(pts, 0.5) + maxpt = max( + [cubic_bezier(pts, x)[1] for x in np.arange(0, 1, 0.05)]) + if maxpt > self.pos_height: + self.pos_height = maxpt + epsilon + + pp1 = mpatches.PathPatch( + Path( + pts, [Path.MOVETO, Path.CURVE4, Path.CURVE4, Path.CURVE4] + ), + fc="none", + ec=rgb, + lw=self.line_width, + ls=self.properties['link_line_style'], + alpha=self.properties['link_alpha']) + ax.add_patch(pp1) + if self.show_number: + ax.text(midpt[0], + midpt[1], + round(interval.data.score, 3), + fontsize=self.properties['link_fontsize'], + horizontalalignment='center', + verticalalignment='center', + bbox=dict(facecolor='white', edgecolor='none', pad=0)) + + # This y axis does not show the negative part, which is only Sashimi links + def plot_y_axis(self, + ax, + plot_axis): + """ + Plot the scale of the y axis with respect to the plot_axis + Args: + ax: axis to use to plot the scale + plot_axis: the reference axis to get the max and min. + + Returns: + + """ + + if self.properties['orientation'] is None: + ymin = self.min_value + ymax = self.max_value + else: + ymax = self.min_value + ymin = self.max_value + + GenomeTrack.plot_y_axis( + self, + ax, + plot_axis, + transform=self.properties['transform'], + log_pseudocount=self.properties['log_pseudocount'], + y_axis=self.properties['y_axis_values'], + only_at_ticks=self.properties['grid'], + forced_ymin=ymin, + forced_ymax=ymax + ) + + def __del__(self): + try: + self.bw.close() + except AttributeError: + pass diff --git a/pygenometracks/tracks/TADsTrack.py b/pygenometracks/tracks/TADsTrack.py index 729ff04d..b94302d1 100644 --- a/pygenometracks/tracks/TADsTrack.py +++ b/pygenometracks/tracks/TADsTrack.py @@ -1,9 +1,7 @@ import numpy as np from .BedTrack import BedTrack -from .GenomeTrack import GenomeTrack - -DEFAULT_BED_COLOR = '#1f78b4' +from .GenomeTrack import DEFAULT_BED_COLOR, GenomeTrack class TADsTrack(BedTrack):