Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
司凯威(Kaisi Wei) committed Nov 12, 2018
1 parent 0ce8e3d commit a444ad5
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 135 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ git clone http://github.com/orangeSi/ClustersPloter.git
### update feture:<br>
#### 2018-11-12:<br>
- rewrite feature.crossing.link.conf so that defined color and opactity or order or anchor position of every pair of links.<br>
- add tracks_reorder to plot tracks by new order, otherwise you must adjust --list file <br>
#### 2018-11-07:<br>
- feature_shaple now support <b>circle_point</b>/rect/arrow, add <b>feature_shift_y</b>, as example/out9.svg. combine with <b>feature_height_ratio</b> or <b>feature_shift_y</b>, try to plot <b>line</b> or <b>scatter</b> or <b>heatmap</b> or <b>histogram</b> is possible but hard for much data points, I will try do this by embed svg in svg, the embedded svg is producted by python or R tool, abd and the linux convert cmd not support embed svg, but cairosvg support it (should use the absoluted embedded svg path)!<br>
#### 2018-10-29:<br>
Expand All @@ -30,7 +31,6 @@ git clone http://github.com/orangeSi/ClustersPloter.git

#### todo:<br>
&nbsp;&nbsp;**2018-11-09**:<br>
&nbsp;&nbsp;&nbsp;&nbsp;1. plot tracks by sort sample list, or you can adjust the track order by adjust list file <br>
&nbsp;&nbsp;&nbsp;&nbsp;3. sort by feature,so same feature of different tracks can align centre<br>
&nbsp;&nbsp;&nbsp;&nbsp;4. add ratio scale in the bottom to recognise the approximate length of every feature <br>
&nbsp;&nbsp;&nbsp;&nbsp;5. embed svg in svg to make heatmap or scatter or line or histogram more easy to product, like example/out.svg*svg or \<foreignObject\> <br> <br>
Expand Down
70 changes: 70 additions & 0 deletions Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import fire"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def test(A:str, B:int):\n",
" print (f\"{A} type is {type(A)}\")\n",
" print (f\"{B} type is {type(B)}\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 type is <class 'str'>\n",
"3 type is <class 'str'>\n"
]
}
],
"source": [
"test(\"1\",\"3\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
5 changes: 4 additions & 1 deletion example/feature.crossing.link.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ gene_s203 gene_s303 cross_link_color #3CB371
gene_s203 gene_s303 cross_link_order 0
gene_s203 gene_s303 cross_link_anchor_pos medium_medium
gene_s203 gene_s303 cross_link_opacity 0.5
#gene_s203 gene_s303 cross_link_orientatation forward
gene_s203 gene_s303 cross_link_orientatation reverse


gene_s107,gene_s207,gene_s307,gene_s4070000
gene_s107,gene_s207,gene_s307,
gene_s307 gene_s4070000 cross_link_orientatation reverse

gene_s110,gene_s210,gene_s310,gene_s4050000
gene_s110 gene_s210 cross_link_color #00BFFF
Expand Down
4 changes: 3 additions & 1 deletion example/main.conf
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ legend_stroke_width=0.5
# crossling among features
crossing_link = feature.crossing.link.conf
cross_link_color = #FF8C00
cross_link_color_reverse = #3CB371
cross_link_opacity = 0.6
cross_link_anchor_pos = medium_medium # up,medium,low
cross_link_orientatation=forward
ignore_sharp_arrow=no # yes or no



#sort_by_one_feature = sort.feature # every track sort block's position by this feaure list(just only one feature for one track, if one traack not has one feature in this list , mean don't sort block's pos of this track )
#scaffold_order = order.list # if set this, will draw full-length of scaffold in gff, will ignore 4th col to last col of the --list
tracks_reorder=track.order.txt

# scale
scale_display=yes # yes or no
Expand Down
230 changes: 115 additions & 115 deletions example/out.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example/out7.dpi100.pdf
Binary file not shown.
8 changes: 4 additions & 4 deletions example/sample.name.new.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#old_sample_name new_sample_name new_sample_color(option) new_sample_font_size()


s1 S1
s2 S2
s3 S3
s4 S4
s1 s1
s2 s2
s3 s3
s4 s4

4 changes: 4 additions & 0 deletions example/track.order.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
s1
s2
s4
s3
57 changes: 44 additions & 13 deletions plot.genome.featureCluster.pl
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@
##

###start:get scaffold length in genome file and scaffold length in gff file of list
my ($genome, $gff, $sample_num) = &read_list($list);
my ($genome, $gff, $track_order, $sample_num) = &read_list($list);
my %genome=%$genome;
my %gff=%$gff;
my @track_order=@$track_order;
my @track_reorder;

&check_track_order();

my $ends_extend_ratio = 0.1;
foreach my $s(sort {$gff{$b}{chooselen_all}<=>$gff{$a}{chooselen_all}} keys %gff){
Expand All @@ -64,16 +68,14 @@
my $top_bottom_margin=$conf{top_bottom_margin};
my %orders;
my $svg="<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"$svg_width\" height=\"$svg_height\" >\n";
open LI,"$list" or die "$!";
my $top_distance=$top_bottom_margin/2*$svg_height;
my $sample_single_height = (1 - $top_bottom_margin)*$svg_height/$sample_num; # 每个track的高度
my $id_line_height = 0.05*$conf{genome_height_ratio}*2*$sample_single_height; # 每个block的genome的高度
my $left_distance_init = (1 + 0.1) * $ref_name_width_ratio * $svg_width ;#block左侧起点的x轴,0.1是指ref name和第一个block的间隔
while(<LI>){
chomp;
next if($_=~ /^#/ || $_=~ /^\s*$/);
while(@track_order){
$index++;
my ($sample,@tmp) = split(/\s+/,$_);
my $sample = shift @track_order;
die "error: $sample not in gff file of --list \n" if (not exists $gff{$sample});
my $block_distance = $space_len*$ratio; # block_distance 是每个block的间距
my $flag;
my $left_distance = $left_distance_init ;#block左侧起点的x轴,0.1是指ref name和第一个block的间隔
Expand Down Expand Up @@ -218,13 +220,13 @@


}
close LI;

# draw crossing_links for feature crosslink
foreach my $pair(keys %{$conf{crossing_link}{index}}){
#$conf{crossing_link}{index}{"$arr[0],$arr[1]"}{$arr[2]} = $arr[3];
my ($up_id, $down_id) = split(",", $pair);
my $color=(exists $conf{crossing_link}{index}{$pair}{cross_link_color})? $conf{crossing_link}{index}{$pair}{cross_link_color}:$conf{cross_link_color};
my $cross_link_orientatation=(exists $conf{crossing_link}{index}{$pair}{cross_link_orientatation})? $conf{crossing_link}{index}{$pair}{cross_link_orientatation}:$conf{cross_link_orientatation};
my $cross_link_opacity=(exists $conf{crossing_link}{index}{$pair}{cross_link_opacity})? $conf{crossing_link}{index}{$pair}{cross_link_opacity}:$conf{cross_link_opacity};
my $cross_link_order=(exists $conf{crossing_link}{index}{$pair}{cross_link_order})? $conf{crossing_link}{index}{$pair}{cross_link_order}:$conf{cross_link_order};
my $cross_link_anchor_pos=(exists $conf{crossing_link}{index}{$pair}{cross_link_anchor_pos})? $conf{crossing_link}{index}{$pair}{cross_link_anchor_pos}:$conf{cross_link_anchor_pos};
Expand Down Expand Up @@ -254,8 +256,13 @@
}elsif($cross_link_anchor_pos !~ /_medium$/){
die "error: not support $conf{cross_link_anchor_pos} yet~\n"
}
$orders{$cross_link_order}.="<polygon points=\"$left_up_x,$left_up_y $right_up_x,$right_up_y $right_down_x,$right_down_y $left_down_x,$left_down_y\" style=\"fill:$color;stroke:#000000;stroke-width:0;opacity:$cross_link_opacity\"/>\n"; #crossing link of features
#print "link corlis $color\n";
die "error: got $cross_link_orientatation for cross_link_orientatation, but must be reverse or forward for $pair\n" if($cross_link_orientatation!~ /reverse/i && $cross_link_orientatation!~ /forward/i);
if($cross_link_orientatation=~ /reverse/i){
$color=(exists $conf{crossing_link}{index}{$pair}{cross_link_color_reverse})? $conf{crossing_link}{index}{$pair}{cross_link_color_reverse}:$conf{cross_link_color_reverse};
$orders{$cross_link_order}.="<polygon points=\"$left_up_x,$left_up_y $right_up_x,$right_up_y $left_down_x,$left_down_y $right_down_x,$right_down_y\" style=\"fill:$color;stroke:#000000;stroke-width:0;opacity:$cross_link_opacity\"/>\n"; #crossing link of features
}else{
$orders{$cross_link_order}.="<polygon points=\"$left_up_x,$left_up_y $right_up_x,$right_up_y $right_down_x,$right_down_y $left_down_x,$left_down_y\" style=\"fill:$color;stroke:#000000;stroke-width:0;opacity:$cross_link_opacity\"/>\n"; #crossing link of features
}


}
Expand Down Expand Up @@ -413,14 +420,14 @@
print SVG "</svg>";
close SVG;
print "outfile is $outdir/$prefix.svg\n";
`set -vex;convert $outdir/$prefix.svg $outdir/$prefix.png ; echo outfile is $outdir/$prefix.png; convert -density $conf{pdf_dpi} $outdir/$prefix.svg $outdir/$prefix.dpi$conf{pdf_dpi}.pdf;echo outfile is $outdir/$prefix.dpi$conf{pdf_dpi}.pdf`;
`set -vx;convert $outdir/$prefix.svg $outdir/$prefix.png ; echo outfile is $outdir/$prefix.png; convert -density $conf{pdf_dpi} $outdir/$prefix.svg $outdir/$prefix.dpi$conf{pdf_dpi}.pdf;echo outfile is $outdir/$prefix.dpi$conf{pdf_dpi}.pdf`;

#$svg.=&draw_genes($gff{$sample}{id}{$id}{$index}{start},$gff{$sample}{id}{$id}{$index}{end},$gff{$sample}{id}{$id}{$index}{strand},$gene_height_medium,$gene_height_top);

sub read_list(){
###start:get scaffold length in genome file and scaffold length in gff file
my ($list) = @_;
my (%genome,%gff,$sample_num);
my (%genome,%gff,@track_order,$sample_num);
my @features=split(/,/, $conf{feature_keywords});
my %uniq_sample;
open LI,"$list" or die "$!";
Expand All @@ -431,6 +438,7 @@ ()
my $block_index=1;
my %scf_block_id;
my ($sample,$gffs,$genome,@arrs)=split(/\t/,$_); # $seq_id,$seq_draw_start,$seq_draw_end
push @track_order, $sample;
if(exists $uniq_sample{$sample}){
die "error:more than one $sample, not allow same 1th column in $list~\n "
}else{
Expand Down Expand Up @@ -567,7 +575,7 @@ ()
}
close LI;

return (\%genome, \%gff, $sample_num);
return (\%genome, \%gff, \@track_order, $sample_num);
####end:get scaffold length in genome file and scaffold length in gff file
}

Expand Down Expand Up @@ -1002,9 +1010,20 @@ ()
$conf{feature_border_size} ||=0;
$conf{feature_border_color} ||="black";
$conf{feature_opacity} =(defined $conf{feature_opacity})? $conf{feature_opacity}:1;
$conf{cross_link_orientatation} ||="forward";
$conf{cross_link_color} ||="#FF8C00";
$conf{cross_link_color_reverse} ||="#3CB371";



if(exists $conf{tracks_reorder}){
open OR,"$conf{tracks_reorder}" or die "$!";
while(<OR>){
chomp;
next if($_=~ /^\s*#/ || $_=~ /^\s*$/);
push @track_reorder, $_;
}
close OR;
}

#sample_name_old2new
if(exists $conf{sample_name_old2new}){
Expand Down Expand Up @@ -1114,3 +1133,15 @@ ()

}


sub check_track_order(){
return 1 if(@track_reorder ==0);
my $len = scalar(@track_order);
my $len_re = scalar(@track_reorder);
if($len != $len_re){
die "error: track_reorder has $len_re tracks which is not equal to --list\n";
}else{
@track_order = @track_reorder;
}

}

0 comments on commit a444ad5

Please sign in to comment.