Python脚本截断目录名称

时间:2013-05-22 13:22:58

标签: python linux csv directory

假设有一个脚本:

import csv
import re

#this script is designed to take a list of probe files and
#generate a corresponding swarm file for blasting them against
#some user defined database.

def __main__():
    #args
    infile  = sys.argv[1] #list of sequences to run
    outfile = sys.argv[2] #location of resulting swarm file
    outdir  = sys.argv[3] #location to store results from blast run
    db      = sys.argv[4] #database to query against

    with open(infile) as fi:
        data = [x[0].strip('\n') for x in list(csv.reader(fi))]

    cmd = open(outfile, 'w')
    blast = 'module load blast/2.2.26; blastall -v 5 -b 5 -a 4 -p blastn '
    db = ' -d ' + db


    def f(x):
         input = ' -i ' + str(x)
         out = re.search('(?<=./)([^\/]*)(?=\.)', x).group(0)
         out = ' -o ' + outdir + out + '.out'
         cmd.write(blast + db + input + out + '\n')

    map(f, data)

__main__()

如果我用:

运行它
python blast-probes.py /data/cornishjp/array-annotations/agilent_4x44k_human/probe-seq-fasta-list.csv ./human.cmd ./ x

human.cmd的一个例子是:

module load blast/2.2.26; blastall -v 5 -b 5 -a 4 -p blastn  -d x -i /data/corni
shjp/array-annotations/agilent_4x44k_human/probe-seqs/A_33_P3344603.fas -o ./A_3
3_P3344603.out

如果我用:

运行它
python blast-probes.py /data/cornishjp/array-annotations/agilent_4x44k_mouse/probe-seq-fasta-list.csv ./mouse.cmd ./ x

mouse.cmd的一个例子是:

module load blast/2.2.26; blastall -v 5 -b 5 -a 4 -p blastn  -d x -i /data/cornishp/array-annotations/agilent_4x44k_mouse/probe-seqs/A_51_P100327.fas -o ./A_51_P100327.out

不同之处在于agilent_4x44k_的结尾为human时,目录将使用cornishjp正确写入文件。当结尾为mouse时,该目录被错误地写为cornishp,而j被省略。我已经交换了所有东西(将人类当作mouse.cmd保存,等等),我不能为我的生活弄明白。

我唯一想到的是,当我为python脚本生成参数时,我使用tab来自动完成(linux)。这可能是问题吗?它正确读取输入文件,因为脚本会失败。

0 个答案:

没有答案