Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plotting bedgraph data for all chromosome at once #139

Open
nirvana693 opened this issue May 5, 2023 · 6 comments
Open

plotting bedgraph data for all chromosome at once #139

nirvana693 opened this issue May 5, 2023 · 6 comments
Assignees
Labels
usage question User question about how to use the package

Comments

@nirvana693
Copy link

Hi @bernatgel
Thank you for the awesome tool.

I have a bedgraph data containing genomic window and motif count

chr1	150000	150010	353
chr10	150000	150010	326
chr10	134700000	134700010	220
chr10	134850000	134850010	366
chr10	135000000	135000010	355
chr10	135150000	135150010	3
chr11	150000	150010	329

I can successfully draw the data using kpBars for each chromosome
image

But how do I do it for all chromosomes at once in single image? I checked this biostar thread , example given is for single chromosome.

any help would be appreciated. Thank you

@bernatgel bernatgel self-assigned this May 5, 2023
@bernatgel bernatgel added the usage question User question about how to use the package label May 5, 2023
@bernatgel
Copy link
Owner

Hi @nirvana693

I'm not sure I see what the problem is, so I'll try my best to guess it. Please correct me if I'm wrong.

If you are able to plot for a single chromosome, the only thing you need to do to plot the whole genome is changing chromosomes="chr8" in plotKarytype to chromosomes="canonical" or removing the parameter altogether. If you want to plot all chromosomes in a single line, then you should add plot.type=3 (or 4, or 5) depending on the exact type of plot you need. You can see the different plot type in the karyoploteR tutorial. You might need to adjust the plotting parameters too, to get a nicer looking plot. you can get that and the code to plot the chromosome names without overlaps in other examples in the sample page.

Hope this helps. And if this was not exactly what you were asking, fell free to reopen the issue :)

Bernat

@nirvana693
Copy link
Author

nirvana693 commented May 8, 2023

hi @bernatgel,

Thank you for the quick response.

Approach1: As shown in my 1st post, when I draw chromosome wise (telomere_plot.R), results are as expected.
Approach2: I removed chromosomes option to plot all chromosome at once using below code:

library(karyoploteR)
library(rtracklayer)
args <- commandArgs(trailingOnly=TRUE)

hcov=args[1]
hcov20=args[2]
cl3=args[3]
outfile=paste(cl3,".pdf", sep="")

hcov_rep= import(hcov, format="bedgraph")
hcov20_rep=import(hcov20, format="bedgraph")
chm13 <- toGRanges("chm13_length.txt")
chm13_cyto <- toGRanges("chm13v2.0_cytobands_allchrs.txt")
pdf (outfile, width=10, height=12)

chrl=c(1:22, "X", "Y")
kp <- plotKaryotype(genome = chm13, cytobands = chm13_cyto, plot.type=2)
#kpAddBaseNumbers(kp, tick.dist = 10000000, tick.len = 10, tick.col="red", cex=1, minor.tick.dist = 1000000, minor.tick.len = 5, minor.tick.col = "gray")

kpDataBackground(kp, data.panel = 1, col="lavender")
kpBars(kp,data= hcov_rep, y1=hcov_rep$score, data.panel=1, ymax=max(hcov_rep$score))
#kpAxis(kp, side = 1, numticks = 2, ymin=0, ymax=max(hcov_rep$score), cex=0.8, data.panel = 1)

kpDataBackground(kp, data.panel = 2, col="lightpink")
kpBars(kp,data=hcov20_rep, y1=hcov20_rep$score, data.panel=2, ymax=max(hcov20_rep$score))
#kpAxis(kp, side = 1, numticks = 2, ymin=0, ymax=max(hcov20_rep$score), cex=0.8, data.panel = 2)
dev.off()

as a result of ymax from the whole dataset (in my dataset chr15), data in many chromosomes are not clearly visible.
image

Approach3: So, I tried plotting karyotype outside the loop and process chromosome wise inside the loop as follows:

library(karyoploteR)
args <- commandArgs(trailingOnly=TRUE)
hcov=args[1]
hcov20=args[2]
cl3=args[3]
outfile=paste(cl3,".pdf", sep="")
hcov_rep=read.table(hcov, sep="\t", header=F)
hcov20_rep=read.table(hcov20, sep="\t", header=F)
chm13 <- toGRanges("chm13_length.txt")
chm13_cyto <- toGRanges("chm13v2.0_cytobands_allchrs.txt")
pdf (outfile, width=10, height=15)
chrl=c(1:22, "X", "Y")
pp <- getDefaultPlotParams(2)
pp$data2inmargin <- 50
pp$data1inmargin <- 50
**kp <- plotKaryotype(genome = chm13, cytobands = chm13_cyto, plot.type=2, plot.params = pp)**  
for (i in chrl)
{
  echr=paste("chr", i, sep="")
  cat (paste("Processing of ", echr, "Started\n"))
  
  hcov_subset=subset(hcov_rep, V1==echr)
  cov_max=max(hcov_subset$V4)
  hcov20_subset=subset(hcov20_rep, V1==echr)
  cov20_max=max(hcov20_subset$V4)
  covmax= max (cov20_max,cov_max)
  
  kpDataBackground(kp, data.panel = 1, col="lavender", r0=0.1, r1=0.7)
  kpBars(kp,chr=echr,x0=hcov20_subset$V2, x1=hcov20_subset$V3, y1=hcov20_subset$V4, ymax=covmax, data.panel=1, r0=0.1, r1=0.7)
  
  kpDataBackground(kp, data.panel = 2, col="lightpink", r0=0.1, r1=0.7)
  kpBars(kp,chr=echr,x0=hcov_subset$V2, x1=hcov_subset$V3, y1=hcov_subset$V4, ymax=covmax, data.panel=2, r0=0.1, r1=0.7)
  cat (paste("Plot for ", echr, "is completed\n"))
}
dev.off()

plot generated without any error/warnings but it appears that chomosome wise data is not rendered correctly.
image

I am trying to plot number of telomere motifs from a assembled genome on chm13. Any suggestions on better representation would be helpful.
I have attached the files in case you want to try. Apologies for the long text.
Thank you
chm13_length.txt
chm13v2.0_cytobands_allchrs.txt
vhap_bedgraph.txt
vhap2_bedgraph.txt

@bernatgel
Copy link
Owner

Hi @nirvana693

Thanks for the report and the attached files! I'll take a look at it and try to find out what's going on. I won't be able to take a look at it at least until next Wednesday, though.

If you have any other advance in the meantime, please let me know

Bernat.

@nirvana693
Copy link
Author

Hi @bernatgel
Thank you.
Is there a way to adjust to chromosome wise scale when granger object (using import function) used?

@nirvana693
Copy link
Author

@bernatgel Approach 3 works perfectly if I add the kpDataBackground outside the loop instead of using it in for loop as I did before. not sure why few chromosomes are rendered when kpDataBackground used in for loop.

Thank you.

@bernatgel
Copy link
Owner

Thanks for the updates! This is a strange behaviour. I'll take a look at it!

@bernatgel bernatgel reopened this Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usage question User question about how to use the package
Projects
None yet
Development

No branches or pull requests

2 participants