Exporting fasta from SQL
1
0
Entering edit mode
7.4 years ago
stacy734 ▴ 40

Hi everyone,

I have sequences stored in an SQL database, with the header stored in one field and the sequence (single line) in another.

header1 GACTACGACT...

header2 ATACGATCAT...

I've been exporting sequences as a csv and running another process to put them in proper fasta format. Can anyone suggest an SQL query that would pull them out in fasta format directly, also adding the ">" to the header? Some students are also using the data and they are still learning the basics of unix commands.

Any advice will be appreciated.

Stacy

fasta format sql • 3.0k views
ADD COMMENT
0
Entering edit mode

what is your SQL engine ?

ADD REPLY
0
Entering edit mode

Thank you very much!

ADD REPLY
0
Entering edit mode
7.4 years ago

say you're using sqlite3:

$ sqlite3 db.sqlite3
SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table fasta(name,sequence);
sqlite> insert into fasta(name,sequence) values ("abcd","ATGACAGATCGATCGATGTACGTAGCTGCTAGTGATATGCTAGCTGCTGATAGCTAGTAGCTAGC");
sqlite> insert into fasta(name,sequence) values ("efegh","ATGATCGTATGGGATCGAGTCTAAAAAAA");
sqlite> (ctrl-d)

export ('||' is the concatenation operator and x'0A' is the carriage return). Another sql engine would have a different syntax(mysql: 'concat') but the idea is the same.

$ sqlite3 db.sqlite3 "select ('>' || name || x'0A' || sequence) from fasta;"
>abcd
ATGACAGATCGATCGATGTACGTAGCTGCTAGTGATATGCTAGCTGCTGATAGCTAGTAGCTAGC
>efegh
ATGATCGTATGGGATCGAGTCTAAAAAAA
ADD COMMENT

Login before adding your answer.

Traffic: 1733 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