This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Fasta file from *.tab file

Hi All,

I want to extract functional sequences from the tab separated file and convert it into the fasta file. I use mac and i know its possible with the awk command but I don't know how to use that so any help/indicator would be appreciated.

The tab file that I have is look like-

No  Seq ID  Functionality  Sequence
1    Seq_1        Yes          atcggtcggctggt

The output I want is-

>seq1
atcggtcggctggt

Thanks for any help!

sequence

If the proposed solution is not working, post the actual lines from your data file, and format as code.

You could also do a simple python script. Something like (untested):

with open('myfile.txt') as f:
    for line in f:
        fields = line.split('\t')
        print ">{}\n{}".format(fields[5],fields[6])

1 answer

grep -v Functionality < file.tab |\
awk -F '\t' '{printf(">%s\n%s\n",$2,$7);}'

Hi Pierre,

Thanks for the fast reply. The command you gave worked well, however, it extracting the wrong sequence (I changed the $4 to $7 because I want seq from that column but didn't work, it extracts the seqs from different column. I tried other $column number but still not working.

In .tab file, a few entries in columns before $7 is empty, may be thats causing the problem in extracting the sequences from the column I want? Any suggestion how to solve this (I also tried to upload picture of the data file here but don't know how it works)

Thanks!

added -F '\t' to specify the tabulation as the delimiter.

Updated command works well with all other columns but unfortunately not with the $6 and $7, don't know whats wrong? Is there anything more that can be changed or modification in the file that can help?

Again, thanks.

Log in to answer this question.