pyGenomeTracks icon indicating copy to clipboard operation
pyGenomeTracks copied to clipboard

[Feature Request]: call pyGenomeTracks from python without a .ini file (or document this ability)

Open alexlenail opened this issue 6 years ago • 23 comments

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)

alexlenail avatar Mar 27 '18 21:03 alexlenail

I will take a look at this when I have some time.

fidelram avatar Apr 05 '18 11:04 fidelram

@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.

zqfang avatar Jul 12 '18 03:07 zqfang

This makes sense. Let's do this.

BTW, do we not have any documentation yet?

shouldsee avatar May 02 '19 17:05 shouldsee

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

Benja1972 avatar May 07 '19 12:05 Benja1972

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.

fidelram avatar May 08 '19 14:05 fidelram

@Benja1972 What kind of tracks from pyg.tracks would you like to plot?

shouldsee avatar May 08 '19 15:05 shouldsee

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 avatar May 09 '19 07:05 Benja1972

@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 avatar May 13 '19 12:05 shouldsee

@shouldsee

Thank you! I will try

Benja1972 avatar May 13 '19 12:05 Benja1972

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.

raivivek avatar Apr 20 '20 03:04 raivivek

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.

lldelisle avatar May 21 '20 08:05 lldelisle

There is a +1 from BCC2020... We should definitely integrate it.

lldelisle avatar Jul 20 '20 18:07 lldelisle

Did anyone ever get to this?

alexlenail avatar Aug 17 '21 16:08 alexlenail

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.

lldelisle avatar Aug 18 '21 06:08 lldelisle

wow 3 yrs has passed... what do we need now? doc? code? test case? @lldelisle

shouldsee avatar Oct 14 '21 17:10 shouldsee

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.

lldelisle avatar Oct 15 '21 08:10 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.

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

shouldsee avatar Oct 16 '21 08:10 shouldsee

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")

lldelisle avatar May 24 '22 08:05 lldelisle

@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.

lldelisle avatar May 24 '22 08:05 lldelisle

For info, the code proposed by @shouldsee above still work.

lldelisle avatar May 24 '22 08:05 lldelisle

@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

sebgra avatar May 24 '22 11:05 sebgra