This is a test version of Biostars. For the public version, visit https://www.biostars.org.
define a variable of type list of different lengths

hi How can define a variable of type list of different lengths? and how can define n different xS in the for loop? for example

xS in for loop

library(seqinr)
x1=read.fasta("dbppt.fasta", seqtype="AA")
library(protr)
x2=getSequence(x1)
s=matrix(data = NA, nrow = 31012, ncol = 1, byrow = FALSE,dimnames = NULL)
for(n in 1:31012) {
  s[n]= c2s(x2[[n]])

}
for(n in 1:31012){
  xS=protseg(s[n] , aa="S", k=7)
}
r sequence

Simple. Don't use a for loop.

... blah blah blah
n_to_protseg <- function(n, X = x2){
  protseg(  c2s(X[[n]]), aa = 'S', k = 7 )}

xS <- lapply(1:31012, n_to_protseg)

1 answer

library(seqinr)
x1=read.fasta("dbppt.fasta", seqtype="AA")
library(protr)
x2=getSequence(x1)
s=matrix(data = NA, nrow = 31012, ncol = 1, byrow = FALSE,dimnames = NULL)
for(n in 1:31012) {
  s[n]= c2s(x2[[n]])

}

xS=list()

for(n in 1:31012){
  xS[[n]]=protseg(s[n] , aa="S", k=7)
}

Log in to answer this question.