Skip to content

Instantly share code, notes, and snippets.

@ethanagb
Created January 22, 2016 16:54
Show Gist options
  • Save ethanagb/6e40c58127b7ca8b9242 to your computer and use it in GitHub Desktop.
Save ethanagb/6e40c58127b7ca8b9242 to your computer and use it in GitHub Desktop.
from Bio import SeqIO
############
pwd = "/Users/Ethan/Desktop/testdir/" #set the present working dir
############
with open(str(pwd) + "namelist.txt") as filenamesFile:
filenames = filenamesFile.readlines()
nameList =[str(e.strip()) for e in filenames]
filenamesFile.close()
for name in nameList:
infile = open(str(pwd) + str(name) + ".fa", "rU")
chroms = []
for record in SeqIO.parse(infile, "fasta"):
x = record.id
chrom = x.split(":")[0] #Set the symbol + field # for text to sort file by
chroms.append(chrom)
with open(str(pwd) + str(name) + "_" + str(chrom) + ".fa","a+") as outfile: #this appends, should add a clean up step somehow first.
SeqIO.write(record, outfile, "fasta")
outfile.close
infile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment