【发布时间】:2017-04-02 15:00:26
【问题描述】:
我不确定为什么下面的代码不起作用 - 我收到错误消息
NameError: name 'group1' is not defined.
在我尝试使用 getopt 之前,代码运行良好。我正在尝试解析命令行输入,例如,如果我放了
python -q file1 file2 -r file3 file4
file1 和 file2 作为 'group1' 成为我的第一个循环的输入。
import sys
import csv
import vcf
import getopt
#set up the args
try:
opts, args = getopt.getopt(sys.argv[1:], 'q:r:h', ['query', 'reference', 'help'])
except getopt.GetoptError as err:
print str(err)
sys.exit(2)
for opt, arg in opts:
if opt in ('-h', '--help'):
print "Usage python -q [query files] -r [reference files]"
print "-h this help message"
elif opt in ('-q', '--query'):
group1 = arg
elif opt in ('-r', '--reference'):
group2 = arg
else:
print"check your args"
#extract core snps from query file, saving these to the set universal_snps
snps = []
outfile = sys.argv[1]
for variants in group1:
vcf_reader = vcf.Reader(open(variants))
【问题讨论】:
标签: python bioinformatics vcf-variant-call-format