pyGenomeTracks
pyGenomeTracks copied to clipboard
[Feature Request]: call pyGenomeTracks from python without a .ini file (or document this ability)
Hello @fidelram and others,
As always, many thanks for building this package and making it open source.
I'd love to call pyGenomeTracks from a python script without a .ini file. The signature might look something like this:
files = ["filename1.bigwig", "filename2.bigwig"]
pyGenomeTracks(files=files, region="chr9:120578911-120581531", outfile="outfile.jpg")
or maybe
track1 = pyGenomeTracks.Track("filename1.bigwig", options={...})
track2 = pyGenomeTracks.Track("filename2.bigwig", options={...})
tracks = [track1, track2]
pyGenomeTracks.plot(tracks=tracks, region="chr9:120578911-120581531", outfile="outfile.jpg")
What do you think? (If this is already possible, I might just be asking for documentation)
I will take a look at this when I have some time.
@fidelram , thanks for your great tool. How this feature going now? I think it's very handy to modify other components in the figure if this feature could be enabled.
This makes sense. Let's do this.
BTW, do we not have any documentation yet?
It would be nice to have example to call pyGenomeTracks inside python without saving to figure. I have many data to combine in one picture and I would like to call pyGenomeTracks only for some part of my final picture. Can you provide iPython notebook example of data exploring and drawing? Thanks
I really don't have time to dig into this.. sorry. But I noticed that the guys from CoolBox (https://github.com/GangCaoLab/CoolBox) integrated pyGenomeTracks into python notebooks. Maybe they can provide a better solution.
@Benja1972 What kind of tracks from pyg.tracks would you like to plot?
Thank for responses. For now I need to draw bigwig tracks and intersect it with my mutations tracks. I have prepared Kataegis script to plot variations density and want place ChiP-seq signals alongside. https://github.com/Benja1972/bioinformatics/blob/master/Kataegis.py
@Benja1972
Run this script in examples/
, as a standalone script.
import os
os.chdir(os.path.dirname(__file__))
import pyBigWig
with pyBigWig.open('bigwig.bw') as f:
print( f.chroms() )
import pygenometracks.tracks as pygtk
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2,1,sharex='col')
region = 'X',2700000,3100000
chrom_region,start_region,end_region = region
ax = axs[1]
track_config = dict(
file='./bigwig.bw')
tk = pygtk.BigWigTrack(track_config)
tk.plot(ax,chrom_region,start_region,end_region,)
fig.savefig('test-axplot-bigwig.png')
print ('[DONE]')
@shouldsee
Thank you! I will try
Just a gentle bump that this would be really nice to have. I played around with the code above @shouldsee and it seems to work well. So looks like it's nicely possible.. just not clearly stated how. Thanks for the package. I am happy to contribute if needed.
Hi, Sorry for the late response. You are right we should include it into our documentation. If you can write it this would be great, just make a PR I will be happy to review it.
There is a +1 from BCC2020... We should definitely integrate it.
Did anyone ever get to this?
We worked on it at some point but then we did not have enough time to finish up. This is something we have in mind: propose to fully use pyGenomeTracks as a package. At the moment, the version script above should still work. You can put your parameters in a dictionary and then initiate a track with this dictionary and use the method plot to display it.
wow 3 yrs has passed... what do we need now? doc? code? test case? @lldelisle
Hi, I feel bad... Indeed time passed and no real improvement... We wanted to take the opportunity of this new API support to tidy classes update variable names etc. but unfortunately we did not do much... I can write a doc now but it will be broken in the 4.0 version so not sure it worth it. But I don't know when 4.0 will be ready so... I don't know. I will check with my team mates.
Hi, I feel bad... Indeed time passed and no real improvement... We wanted to take the opportunity of this new API support to tidy classes update variable names etc. but unfortunately we did not do much... I can write a doc now but it will be broken in the 4.0 version so not sure it worth it. But I don't know when 4.0 will be ready so... I don't know. I will check with my team mates.
Okay I see. Shall we try adapting this for the v4.0? Not sure how much need is out there, but I personally predicts a small boost in performance in certain scenario, and you can always do more with a python API :D
Hi, Waiting for the 4.0, I put here a way to use pgt in python using the version 3.7 (the only version which allows to get the figure from the plot method) and add an arrow. This is clearly not a full documentation and I cannot guaranty this will still work on the 4.0 but waiting for us to get time to write the full API support, this is better than nothing:
import matplotlib as mpl
mpl.use('agg')
import pygenometracks.tracksClass
ini_file = 'bed_squares_overlay.ini'
trp = pygenometracks.tracksClass.PlotTracks(ini_file, dpi=150, plot_regions=[('X', 0, 10000000)])
current_fig = trp.plot("test2.png", "X", 3000000, 3300000)
current_fig.get_axes()[0].arrow(x=3100000, y=3000000, dx=0, dy=100000, facecolor='red', edgecolor='red', head_width=10000, head_length=10000)
current_fig.savefig("test3.png")
@sebgra, Could you explain exactly what you would like to do? I can guide you but pyGenomeTracks does not officially support api so what I explain for version 3.7 may be only valid for 3.7.
For info, the code proposed by @shouldsee above still work.
@sebgra, Could you explain exactly what you would like to do? I can guide you but pyGenomeTracks does not officially support api so what I explain for version 3.7 may be only valid for 3.7.
Works perfectly ! Thanks a lot