<p>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:</p>

<p><a href="https://genomebiology.biomedcentral.com/articles/10.1186/s13059-017-1284-1" rel="nofollow noreferrer">https://genomebiology.biomedcentral.com/articles/10.1186/s13059-017-1284-1</a></p>

<blockquote>
  <p>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.</p>
</blockquote>

CC BY-SA 4.0
2019-07-06T14:58:00.893Z
I was unaware of the existence of Lace and SuperTranscripts. My mentor in the lab I just started in wanted me to write code in R to help organize his Illumina reads for his research. I can ask him if he has heard of it, and if he would consider using it.
Joe Kowzun
CC BY-SA 4.0
2019-07-06T14:43:32.370Z
2019-07-06T14:43:32.370Z
gringer
<p>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 <code>matchLRpatterns()</code> from the Biostrings package with a max gap length of 0, after running a <code>matchpattern</code> 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 <code>gsub</code>, then using <code>matchpattern</code> 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 <code>matchpattern</code> 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.</p>

<p>I was thinking <code>lapply</code> the <code>gsub</code> function to the transcripts to remove up to the splice junction, then <code>lapply</code> the <code>strsplit</code> function to make a list of lists of groups of 1 character strings, <code>lapply</code> the <code>head</code> function to get the first 8 single character strings in each list, <code>lapply</code> the <code>paste</code> function to make them one string again, <code>lapply</code> the <code>DNAString</code> function to make the sequences readable by matchpattern, then lapply the <code>matchpattern</code> 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?</p>

CC BY-SA 4.0
2019-07-06T12:42:35.343Z
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.
terdon
CC BY-SA 4.0
2019-07-06T14:13:42.847Z
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)
Fabio Marroni
<r>
Reducing a string to a certain amount of the first characters in R
# Reducing a string to a certain amount of the first characters in R

(Asked by: username_0 on 2019-07-05)

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?

**Tags:** r
> **Comments:**
> **username_1**: 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.  
> **username_2**: 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)  

---

## 1 answers

### Answer by username_3 on 2019-07-06. Score: 1

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.

> **Comments:**
> **username_0**: I was unaware of the existence of Lace and SuperTranscripts. My mentor in the lab I just started in wanted me to write code in R to help organize his Illumina reads for his research. I can ask him if he has heard of it, and if he would consider using it.  

---

