RNA-seq coverage plots via ggplot --> Error in as.vector(x, "character") : cannot coerce type 'environment' to vector of type 'character'
1
0
Entering edit mode
7.2 years ago

Hi there! I am very new in this field and learning bit by bit. really appreciate your help! I am trying to normalize a set of RNA-seq data chromsome by chromsome in my case. Before normalisation, I just want to plot coverage on individual chromosomes. Here is my code from bioconductor:

>library(GenomicAlignments)
>library(Rsamtools)
>library(ggplot2)

>elution_wt1 <- "/Users/berkyurekahmetcan/Dropbox (ericmiskalab)/cambridge-UK/NGS/piChIP/smallRNA/elution/wt1/elution_wt1_22Gs_dedup.bam"

## Coverage of a GAlignments object:

>elution_wt1_gal <- readGAlignments(elution_wt1)
>elution_wt1_cvg <- coverage(elution_wt1_gal)
>elution_wt1_cvg

>elution_wt2 <- "/Users/berkyurekahmetcan/Dropbox (ericmiskalab)/cambridge-UK/NGS/piChIP/smallRNA/elution/wt2/elution_wt2_22Gs_dedup.bam"


## Coverage of a GAlignments object:

>elution_wt2_gal <- readGAlignments(elution_wt1)
>elution_wt2_cvg <- coverage(elution_wt1_gal)
>elution_wt2_cvg

>elution_wt3 <- "/Users/berkyurekahmetcan/Dropbox (ericmiskalab)/cambridge-UK/NGS/piChIP/smallRNA/elution/wt3/elution_wt3_22Gs_dedup.bam"


## Coverage of a GAlignments object:

>elution_wt3_gal <- readGAlignments(elution_wt1)
>elution_wt3_cvg <- coverage(elution_wt1_gal)
>elution_wt3_cvg

>vctr1 <- as.vector(elution_wt1_cvg[[8]])
>vctr2 <- as.vector(elution_wt2_cvg[[8]])
>vctr3 <- as.vector(elution_wt3_cvg[[8]])

#[[8]] corresponds to the piRNAsensor, which is an extrachromosomal addition!

>wt1 = as.data.frame(vctr1)
>wt2 = as.data.frame(vctr2)
>wt3 = as.data.frame(vctr3)

>x = 1:1663
>y = wt1[,1]
>coverage = data.frame(x,y)
>p = ggplot(coverage) + aes(color = "red") + labs(title = 'elution_wt1', x = 'bps (piRNAsensor)', y = 'Coverage') + scale_x_continuous(scale_fill_grey(start = 1, end = 1663, na.value = "red")) + scale_y_continuous(limits=c(0, 10)) 
>ggsave("wt1.pdf",p)

When I run this script, I get an error as:

> source('~/Dropbox (ericmiskalab)/cambridge-UK/NGS/piChIP/smallRNA/coverage.R')
> p
Error in as.vector(x, "character") : 
  cannot coerce type 'environment' to vector of type 'character'

I would really appreciate your help in this case. Is there any problem with my code? How can I resolve this issue?

RNA-Seq sequencing • 3.9k views
ADD COMMENT
0
Entering edit mode

You're not actually starting the lines with > in coverage.R, I hope.

ADD REPLY
0
Entering edit mode

of course not :). I was just trying to find the best way to write the code in this platform.

ADD REPLY
0
Entering edit mode
7.2 years ago

I think I found the solution by myself. "aes" must be specificed within ggplot!

p = ggplot(coverage, aes(x=x, y=y)) + labs(title = 'elution_wt1', x = 'bps (piRNAsensor)', y = 'Coverage') + scale_x_continuous(scale_fill_grey(start = 1, end = 1663, na.value = "red")) + scale_y_continuous(limits=c(0, 10))

ggsave("wt1.pdf",p)

ADD COMMENT

Login before adding your answer.

Traffic: 2096 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6