【发布时间】:2014-02-13 01:23:29
【问题描述】:
我正在编写一个 python 脚本(2.7 版),它将指定目录中的每个输入文件(.nexus 格式)更改为 .fasta 格式。 Biopython 模块 SeqIO.convert 完美地处理了单独指定文件的转换,但是当我尝试使用 os.walk 在目录上自动执行该过程时,我无法正确地将每个输入文件的路径名传递给 SeqIO.convert。我哪里错了?我是否需要使用 os.path 模块中的 join() 并将完整路径名传递给 SeqIO.convert?
#Import modules
import sys
import re
import os
import fileinput
from Bio import SeqIO
#Specify directory of interest
PSGDirectory = "/Users/InputDirectory”
#Create a class that will run the SeqIO.convert function repeatedly
def process(filename):
count = SeqIO.convert("files", "nexus", "files.fa", "fasta", alphabet= IUPAC.ambiguous_dna)
#Make sure os.walk works correctly
for path, dirs, files in os.walk(PSGDirectory):
print path
print dirs
print files
#Now recursively do the count command on each file inside PSGDirectory
for files in os.walk(PSGDirectory):
print("Converted %i records" % count)
process(files)
当我运行脚本时,我收到以下错误消息:
Traceback (most recent call last):
File "nexus_to_fasta.psg", line 45, in <module>
print("Converted %i records" % count)
NameError: name 'count' is not defined
This conversation 很有帮助,但我不知道在哪里插入 join() 函数语句。 Here is an example of one of my nexus files
感谢您的帮助!
【问题讨论】: