[R] Problem with substr

Sarah Goslee sarah.goslee at gmail.com
Wed Nov 16 03:32:21 CET 2011


Hi,

On Tue, Nov 15, 2011 at 4:31 PM, sophy1987 <yatingcheng.marina at gmail.com> wrote:
> Hi, everyone
> When I ran this cript,  There is Error in substring(tmp.subject, tmp.end[ex]
> + 1, tmp.start[ex + 1] - 1) :
>  invalid substring argument(s)
>
> Could someone figure out what the problem is?

Not without a reproducible example. We don't know what tmp.subject
is, or tmp.start or tmp.end, since they're both derived from tmp.align
and we don't have that either.

Presumably there's something wrong with one of the arguments to
substring, but there's no way we can figure out which one.

Sarah

> for(i in 1:length(genebody[,1])){
>
>        tmp.id<-as.vector(genebody[i,1])                                                                                        # get gene id
>        tmp.subject<-as.vector(genebody[i,2])                                                                           # get gene sequence
>        tmp.exons<-exons[which(exons[,1]==tmp.id),]                                                                     # get exons of the
> selected genes
>
>        tmp.pattern<-as.vector(tmp.exons[,3])                                                                           # define exons as patterns
> for alignment
>        tmp.align<-pairwiseAlignment(pattern=tmp.pattern,
> subject=tmp.subject,type="local")                       # align all exons pairwise to gene
> sequence
>        tmp.start<-start(subject(tmp.align))                                                                            # vector of all alignment
> starts
>        tmp.end<-end(subject(tmp.align))                                                                                        # vector of all alignment ends
>
>        for(ex in 1:(length(tmp.end)-1)){                                                                                       # extract introns
>
>                tmp.intron<-substr(tmp.subject,tmp.end[ex]+1,tmp.start[ex+1]-1)
>
>
> introns<-rbind(introns,cbind(tmp.id,tmp.end[ex]+1,tmp.start[ex+1]-1,tmp.intron))
>
>                                }
>
>        }
>
>
> Thank you



-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list