Skip to content

Commit

Permalink
Add option for custom chr_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
e-sollier committed Oct 10, 2024
1 parent 77e263c commit 2405d2b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/content/describe_figure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Parameters:

* ``ticks_angle``: Angle in degrees at which the ticks are written. The default (0) results in horizontal ticks, but you can also tilt them by increasing this value to e.g. 30. Rotating the ticks might result in them overlapping with the chromosome name, so you might want to post-process the figure in a vector graphics editor by manualling moving the chromosome name in case of overlap.

* ``chr_prefix``: Prefix to add before the chromosome names (default: "chr").

genes
^^^^^
Expand Down
2 changes: 1 addition & 1 deletion figeno/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from figeno.cli import gui, init,make

__version__ = "1.4.7"
__version__ = "1.5.0"

def main():
parser = ArgumentParser("figeno",formatter_class=ArgumentDefaultsHelpFormatter)
Expand Down
4 changes: 2 additions & 2 deletions figeno/gui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion figeno/gui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "figeno",
"version": "1.4.7",
"version": "1.5.0",
"private": true,
"homepage": "./",
"dependencies": {
Expand Down
4 changes: 4 additions & 0 deletions figeno/gui/src/Track.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ function ChrTrack({track,set_value}){
<div className='formItem'>
<label htmlFor={"ticks_angle"+track.id}>Ticks angle (°):</label>
<input id={"ticks_angle"+track.id} style={{width:"3em"}} value={track.ticks_angle} onChange={(e)=>set_value("ticks_angle",e.target.value)} ></input>
</div>
<div className='formItem'>
<label htmlFor={"chr_prefix"+track.id}>Chr prefix:</label>
<input id={"chr_prefix"+track.id} style={{width:"3em"}} value={track.chr_prefix} onChange={(e)=>set_value("chr_prefix",e.target.value)} ></input>
</div>
</>):""}
</div>
Expand Down
3 changes: 2 additions & 1 deletion figeno/gui/src/TracksContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const defaultTrackValues={
ticklabels_pos:"below",
unit:"kb",
ticks_interval:"auto",
ticks_angle:0
ticks_angle:0,
chr_prefix: "chr"
},
"genes":{
height:"10",
Expand Down
15 changes: 8 additions & 7 deletions figeno/track_chr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from figeno.utils import KnownException, split_box, draw_bounding_box , interpolate_polar_vertices, compute_rotation_text, polar2cartesian, cartesian2polar

class chr_track:
def __init__(self,style="default",unit="kb",ticklabels_pos="below",ticks_interval="auto",ticks_angle=0,lw_scale=1.0,no_margin=False,reference="custom",cytobands_file="",
def __init__(self,style="default",unit="kb",ticklabels_pos="below",ticks_interval="auto",ticks_angle=0,lw_scale=1.0,chr_prefix="chr",no_margin=False,reference="custom",cytobands_file="",
fontscale=1,bounding_box=False,height=12,margin_above=1.5,label="",label_rotate=False,**kwargs):
self.style=style
self.unit=unit
Expand All @@ -19,6 +19,7 @@ def __init__(self,style="default",unit="kb",ticklabels_pos="below",ticks_interva
self.lw_scale= float(lw_scale)
while self.ticks_angle<-180: self.ticks_angle+=360
while self.ticks_angle>180: self.ticks_angle-=360
self.chr_prefix=chr_prefix
self.no_margin=no_margin
self.reference=reference
self.fontscale=float(fontscale)
Expand Down Expand Up @@ -149,9 +150,9 @@ def draw_region(self,region,box,single_region=False):
# Chr label
if self.ticklabels_pos!="none":
if self.ticklabels_pos=="below" and (not "upside_down" in box):
box["ax"].text((box["left"]+box["right"])/2,box["bottom"],"chr"+region.chr,horizontalalignment="center",verticalalignment="bottom",fontsize=9*self.fontscale)
box["ax"].text((box["left"]+box["right"])/2,box["bottom"],self.chr_prefix+region.chr,horizontalalignment="center",verticalalignment="bottom",fontsize=9*self.fontscale)
else:
box["ax"].text((box["left"]+box["right"])/2,box["top"],"chr"+region.chr,horizontalalignment="center",verticalalignment="top",fontsize=9*self.fontscale)
box["ax"].text((box["left"]+box["right"])/2,box["top"],self.chr_prefix+region.chr,horizontalalignment="center",verticalalignment="top",fontsize=9*self.fontscale)

def draw_region_arrow(self,region,box):
arrow_height = (box["top"]-box['bottom']) * 0.5 *self.lw_scale
Expand Down Expand Up @@ -193,23 +194,23 @@ def draw_region_arrow(self,region,box):
fontsize=8*self.fontscale)

if self.ticklabels_pos=="below" and (not "upside_down" in box):
box["ax"].text((box["right"]+box["left"])/2,box["top"]-arrow_height*1.55,"chr"+region.chr.lstrip("chr"),horizontalalignment="center",verticalalignment="top",
box["ax"].text((box["right"]+box["left"])/2,box["top"]-arrow_height*1.55,self.chr_prefix+region.chr.lstrip("chr"),horizontalalignment="center",verticalalignment="top",
fontsize=10*self.fontscale)
else:
box["ax"].text((box["right"]+box["left"])/2,box["bottom"]+arrow_height*1.55,"chr"+region.chr.lstrip("chr"),horizontalalignment="center",verticalalignment="bottom",
box["ax"].text((box["right"]+box["left"])/2,box["bottom"]+arrow_height*1.55,self.chr_prefix+region.chr.lstrip("chr"),horizontalalignment="center",verticalalignment="bottom",
fontsize=10*self.fontscale)

def draw_region_ideogram(self,region,box):
height = (box["top"]-box["bottom"]) * 0.5 *self.lw_scale
if self.ticklabels_pos=="below" and (not "upside_down" in box):
y = box["bottom"] + (box["top"]-box["bottom"]) * 0.75
if self.fontscale>0:
box["ax"].text((box["left"]+box["right"])/2, box["top"]-height-1, "chr"+region.chr,
box["ax"].text((box["left"]+box["right"])/2, box["top"]-height-1, self.chr_prefix+region.chr,
horizontalalignment="center", verticalalignment="top",fontsize=10*self.fontscale)
elif self.ticklabels_pos=="above":
y = box["bottom"] + (box["top"]-box["bottom"]) * 0.25
if self.fontscale>0:
box["ax"].text((box["left"]+box["right"])/2, box["bottom"] + height+1, "chr"+region.chr,
box["ax"].text((box["left"]+box["right"])/2, box["bottom"] + height+1, self.chr_prefix+region.chr,
horizontalalignment="center", verticalalignment="bottom",fontsize=10*self.fontscale)
else:
y= (box["bottom"]+box["top"]) / 2
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ packages = ["figeno", "figeno.data", "figeno.cli", "figeno.gui"]

[project]
name = 'figeno'
version = "1.4.7"
version = "1.5.0"
description = 'Package for generating genomics figures.'
readme = 'README.md'
authors = [
Expand Down

0 comments on commit 2405d2b

Please sign in to comment.