Apologies for not being clear. There can be other mutation types also like G>T, G>C,T>A... etc.
• 1 views
•
link
I have a list of strings of the format "c.2455C>T".
How can I extract the mutation type or the "C>T" part from the string?
grep "[ATGC]>[ATGC]" file.txt > output.txt
using simple grep command you can extract the line based on pattern. for e.g
grep "C>T" file.txt >output.txt
and grep can be done in R as well
a <- c("c.2455C>T","c.2455C>G","c.2455C>A")
b <- grep(pattern = "[C]>[TG]",a,perl = TRUE,value = TRUE) # as Pierre suggested
b
[1] "c.2455C>T" "c.2455C>G"
Apologies for not being clear. There can be other mutation types also like G>T, G>C,T>A... etc.
Assuming you want just the mutation type part, you can strip the string with sed -E 's|.+[0-9_]+||g'
$ echo -e "c.2455C>T\nc.234A>G\nc.6345TTT>G\nc.4375_4376insACCT\nc.4375_4379del"
c.2455C>T
c.234A>G
c.6345TTT>G
c.4375_4376insACCT
c.4375_4379del
$ echo -e "c.2455C>T\nc.234A>G\nc.6345TTT>G\nc.4375_4376insACCT\nc.4375_4379del" | sed -E 's|.+[0-9_]+||g'
C>T
A>G
TTT>G
insACCT
del
Note: If your input is any HGVS cDNA mutation, you may get del,ins,delins etc. and not just substitutions (e.g. A>T).
In R just use gsub
> gsub("c.4375_4376insACCT", pattern=".+[0-9_]+", replacement="")
[1] "insACCT"
Log in to answer this question.
Like with most of your questions, you should start by showing some effort, like what you've tried and how your data look like. Are there edge cases like indels or in general cases where you have non 1vs1 nucleotide changes? Show an example (more than n=1) of the data. Brief Reminder On How To Ask A Good Question
Sorry about that. I have read the link you shared and will definitely consider them all while asking questions in the future.