Created
February 16, 2018 16:44
-
-
Save mattravenhall/2acb93626a1d72c06735448ab10256cc to your computer and use it in GitHub Desktop.
Given a list of sequences and contig names, write out a fasta.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def writeFasta(titles=[], sequences=[], filename='tmp.fasta'): | |
if len(titles) != len(sequences): | |
titles = ['contig_{}'.format(i) for i in range(len(sequences))] | |
# Initial new file | |
with open(filename, 'w') as fasta: | |
fasta.write('') | |
with open(filename, 'a') as fasta: | |
for t, s in zip(titles,sequences): | |
fasta.write('> {}\n'.format(t)) | |
s_wNewlines = re.sub("(.{80})","\\1\n", s, 0, re.DOTALL) | |
fasta.write(s_wNewlines+'\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment