我正在Windows 7上编程,在我的一个Python项目中,我需要调用床头工具,它只在Windows上使用Cygwin。我是Cygwin的新手,安装了默认版本+床工具所需的一切,然后使用Cygwin通过使用安装说明中描述的make安装床头工具。
$ tar -zxvf BEDTools.tar.gz
$ cd BEDTools-<version>
$ make当我使用Cygwin终端像下面这样手动调用它时,它没有问题,输出文件包含正确的结果。
bedtools_exe_path intersect -a gene_bed_file -b snp_bed_file -wa -wb > output_file但是当我在我的程序中使用subprocess.call时,它似乎使用了Windows,而不是Cygwin,后者不起作用。
arguments = [bedtools_exe_path, 'intersect', '-a', gene_bed_file, '-b',
snp_bed_file, '-wa', '-wb', '>', output_file]
return_code = suprocess.call(arguments)结果没有输出文件和3221225781的返回代码。
arguments = [bedtools_exe_path, 'intersect', '-a', gene_bed_file, '-b',
snp_bed_file, '-wa', '-wb', '>', output_file]
return_code = suprocess.call(arguments, shell=True)结果是一个空的输出文件和一个3221225781的返回代码。
cygwin_bash_path = 'D:/Cygwin/bin/bash.exe'
arguments = [cygwin_bash_path, bedtools_exe_path, 'intersect', '-a', gene_bed_file, '-b',
snp_bed_file, '-wa', '-wb', '>', output_file]
return_code = suprocess.call(arguments)结果没有输出文件,返回代码为126和
D:/BEDTools/bin/bedtools.exe: D:/BEDTools/bin/bedtools.exe: cannot execute binary filearguments = [cygwin_bash_path, bedtools_exe_path, 'intersect', '-a', gene_bed_file, '-b',
snp_bed_file, '-wa', '-wb', '>', output_file]
return_code = suprocess.call(arguments, shell=True)结果是一个空的输出文件,返回代码为126和
D:/BEDTools/bin/bedtools.exe: D:/BEDTools/bin/bedtools.exe: cannot execute binary file我有什么办法让它起作用吗?
发布于 2015-07-05 12:02:18
下面的工作没有问题。不需要转义"。
argument = 'sh -c \"' + bedtools_exe_path + ' intersect -a ' + gene_bed_file +
' -b ' + snp_bed_file + ' -wa -wb\"'
with open(output_file, 'w') as file:
subprocess.call(argument, stdout=file)还使用了以下工作:
argument = 'bash -c \"' + bedtools_exe_path + ' intersect -a ' + gene_bed_file +
' -b ' + snp_bed_file + ' -wa -wb\"'
with open(output_file, 'w') as file:
subprocess.call(argument, stdout=file)通过以下方式:
bedtools_exe_path = 'D:/BEDTools/bin/bedtools.exe'
gene_bed_file = 'output/gene.csv'
snp_bed_file = 'output/snps.csv'
output_file = 'output/intersect_gene_snp.bed'使用到cygwin bash.exe (D:/Cygwin/bin/bash.exe)的路径而不是使用bash或sh是行不通的。
谢谢你,艾尔克孙,帕德拉克·坎宁安和J.F.塞巴斯蒂安。
发布于 2015-07-04 19:40:54
假设您想要从Windows运行Linux命令。您可以将Linux安装到VM中,并通过ssh (Windows上的Putty/plink)运行命令:
#!/usr/bin/env python
import subprocess
cmd = [r'C:\path\to\plink.exe', '-ssh', 'user@vm_host', '/path/to/bedtools']
with open('output', 'wb', 0) as file:
subprocess.check_call(cmd, stdout=file)Cygwin提供了允许直接运行命令的run命令:
cmd = [r'C:\cygwin\path\to\run.exe', '-p', '/path/to/', 'bedtools',
'-wait', 'arg1', 'arg2']注意:在这两种情况下,Python脚本都是从Windows运行的。bedtools是Linux或Cygwin (非Windows)命令,因此您应该提供POSIX路径。
https://stackoverflow.com/questions/31221279
复制相似问题