python判断linux中文件是否存在_linux中的Python子进程在文件存在时找不到文件

这个虫子快把我逼疯了。

脚本的错误输出:>>>Run shell cmd "grep -vw ^# *.blastn | awk $1 != $2 > *matchfile*"

grep: /projects/percid100_2/blastn.outfile: No such file or directory

2

我一定查过档案了。在

^{pr2}$

上一功能:def run_blastn(outdir, outfile):

"""Run blastn under given percent identity """

print ">>> Run blastn"

blastnlog = os.path.join(outdir, 'blastn_db_log')

# make database and run blastn

ref = Popen(['cmd1', '-logfile', blastnlog])

ref.communicate()

blastn = Popen(['cmd2', '-out', outfile], stderr=PIPE)

出现函数错误:def filter_query(infile, matchfile):

"""Filter out self to self hit and no hit"""

print ">>> Filter query self to self hit and no hit"

print('>>> Run shell cmd "grep -vw ^# *.blastn | awk $1 != $2 > *matchfile*"')

grep = Popen(['grep', '-vw', '^#', infile], stdout=PIPE)

awk = Popen(['awk', '$1 != $2'], stdin=grep.stdout, stdout=PIPE)

output = awk.communicate()[0]

grep.communicate()

if grep.returncode != 0:

print grep.returncode

sys.exit()

with open(matchfile, 'wb') as ofile:

print 'Write to file %s' % matchfile

ofile.write(output)

主要功能:def main():

parser = get_parser()

args = parser.parse_args()

if not os.path.exists(args.outdir):

os.makedirs(args.outdir)

outdir = os.path.abspath(args.outdir)

bloutfile = 'blastn.outfile'

path_bloutfile = os.path.join(outdir, bloutfile)

# filter query seq outfile name

matchfile = 'match_file'

path_matchfile = os.path.join(outdir, matchfile)

# run blastn

run_blastn(outdir, path_bloutfile)

# filter blastn output gain only matching information

filter_query(path_bloutfile, path_matchfile)

if __name__=='__main__':

main()

其中一个函数输入infile是由调用另一个程序的上一个函数use subprocess.Popen生成的。在

我对这个问题的猜测是上一个命令完成了,不知何故这个子进程调用没有识别上一个函数的输出文件。我不知道该怎么解决。在

如果我再尝试运行脚本几次,脚本最终将成功运行。在

然而,这是不好的。在

我试图使用os.path.abspath(),但没有解决这个问题的运气。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值