Want to reverse the fasta sequence
2
0
Entering edit mode
3.7 years ago
harry ▴ 40
>ENST00000014935
TAGGTTTTTAATTACCTTTATTTTATTTTGCCAAACATACCTGGGAATACCTTTTATTTTTTTTTTACCTTGGGGTGATGGTTCCAAACCATAAATGTGATTATAGTTAACACATGACCCTTCTAGCGTCCCAGCCAGTGTTTTTCCTGACCTCTCTTCTTTGGAGAGGAGGATGGAAGGGAGGGGTCCGGCATGCTGCTGGCATTTTGCTGTGTCCTGCAGCCCCTTTCCGGGACACCTGGGTTCACACAGCTTTTTAGCTTACATAACTGGTGCAGATTTTCTGTGTGGAGATGTTGCCTTGACCAGCCTTGGCTGGACTTTACCAGGCATGCAGAAGCCTGTACCAACACAGACTACAGCACCCAGGAGGTGCGAGTGTGGCTGCTCAGCGGTTATAACAGGCCTGACTGCATTGTTCACCGGATTATAATGAGCCAAAATGTTTCCCGGTGTTTGCTGGTTTCAGGGAAGGAGTTTGATATAGCAGATTAACCACCCTCCTTGTAGCTATTGGGGCTTAATGGTTTCCTGGTGATTCTTACCAATCCACAATAAACATGGCCCATTGGCATATCTGCTGCACAAGTGTCCTATCTCACCAATCTGGGTTTTTGTTCTCAGTAACTTTCCTTCTTGTCATACAACATCTTCATTCCTCTTTCTGAACCCTCCCTTCCCCTACCCCAACCCAGAGCCCACTTTGTCTCCACTCCTGATACTACACTACCTGGCAGGTGGCATGAGTGCAGGGCCCCTGGCTTCCTCTCCTAATCTAGGCACAAGCCCAACCAAAGAACAAGAGCCAAATCAAACAAGGCAGGCAGGGGTGGACTACAGTCACAGGGCAACTATAGTTGAAGCCCCCCAGCCCCAGGGCTGGATGGACGGGGGAGGCTGGGGTTTAAGTCCCAAAAGGCAGCAGGCCCTGGGGGGGTAGGGGGACGCTCAGGCAGCAGGGCACAGCTGAGGGGACAGGAGTGATAGCAGCAACAGAACAGTGAGGCTGAGAGGCTGGACGCTGTGCGCCTGGCTCAGCTTCAGCTCCACCTCCACGGGGTAGTGGTCACTGATGTTGAGGGC
>ENST00000014944
TCCTCCTCGGTGAGCTGGAAGCTCGTGGGGAAGTCAAAGGCAGCCGCAGTGTGCAGCAGACTCCGGCAGCGCTCCCCGTGCAGCACGACGCGGTCATAGGTGCAGTGGGTGCTGGCCCGCACTGTGGTGTCCTCCCCATCGGCAATCACCCAGTGGAAGCCTGGCTCAGTCCGCAGCTCCAGCTTGTCCAGGCGCTTTTTGGTCAGTGAAGCGCAGTCAGCATTGAAGTCCCCAAGCAGGATCACGTC

Likewise, I have a huge fasta sequence and I want to reverse the sequence of those fasta sequences like below:-

>ENST00000014935
CGGGAGTTGTAGTCACTGGTGATGGGGCACCTCCACCTCGACTTCGACTCGGTCCGCGTGTCGCAGGTCGGAGAGTCGGAGTGACAAGACAACGACGATAGTGAGGACAGGGGAGTCGACACGGGACGACGGACTCGCAGGGGGATGGGGGGGTCCCGGACGACGGAAAACCCTGAATTTGGGGTCGGAGGGGGCAGGTAGGTCGGGACCCCGACCCCCCGAAGTTGATATCAACGGGACACTGACATCAGGTGGGGACGGACGGAACAAACTAAACCGAGAACAAGAAACCAACCCGAACACGGATCTAATCCTCTCCTTCGGTCCCCGGGACGTGAGTACGGTGGACGGTCCATCACATCATAGTCCTCACCTCTGTTTCACCCGAGACCCAACCCCATCCCCTTCCCTCCCAAGTCTTTCTCCTTACTTCTACAACATACTGTTCTTCCTTTCAATGACTCTTGTTTTTGGGTCTAACCACTCTATCCTGTGAACACGTCGTCTATACGGTTACCCGGTACAAATAACACCTAACCATTCTTAGTGGTCCTTTGGTAATTCGGGGTTATCGATGTTCCTCCCACCAATTAGACGATATAGTTTGAGGAAGGGACTTTGGTCGTTTGTGGCCCTTTGTAAAACCGAGTAATATTAGGCCACTTGTTACGTCAGTCCGGACAATATTGGCGACTCGTCGGTGTGAGCGTGGAGGACCCACGACATCAGACACAACCATGTCCGAAGACGTACGGACCATTTCAGGTCGGTTCCGACCAGTTCCGTTGTAGAGGTGTGTCTTTTAGACGTGGTCAATACATTCGATTTTTCGACACACTTGGGTCCACAGGGCCTTTCCCCGACGTCCTGTGTCGTTTTACGGTCGTCGTACGGCCTGGGGAGGGAAGGTAGGAGGAGAGGTTTCTTCTCTCCAGTCCTTTTTGTGACCGACCCTGCGATCTTCCCAGTACACAATTGATATTAGTGTAAATACCAAACCTTGGTAGTGGGGTTCCATTTTTTTTTTATTTTCCATAAGGGTCCATACAAACCGTTTTATTTTATTTCCATTAATTTTTGGAT
>ENST00000014944
CTGCACTAGGACGAACCCCTGAAGTTACGACTGACGCGAAGTGACTGGTTTTTCGCGGACCTGTTCGACCTCGACGCCTGACTCGGTCCGAAGGTGACCCACTAACGGCTACCCCTCCTGTGGTGTCACGCCCGGTCGTGGGTGACGTGGATACTGGCGCAGCACGACGTGCCCCTCGCGACGGCCTCAGACGACGTGTGACGCCGACGGAAACTGAAGGGGTGCTCGAAGGTCGAGTGGCTCCTCCT

