Jump to content

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

Submit your paper to J Biol Methods today!
Photo
- - - - -

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

Python

  • Please log in to reply
1 reply 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

#2 mboss

mboss

    member

  • Active Members
  • Pip
  • 6 posts
2
Neutral

Posted 24 June 2013 - 03:19 PM

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




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

©1999-2013 Protocol Online, All rights reserved.