This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to resolve the error which I get when I try to make objects for GRanges.

Hi,

I am trying to use ChIPseeker to annotate the ChIP peaks which I called using MACS2.

I don't know why I get this error:

Error in .normarg_seqnames1(seqnames) : object 'chr' not found

when I try to make objects for GRanges using this command:

H3K27me3_Rep1 <- with(H3K27me3_Rep1, 
                    GRanges(chr,
                            IRanges(start,end),
                    length=length,
                    log10q = qvalue
                    ))

The same command works perfectly fine on other CSV files. I have tried writing chromosome names in different formats like "chr1,chr2..." also "chrI, chrII..." etc nothing seems to work. Do you know what might be the problem?

Any help will be highly appreciated.

Thanks

-S

chipseeker granges

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. If your code has long lines with a single command, break those lines into multiple lines with proper escape sequences so they're easier to read and still run when copy-pasted. I've done it for you this time.
code_formatting

Thanks for pointing it out. I didn't know.

1 answer

That error typically refers to missing column names. Either your CSV doesn't contain the column names in the first line as header or there is another issue with reading that file in.

What is the output of

str(H3K27me3_Rep1)

?

Hi, Thanks for getting back. My file has headers. I am also able to read the file. This is what I get after doing str(H3K27me3_Rep1)

    > str(H3K27me3_Rep1)
'data.frame':   14275 obs. of  5 variables:
 $ ï..chr: chr  "chrI" "chrI" "chrI" "chrI" ...
 $ start : int  624 37913 44456 45428 55598 56728 58907 119676 122471 138332 ...
 $ end   : int  1212 38522 44729 45776 56205 57172 60163 121109 122871 139406 ...
 $ length: int  589 610 274 349 608 445 1257 1434 401 1075 ...
 $ qvalue: num  5.02 3.62 2.5 2.54 3.76 ...

Then we already have identified the culprit. The name of the first column is mangled. It should be chr but in reality is ï..chr. You can test that with trying to access H3K27me3_Rep1$start (should work) and H3K27me3_Rep1$chr (should return NULL).

You can now either manually rename the first column in R with colnames(H3K27me3_Rep1)[1] <- "chr" or fix the source CSV file by removing the non-displayable character(s) before the chr that R reads as ï...

Lycka till from Sweden Matthias

Ahh!!!!! Thanks so so much!!!!! This makes sense. I don't know why I didn't notice. How careless of me.

Log in to answer this question.