Can anyone tell me how can I do this. Thanks in advance.

fasta • 3.5k views
ADD COMMENT
1
Entering edit mode

you can try (for flattened fasta):

$ paste  <(grep ">" test.fa) <(grep -v ">" test.fa|rev) | awk -v OFS="\n" '{print $1,$2}'

or use revseq -nocomplement from EMBOSS.

ADD REPLY
0
Entering edit mode

fasta - reverse complement sequence previously answed. Please have a look.

ADD REPLY
0
Entering edit mode

I don't want reverse complementary sequence, I just want to only reverse the sequence.

ADD REPLY
1
Entering edit mode

If you only want to reverse then change @Pierre's solution to:

cat input.fa | while read L; do  echo $L; read L; echo "$L" | rev ; done
ADD REPLY
0
Entering edit mode

harry : Don't forget to follow up on your past threads.

If an answer/comment was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one if they work.
Upvote|Bookmark|Accept

ADD REPLY
0
Entering edit mode

Can anyone help me if I have the fasta file in tab separated format which I got from bedtools get fasta. Then is there a way to get the reverse sequence of that fasta sequence.

Thanks in advance

ADD REPLY
0
Entering edit mode

bedtools getfasta returns a normal fasta, not tab. Please be more precise what the problem is.

ADD REPLY
0
Entering edit mode

bedtools getfasta option see below, so as i used -tab option then how i reverse the sequence of the output fasta sequence.

-fi     Input FASTA file
        -fo     Output file (opt., default is STDOUT
        -bed    BED/GFF/VCF file of ranges to extract from -fi
        -name   Use the name field for the FASTA header
        -name+  Use the name field and coordinates for the FASTA header
        -split  given BED12 fmt., extract and concatenate the sequences
                from the BED "blocks" (e.g., exons)
        -tab    Write output in TAB delimited format.
                - Default is FASTA format.

        -s      Force strandedness. If the feature occupies the antisense,
                strand, the sequence will be reverse complemented.
                - By default, strand information is ignored.

        -fullHeader     Use full fasta header.
                - By default, only the word before the first space or tab
                is used.

Thanks in advance for helping me to sort this issue.

ADD REPLY
0
Entering edit mode

Don't use tab ¯_(ツ)_/¯

If you need the reversed fasta (output of the bioawk command) as tab-separated file then you can do:

(...) | bioawk-command | tr "\n" "\t"

That will replace the newline character \n by tab so you should have the name of the sequence in column1 and the sequence itself in column2.

So 1) get fasta with bedtools, 2) reverse it with bioawk, 3) get tabdelimited file with tr.

Does that make sense in your case?

ADD REPLY
0
Entering edit mode

Hi, I tried it but again I didn't get the reverse sequence. I don't know why is it happen. this command is done fine with pipe command or not. Thanks in advance

ADD REPLY
0
Entering edit mode

I cannot see your screen or your data, cannot comment unfortunately.

ADD REPLY
2
Entering edit mode
3.7 years ago
ATpoint 85k

awk '$1 ~ /^>/ {print $0;next} {print $0 | "rev"}' test.fa

Edit: Forget about cumbersome awk, and just use bioawk (bioawk Github):

cat test.fa 
>foo
AATTGGC
GGAT
TGATCGATCGATCGAC
>bar
GGT
TTTTTT
>gee
TATCGACTGACTTTTTTTTTTT

bioawk -c fastx '{print ">"$name;print reverse($seq)}' test.fa 
>foo
CAGCTAGCTAGCTAGTTAGGCGGTTAA
>bar
TTTTTTTGG
>gee
TTTTTTTTTTTCAGTCAGCTAT
ADD COMMENT
0
Entering edit mode

This will not handle multi-line fasta (which is pretty common) correctly since each line is reversed individually

ADD REPLY
0
Entering edit mode

Correct! Edited it.

ADD REPLY
0
Entering edit mode
3.7 years ago
predeus ★ 2.1k

If you sequence is unfolded (two lines per sequence), you can do

perl -ne 'if (/^>/) {print} else {chomp; $rev = reverse($_); print "$rev\n"}' file.fa > rev.fa

If it's folded, you can unfold it first:

seqtk seq -l 0 file.fa | perl -ne 'if (/^>/) {print} else {chomp; $rev = reverse($_); print "$rev\n"}' > rev.fa

(If you don't have seqtk, you can get it via conda, or just download the binary from GitHub)

ADD COMMENT
0
Entering edit mode

Better to use seqtk seq -r file.fa for revcomp.

ADD REPLY
0
Entering edit mode

The original poster wanted reverse, not revcomp.

ADD REPLY
0
Entering edit mode

You are right. I misread the OP.

ADD REPLY

Login before adding your answer.

Traffic: 1927 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6