Trying to return a specified number of characters from a gene sequence in R

I have a DNA sequence, for example: cgtcgctgtttgtcaaagtcg....

maybe 1000 letters.

However, I want to see, for example, the letters 5 through 200 and define this subset of the string as a new object.

I tried to look at the function nchar, but did not find what would do it.

+3
source share
3 answers

Try

substr("cgtcgctgtttgtcaa[...]", 5, 200)

See substr () .

+9
source

Use the substring function:

> tmp.string <- paste(LETTERS, collapse="")
> tmp.string <- substr(tmp.string, 4, 10)
> tmp.string
[1] "DEFGHIJ"
+6
source

. Bioconductor Biostrings, , .

#source("http://bioconductor.org/biocLite.R");biocLite("Biostrings") 
library(Biostrings)
s <-paste(rep("gtcgctgtttgtcaac",20),collapse="")
d <- DNAString(s)
d[5:200]
as.character(d[5:200])
+3
source

Source: https://habr.com/ru/post/1718758/


All Articles