【问题标题】:no such file or directory没有相应的文件和目录
【发布时间】:2020-09-22 16:07:44
【问题描述】:

当我尝试在 Biopython 中执行任何操作时,我不断收到此错误消息。我不确定如何更改 Biopython 的路径,因为 python 和 Biopython 在同一路径中。我不确定我还需要做什么。

    Python 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27) 
    [Clang 6.0 (clang-600.0.57)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from Bio import SeqIO
    >>> 
    >>> user_input = input("please input an Accession Number: ")
    please input an Accession Number: NC_005816.gb

    >>> file = SeqIO.read(user_input, "genbank")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-       packages/Bio/SeqIO/__init__.py", line 654, in read
        iterator = parse(handle, format, alphabet)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-  packages/Bio/SeqIO/__init__.py", line 607, in parse
        return iterator_generator(handle)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site- packages/Bio/SeqIO/InsdcIO.py", line 93, in __init__
        super().__init__(source, mode="t", fmt="GenBank")
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Bio/SeqIO/Interfaces.py", line 47, in __init__
        self.stream = open(source, "r" + mode)
    FileNotFoundError: [Errno 2] No such file or directory: 'NC_005816.gb'

【问题讨论】:

  • NC_005816.gb 不在您调用python 的目录中。尝试使用import os; os.chdir("path/to/NC_005816.gb") 更改当前工作目录
  • 为什么你认为这与BioPython有关?错误非常明显。当前工作目录中没有NC_005816.gb(这是你输入的)这样的文件
  • 您是否尝试在没有本地存储文件的情况下从加入中查找 genbank 文件?如果是,你需要Bio.Entrezbiopython.org/DIST/docs/tutorial/Tutorial.html#sec139

标签: python python-3.x bioinformatics biopython


【解决方案1】:

NC_005816.gb 不在您调用python 的目录中。 尝试做

import os
os.chdir("path/to/folder/of/NC_005816.gb")
...  # Your code here

更改当前工作目录。 但是,如果您需要针对用户输入进行动态更改,则可以询问文件的路径:

from pathlib import Path
from Bio import SeqIO
user_input = input("Enter the path to the accession number:")

if Path(user_input).expand_user().exists():
    file = SeqIO.read(user_input, "genbank")
else:
    print("Invalid input")

Python 的 pathlib 文档可以在 here 找到

【讨论】:

  • 那么我需要为每个用户输入的登录号更改我的目录吗?
  • @Chris 你可以向用户询问入藏号的路径
  • 感谢您的帮助。
  • 入藏号是 SeqIO 包的一部分。我不应该要求正确的路径吗?它是 Genbank 文件的标识符。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多