GRanges R
1
0
Entering edit mode
2.6 years ago
mera El ▴ 10

Hi, I have a small question

When I try to run this code, everything seems to be good :

# load refrence fasta file
dna <- readDNAStringSet('hg19.fasta')
# Find chromosome
dna.chr <- dna[grep('11',names(dna))]
names(dna.chr) <- '11'
# set chromosome poriostion
gr <- GRanges('11: 108121429')
print(gr)

output :

> > GRanges object with 1 range and 0 metadata columns:
> >       seqnames    ranges strand
> >          <Rle> <IRanges>  <Rle>   [1]       11 108121429      *
> 
>   -------   seqinfo: 1 sequence from an unspecified genome; no
> seqlengths

But when I try to change the code to this by adding a variable:

# load refrence fasta file
dna <- readDNAStringSet('hg19.fasta')
# Find chromosome
dna.chr <- dna[grep('11',names(dna))]
names(dna.chr) <- '11'
# set chromosome poriostion
i <- 108121429
gr <- GRanges('11:i')
print(gr)

output:

I get this error

> Error in asMethod(object) :    The character vector to convert to a
> GRanges object must contain strings of the form   "chr:start-end" or
> "chr:start-end:strand", with end >= start - 1, or "chr:pos" or  
> "chr:pos:strand". For example: "chr1:2501-2900", "chr1:2501-2900:+",
> or "chr1:740". Note   that ".." is a valid alternate start/end
> separator. Strand can be "+", "-", "*", or   missing.

The problem is that I need to have a variable inside Granges to make a boucle. Anyone have a solution? Thank you very much

chromosome GRanges position R • 1.1k views
ADD COMMENT
1
Entering edit mode
2.6 years ago

'11:i' is a literal string, meaning that i won't be substituted with 108121429 and will be just the letter 'i'. Instead you need to programmatically construct the string.

GRanges(paste0("11:", i))
ADD COMMENT
0
Entering edit mode

Thank's a lot !! That solved the problem

ADD REPLY

Login before adding your answer.

Traffic: 1789 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