Friday, February 16, 2018

Brief Bioinformatics Bash

FASTA to single line FASTA

Write the wrapped sequences of a FASTA file to a single line; example:

Before:
>Seq1
ACGTACGTACGT
ACGTACGTACGT
ACGTACGTACGT
>Seq2
GCAGTGCAGTGCAGTGCAGT
GCAGTGCAGTGCAGTGCAGT

After:
>Seq1
ACGTACGTACGTACGTACGTACGTACGTACGTACGT
>Seq2
GCAGTGCAGTGCAGTGCAGTGCAGTGCAGTGCAGTGCAGT


multifasta2Singleline.sh
#/bin/bash
awk '/^>/ {printf("\n%s\n",$0);next; } { printf("%s",$0);}  END {printf("\n");}' < $1 | grep -v '^$'


 Don't forget to chmod +x multifasta2Singleline.sh

Usage:
 ./multifasta2Singleline.sh input.fasta > output.fasta

No comments:

Post a Comment