Protocol Online logo
Top : New Forum Archives (2009-): : Bioinformatics and Biostatistics

Python function to read multiple FASTA files and merging them into one dictionar - (Nov/17/2012 )

Hi guys, I'm just throwing this function up here to see if there are any Python aces out there,

Any ideas why this collapses???


import sys, pdb

def FASTAs_to_dict(files):
+"""Appends FASTA files given as arguments to a dictionary"""
+ID = ""
+SEQ = ""
+for seqfile in files: #goes through each sequence in Sequences
++sequences = open(seqfile, 'r')
++for line in sequences:
+++if line.startswith(">"): #> saves previous entry, set new ID, clears SEQ
++++if ID != "": #only makes entries for ID with values
+++++FASTA_dict = SEQ
++++ID = line
++++SEQ = ""
++++if line != "": #neccesary? ..does adding a "" string affect anything?
+++++SEQ += line
+return FASTA_dict


FASTA_dict = {}


FASTA_dict = FASTAs_to_dict(files)

print FASTA_dict


Are you programming in Python or do you just need to concatenate several fasta files?