Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

- - - - -

Python function to read multiple FASTA files and merging them into one dictionar

Python

  • Please log in to reply
No replies to this topic

#1 mordiano

mordiano

    member

  • Active Members
  • Pip
  • 22 posts
0
Neutral

Posted 17 November 2012 - 03:44 AM

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???

cheers!







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[ID] = SEQ
++++ID = line
++++SEQ = ""
+++else:
++++if line != "": #neccesary? ..does adding a "" string affect anything?
+++++SEQ += line
+return FASTA_dict

#main


FASTA_dict = {}

files=sys.argv[1:]
FASTAs_to_dict(files)
files.close


FASTA_dict = FASTAs_to_dict(files)

print FASTA_dict




Home - About - Terms of Service - Privacy - Contact Us

©1999-2012 Protocol Online, All rights reserved.