# Reducing a string to a certain amount of the first characters in R

So I have a list of several thousand RNA transcripts, and I am trying to find out how they are spliced. Right now I am running matchLRpatterns() from the Biostrings package with a max gap length of 0, after running a matchpattern function to categorize the transcripts by donor sites (where the first cut in an RNA transcript is made to cut out introns). But applying that to several thousand transcripts is quite time consuming, when you have 5 donor sequences to match to 9 acceptor sequences in 100 nucleotide long transcripts. Instead, I am thinking to sort by donor, remove all that comes before the splice junction by converting it to a string then using gsub, then using matchpattern again, but I only want to check the first 8 nucleotides after the splice junction for the consensus sequence that follows my list of acceptor sites. If I just run matchpattern without shortening the length of the transcript, I will just find acceptor sites in the RNA transcript, not the acceptor site at the splice junction.

I was thinking lapply the gsub function to the transcripts to remove up to the splice junction, then lapply the strsplit function to make a list of lists of groups of 1 character strings, lapply the head function to get the first 8 single character strings in each list, lapply the paste function to make them one string again, lapply the DNAString function to make the sequences readable by matchpattern, then lapply the matchpattern function to check the acceptor sequence at the splice junction. Is there a better way? This feels a bit clunky and roundabout way of doing it. I know gsub can remove characters after a certain character or sequence of characters, but I am not sure what the first sequence in each transcript is at the splice junction. Can I still use gsub, but tell it to remove characters after a certain number of characters? Or better yet, is there a way to get matchpattern to only check the first x nucleotides in a sequence?

• Please edit your question and include i) an example of your input data, ii) the output you would want from that data and iii) the code you are currently using so we don't reinvent the wheel. Jul 6, 2019 at 12:42
• I suggest you follow @terdon suggestion to increase the likelihood of receiving help. The task you are referring to in the title can be easily achieved via the following: smallx<-substr(x, start, stop) Jul 6, 2019 at 14:13