Created
January 22, 2016 16:54
-
-
Save ethanagb/6e40c58127b7ca8b9242 to your computer and use it in GitHub Desktop.
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
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