在python中打印已处理文件的数量

时间:2017-01-15 19:44:06

标签: python biopython

我想打印一个关于由以下代码处理的文件数量的参数:

import sys
import re
import os
import fileinput
from Bio import SeqIO
from Bio.Alphabet import IUPAC
directory = os.getcwd()
def process(directory):
    filelist = os.listdir(directory)
    for f in filelist:
        if not f.endswith('.fastq'):
           continue
        SeqIO.convert(f, 'fastq', f[:-len('.fastq')]+'.fasta', 'fasta', alphabet=IUPAC.ambiguous_dna)

my_directory = os.getcwd()
process(my_directory)

1 个答案:

答案 0 :(得分:2)

您只想打印转换的文件数量?你的意思是这样吗?

import sys
import re
import os
import fileinput
from Bio import SeqIO
from Bio.Alphabet import IUPAC
directory = os.getcwd()

def process(directory):
    filelist = os.listdir(directory)
    files_processed = 0
    for f in filelist:
        if not f.endswith('.fastq'):
           continue
        SeqIO.convert(f, 'fastq', f[:-len('.fastq')]+'.fasta', 'fasta', alphabet=IUPAC.ambiguous_dna)
        files_processed += 1

    return files_processed

my_directory = os.getcwd()
files_processed = process(my_directory)
print(files_processed)