代码拉取完成,页面将自动刷新
from string import Template
import argparse
import subprocess
import os
from twisted.web.server import Site
from twisted.web.static import File
from twisted.internet import reactor, endpoints
parser = argparse.ArgumentParser(description='manual to this script')
parser.add_argument("--path", type=str, required=True, nargs='+', help='文件路径')
parser.add_argument("--name", type=str, required=True, nargs='+', help='文件名')
args = parser.parse_args()
script_path = os.path.abspath(os.path.dirname(__file__))
all_supl_type = {'bam': 'alignment','vcf':'variant'}
if len(args.name) != len(args.path):
print('输入长度不匹配')
exit()
filetype = [path.split('.')[-1] for path in args.path]
if not set(filetype).issubset(set(all_supl_type.keys())):
print('文件类型需要为' + ' '.join(list(all_supl_type.keys())))
exit()
def link_path(raw_path,name):
last_fname = raw_path.split('/')[-1]
subprocess.run(['mkdir',script_path+'/link_file/'+name])
subprocess.run(['ln','-s',os.path.abspath(raw_path), script_path+'/link_file/'+name+'/'+last_fname ])
return '/link_file/'+name+'/'+last_fname
list_tracks = []
info = dict(zip(args.path, zip(args.name, filetype)))
for k, v in info.items():
if v[1] == 'bam':
tmp_dict = {
'type': all_supl_type[v[1]],
'format': v[1],
'name': v[0],
'url': link_path(k,v[0]),
'indexURL': link_path(k + ".bai",v[0])
}
else:
tmp_dict = {
'type': all_supl_type[v[1]],
'format': v[1],
'name': v[0],
'url': link_path(k,v[0])
}
list_tracks.append(tmp_dict)
print(list_tracks)
# "link_file/CBP90012_DNA_bqsr_chr20_57429609_57429629.bam"
with open(script_path+'/igvwebConfig_tpl.js', 'r') as f:
tpl_js = Template(f.read())
out_js=tpl_js.substitute(track_config=list_tracks)
with open(script_path+'/igvwebConfig.js', 'w') as f:
f.write(out_js)
resource = File(script_path)
factory = Site(resource)
endpoint = endpoints.TCP4ServerEndpoint(reactor, 9999)
endpoint.listen(factory)
reactor.run()
#demo来自
#https://docs.twisted.org/en/stable/web/howto/web-in-60/static-content.html
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。