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?
Is there any particular reason why you want to do this via pattern matching in R? This sounds like something that SuperTranscripts and Lace might be useful for:

https://genomebiology.biomedcentral.com/articles/10.1186/s13059-017-1284-1


  Finally, Lace will annotate each superTranscript with blocks either by using the graph structure itself or alternatively using a script called Mobius (packaged with Lace) which infers the annotation from spliced junctions discovered when mapping reads to the superTranscript.