[英]Snakemake : SFTP on local machine
我從本地機器與遠程服務器上的 ssh 連接。
我在遠程服務器上運行我的 Snakemake。
我想將本地計算機上的文件用作規則的輸入。
當然,因為我在服務器上運行我的 Snakemake,服務器成為本地機器,本地機器成為遠程機器(對於 Snakemake)。
from snakemake.remote.SFTP import RemoteProvider
# I am not sure about the private key, is it the one I have on the server ?
# I have the same result with or without private_key anyway
# SFTP = RemoteProvider(port=22, username="myusername", private_key="/path/to/.ssh/id_rsa")
SFTP = RemoteProvider(port=22, username="myusername")
configfile : "config.json"
localrules: copyBclLocalToCluster
rule all:
input:
"copycluster.txt"
rule copyBclLocalToCluster:
input:
SFTP.remote("adress:path/to/filelocal.txt")
output:
"copycluster.txt"
shell:
"scp {input} {output}"
-----------------------------------------
Building DAG of jobs...
MissingInputException in line 26 of /path/to/Snakefile:
Missing input files for rule copyBclLocalToCluster:
adress:path/to/filelocal.txt
https://snakemake.readthedocs.io/en/stable/snakefiles/remote_files.html
使用的遠程文件地址必須與主機(域或 IP 地址)和遠程服務器上文件的絕對路徑一起指定。 如果服務器上的 SSH 守護進程在 RemoteProvider 或每個 remote() 實例中偵聽 22 以外的端口,則可以指定端口:
文檔說端口不應該是端口 22,但為什么呢? 我真的很想使用它,因為我不知道如何配置另一個端口,而且我什至不確定是否有權這樣做。
真的是端口問題嗎? 或者我只是不明白如何將 SFTP 與 Snakemake 一起使用。
在我的本地機器上使用文件作為我的 snakemake 輸入的最佳方法是什么?
這不是端口的問題,我什至不需要指定它,因為它是端口 22。
我試圖指定好的 ssh 私鑰:
SFTP = RemoteProvider(port=22, username="myusername", private_key="/path/to/.ssh/id_rsa")
-----------------------------
Building DAG of jobs...
MissingInputException in line 26 of /path/to/Snakefile:
Missing input files for rule copyBclLocalToCluster:
adress:path/to/filelocal.txt
如果我嘗試sftp myusername@adress:path/to/filelocal.txt .
在我服務器上的控制台上它工作正常。
為什么它在 snakemake 中不起作用?
當我嘗試在remoteProvider
使用我的密碼而不是 ssh-key 時,我remoteProvider
了同樣的錯誤。
SFTP = RemoteProvider(port=22, username="myusername", password="mypassword")
--------------------------------
Building DAG of jobs...
MissingInputException in line 26 of /path/to/Snakefile:
Missing input files for rule copyBclLocalToCluster:
adress:path/to/filelocal.txt
我確定地址、用戶名、密碼、ssh-key 是正確的並且文件存在,我可以在snakemake 之外進行它工作正常。
由於RemoteProvider
用途pysftp
,我試圖相同的文件復制與pysftp
在python
腳本。
import pysftp
with pysftp.Connection(adress,
username="myusername",
private_key_pass="/path/to/.ssh/id_rsa") as sftp:
sftp.get(path/to/filelocal.txt, /path/on/cluster/fileCOPY.txt)
它工作正常,所以問題肯定來自我的 Snakefile。
RemoteProvider
也需要ftputil
,我在 python 腳本中嘗試了 ftputil 。
import ftputil
with ftputil.FTPHost("adress", "myusername", "mypassword") as ftp_host:
print(getcwd())
ftp_host.download(remote_path, local_path)
----------------------------------------------
Traceback (most recent call last):
File "/work/username/miniconda3/envs/RNAseq_snakemake/lib/python3.6/site-packages/ftputil/host.py", line 129, in _make_session
return factory(*args, **kwargs)
File "/work/username/miniconda3/envs/RNAseq_snakemake/lib/python3.6/ftplib.py", line 117, in __init__
self.connect(host)
File "/work/username/miniconda3/envs/RNAseq_snakemake/lib/python3.6/ftplib.py", line 152, in connect
source_address=self.source_address)
File "/work/username/miniconda3/envs/RNAseq_snakemake/lib/python3.6/socket.py", line 724, in create_connection
raise err
File "/work/username/miniconda3/envs/RNAseq_snakemake/lib/python3.6/socket.py", line 713, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "sftptest.py", line 16, in <module>
with ftputil.FTPHost("adress", "myusername", "mypassword") as ftp_host:
File "/work/username/miniconda3/envs/RNAseq_snakemake/lib/python3.6/site-packages/ftputil/host.py", line 69, in __init__
self._session = self._make_session()
File "/work/username/miniconda3/envs/RNAseq_snakemake/lib/python3.6/site-packages/ftputil/host.py", line 129, in _make_session
return factory(*args, **kwargs)
File "/work/username/miniconda3/envs/RNAseq_snakemake/lib/python3.6/site-packages/ftputil/error.py", line 146, in __exit__
raise FTPOSError(*exc_value.args, original_exception=exc_value)
ftputil.error.FTPOSError: [Errno 111] Connection refused
Debugging info: ftputil 3.2, Python 3.6.7 (linux)
會不會有問題? 但是我在snakemake中沒有這種錯誤,只是缺少文件錯誤。 我不明白為什么 ftputil 不起作用。
所以我在 Snakemake 的源代碼中做了一個快速而骯臟的搜索,Snakemake 使用了需要用戶名和密碼的ftputil
。 當您不提供 Snakemake 的 ssh-key 路徑時,此密碼將默認為None
,然后傳遞給ftputil
。
參見Snakemake 源。
我同意默認行為應該默認為更合理的東西,比如~/.ssh/id_rsa
,但不幸的是它沒有。
當您在控制台上使用 SFTP 時,您必須編寫
sftp myusername@adress:/path/to/file .
但是在Snakemake的遠程功能中,您應該刪除主機和文件路徑之間的“:”。
我被 SFTP 語法誤導了,但它在 snakemake 文檔中寫得很好
# example from snakemake doc
SFTP.remote("example.com/path/to/file.bam")
# what I was doing badly
SFTP.remote("adress:path/to/filelocal.txt")
正確的命令是:
from snakemake.remote.SFTP import RemoteProvider
SFTP = RemoteProvider(port=22, username="myusername", password="mypassword")
rule all:
input:
# "/" instead of ":" between host and the path of the file
SFTP.remote("adress/path/to/filelocal.txt")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.