This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to extract the first and last 2 nt from multiple sequences in a FASTA file?

Hi Everyone, I have multiple intron sequence fasta file. I would like to extract first and last 2 nucleotide sequence from that file. Please let me know if you have any suggestion or short code?

perl awk fasta genome sequence

1 answer

Try seqkit subseq

# example
$ cat t.fasta
>s1
acntg
>s2
ACNNTG

# first 2 bases
$ seqkit subseq -r 1:2 t.fasta 
>s1
ac
>s2
AC

# last 2 bases
$ seqkit subseq -r -2:-1 t.fasta 
>s1
tg
>s2
TG

# first 2 +  last 2, although every strange
$ seqkit concat <(seqkit subseq -r 1:2 t.fasta) <(seqkit subseq -r -2:-1 t.fasta)
>s1
actg
>s2
ACTG

Thank you very much

Accept this answer to mark the post as solved, and please don't ask the same question again.

Log in to answer this question.