Score:0

How to cut intervals of lines of a file and put them into multiple files?

af flag

I have a fasta file containing ids and sequences like this:

>4S3O_2:C
GSMSQAVQTNGTQPLSKTWELSLYELQRTPQEAITDGLEIVVSPRSLHSELMCPICLDMLKNTMTTKECLHRFCADCIITALRSGNKECPTCRKKLVSKRSLRPDPNFDALISKIYPS
>5JH8_1:A
AAMVLAYYSGYAGNYAALTRYAASFNAVAVDFYNITAQGAVTGNGDPAPNDAISFLLGRKIPAYGCVSNVDGNGNWSADIAHAVSTSAQSQAVANLVKFAQDKRFSGINVDFEAVAQGDRNNFSHFI

I want to recursively cut the lines containing the ids and the sequences and put them into new multiple files named after the corresponding ids (chains excluded) so like the newfile cointains

>4S3O_2:C
GSMSQAVQTNGTQPLSKTWELSLYELQRTPQEAITDGLEIVVSPRSLHSELMCPICLDMLKNTMTTKECLHRFCADCIITALRSGNKECPTCRKKLVSKRSLRPDPNFDALISKIYPS

and It's named 4S30_2.fasta

This is what I tried:

awk -F ">" | sed -i -e '$0,$1{w file.fasta d}' BlindSet150.fasta 
Score:2
hr flag

There's probably a robust bioinformatics tool for extracting fasta sequences to individual files, but if you want to roll your own with awk I'd suggest something like

awk -F '[>:]' '/^>/ {close(f); f = $2 ".fasta" } f {print > f}' BlindSet150.fasta
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.