[code] 追蹤 pbrun 程式碼
===
###### tags: `Parabricks-v3.5`
###### tags: `基因體`, `NVIDIA`, `Clara`, `Parabricks`, `二級分析`, `Azure`
<br>
[TOC]
<br>
> 因 debug 關係,有 print 一些資訊,code stack 行數僅供參考
<br>
## 組裝 docker run 的地方
> [pbmaster.py / RunDNABricks(runArgs, IOMapping)](http://10.78.26.44:30000/Tj_Tsai/parabricks/-/blob/master/v3.5.0/pbrun/pbmaster.py#L160)
```python=180
cmdLine = ["docker", "run"]
if runArgs.command not in pbargs.cpuTools:
if nvDocker:
cmdLine = ["nvidia-docker", "run"]
elif runtimeDocker == True:
cmdLine.append("--runtime=nvidia")
elif gpusDocker == True:
if runArgs.command == "licenseinfo":
print("This feature is only available for GPU-based licenses using nvidia-docker or docker with nvidia runtime.")
pbutils.pbExit(1)
if runArgs.runArgs.gpu_devices == "all":
cmdLine.extend(["--gpus", "all"])
else:
validateGpuDevices(runArgs.runArgs.gpu_devices)
cmdLine.extend(["--gpus", "\"device=" + runArgs.runArgs.gpu_devices + "\""])
if runArgs.runArgs.no_seccomp_override == False:
cmdLine.extend(["--security-opt", "seccomp=unconfined"])
cmdLine.extend(["-u=" + str(getpwnam(getuser()).pw_uid) + ":" + str(getpwnam(getuser()).pw_gid)])
cmdLine.extend(["--rm", "-w=" + os.path.abspath(os.getcwd())])
cmdLine.extend(["--net=host"])
if "NVIDIA_VISIBLE_DEVICES" in os.environ:
cmdLine.extend(["-e", "NVIDIA_VISIBLE_DEVICES=" + os.environ["NVIDIA_VISIBLE_DEVICES"]])
elif "NV_GPU" in os.environ:
cmdLine.extend(["-e", "NVIDIA_VISIBLE_DEVICES=" + os.environ["NV_GPU"]])
```
```=
Traceback (most recent call last):
File "/usr/bin/pbrun", line 17, in <module>
pbmaster.pb_main(runArgs)
File "/opt/parabricks/pbmaster.py", line 240, in pb_main
RunDNABricks(runArgs, IOMapping)
File "/opt/parabricks/pbmaster.py", line 227, in RunDNABricks
```
> [TJ][pbmaster] RunDNABricks: cmdLine: ['docker', 'run', '--gpus', 'all', '-u=1000:1000', '--rm', '-w=/uploads/workspace', '--net=host', '-v', '/opt/parabricks:/INSTALL/', '-v', '/uploads/workspace/H5MGX7XZ:/uploads/workspace/H5MGX7XZ', '-v', '/uploads/workspace:/uploads/workspace', '-v', '/uploads/workspace/parabricks_sample/Ref:/uploads/workspace/parabricks_sample/Ref', '-v', '/uploads/workspace/parabricks_sample/Data:/uploads/workspace/parabricks_sample/Data', 'parabricks/release:v3.5.0']
> [TJ][pbmaster] RunDNABricks: runArgs: <pbargs.PBRun object at 0x7f61ebf287c0>
<br>
## 執行 docker run 的呼叫堆疊
> 執行環境:container 內部
> 預備工具:將外部 pbrun 掛載到 /INSTALL
> 執行指令:同一般 pbrun 指令
> 觀察事項:看看 pbrun 指令是如何轉呼叫 docker
```
Traceback (most recent call last):
File "/INSTALL/pbrun", line 17, in <module>
pbmaster.pb_main(runArgs)
File "/INSTALL/pbmaster.py", line 240, in pb_main
RunDNABricks(runArgs, IOMapping)
File "/INSTALL/pbmaster.py", line 228, in RunDNABricks
pb_compose.composeRun(cmdLine, runArgs)
File "/INSTALL/pb_compose.py", line 1382, in composeRun
PBTool(runArgs.command, list(defaultCmdLine), finalArgs, os.environ.copy(), tmp_dir=runArgs.runArgs.tmp_dir, parentCmd=None, verbosity=runArgs.runArgs.x3).dispatch()
File "/INSTALL/pb_compose.py", line 144, in dispatch
subprocess.check_call(fullCmdLine, env=self.environ)
File "/usr/lib/python3.7/subprocess.py", line 358, in check_call
retcode = call(*popenargs, **kwargs)
File "/usr/lib/python3.7/subprocess.py", line 339, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.7/subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.7/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'docker': 'docker'
```
<br>
## 獨立工具或 pipeline 的 docker-run 指令轉送
> [pbrun/pb_compose.py / composeRun()](http://10.78.26.44:30000/Tj_Tsai/parabricks/-/blob/master/v3.5.0/pbrun/pb_compose.py#L1359)
```python=1359
def composeRun(defaultCmdLine, runArgs):
if runArgs.command in standaloneTools: #<-- 獨立工具
finalArgs = sys.argv[2:]
if not "--tmp-dir" in finalArgs:
finalArgs.extend(["--tmp-dir", runArgs.runArgs.tmp_dir])
else:
finalArgs[finalArgs.index("--tmp-dir") + 1] = runArgs.runArgs.tmp_dir
PBTool(runArgs.command, list(defaultCmdLine), finalArgs, os.environ.copy(), tmp_dir=runArgs.runArgs.tmp_dir, parentCmd=None, verbosity=runArgs.runArgs.x3).dispatch()
else: #<--- pipeline
newPipeline = globals()[runArgs.command](defaultCmdLine, runArgs)
for cmd in newPipeline.runCmds:
cmd.dispatch()
```
```
Traceback (most recent call last):
File "/usr/bin/pbrun", line 17, in <module>
pbmaster.pb_main(runArgs)
File "/opt/parabricks/pbmaster.py", line 240, in pb_main
RunDNABricks(runArgs, IOMapping)
File "/opt/parabricks/pbmaster.py", line 228, in RunDNABricks
pb_compose.composeRun(cmdLine, runArgs)
File "/opt/parabricks/pb_compose.py", line 1384, in composeRun
newPipeline = globals()[runArgs.command](defaultCmdLine, runArgs)
File "/opt/parabricks/pb_compose.py", line 180, in __init__
```
<br>
## docker-run 轉送 OS 的地方
> [pb_compose.py: PBTool](http://10.78.26.44:30000/Tj_Tsai/parabricks/-/blob/master/v3.5.0/pbrun/pb_compose.py#L126)
```python=126
def dispatch(self):
signal.signal(signal.SIGINT, self.signal_handler)
signal.signal(signal.SIGTERM, self.signal_handler)
try:
if self.parentcmd != None:
fullCmdLine = ["pbrun", self.basecmd] + self.cmdArgs
newRun = PBRun(fullCmdLine)
fullCmdLine, streamingPIDs = self.UpdateCmdLine(self.initCmds + [self.basecmd] + self.cmdArgs)
if self.verbosity == True:
print (" ".join(fullCmdLine))
sys.stdout.flush()
subprocess.check_call(fullCmdLine, env=self.environ)
if len(streamingPIDs) > 0:
print("Waiting to finish streaming")
for streamer in streamingPIDs:
streamer.communicate()
except (subprocess.CalledProcessError, KeyboardInterrupt) as e:
errorString = "\nCould not run %s" % self.basecmd
if self.parentcmd != None:
errorString += " as part of %s" % self.parentcmd
self.exitFunction(errorString)
self.clearFunction()
```
```
Traceback (most recent call last):
File "/usr/bin/pbrun", line 17, in <module>
pbmaster.pb_main(runArgs)
File "/opt/parabricks/pbmaster.py", line 240, in pb_main
RunDNABricks(runArgs, IOMapping)
File "/opt/parabricks/pbmaster.py", line 228, in RunDNABricks
pb_compose.composeRun(cmdLine, runArgs)
File "/opt/parabricks/pb_compose.py", line 1375, in composeRun
PBTool(runArgs.command, list(defaultCmdLine), finalArgs, os.environ.copy(), tmp_dir=runArgs.runArgs.tmp_dir, parentCmd=None, verbosity=runArgs.runArgs.x3).dispatch()
File "/opt/parabricks/pb_compose.py", line 128, in dispatch
```
> [TJ][pb_compose] PBTool: dispatch: self.parentcmd: None
> [TJ][pb_compose] PBTool: dispatch: self.basecmd: fq2bam
> [TJ][pb_compose] PBTool: dispatch: fullCmdLine: ['docker', 'run', '--gpus', 'all', '-u=1000:1000', '--rm', '-w=/uploads/workspace', '--net=host', '-v', '/opt/parabricks:/INSTALL/', '-v', '/uploads/workspace/6TDZET1C:/uploads/workspace/6TDZET1C', '-v', '/uploads/workspace:/uploads/workspace', '-v', '/uploads/workspace/parabricks_sample/Ref:/uploads/workspace/parabricks_sample/Ref', '-v', '/uploads/workspace/parabricks_sample/Data:/uploads/workspace/parabricks_sample/Data', 'parabricks/release:v3.5.0', 'fq2bam', '--ref', 'parabricks_sample/Ref/Homo_sapiens_assembly38.fasta', '--in-fq', 'parabricks_sample/Data/sample_1.fq.gz', 'parabricks_sample/Data/sample_2.fq.gz', '--out-bam', 'output.bam', '--tmp-dir', '/uploads/workspace/6TDZET1C']
[TJ][pb_compose] PBTool: dispatch: self.verbosity: None