【问题标题】:#WatsonStudio and #Biopython and #fasta file saved on #S3 #Objectstorage#WatsonStudio 和 #Biopython 和 #fasta 文件保存在 #S3 #Objectstorage
【发布时间】:2018-10-03 15:14:27
【问题描述】:

我需要使用 Biopython 读取上传到云对象存储上的 fasta 文件。 我在 Watson Studio 中有一个 Python 2.7 笔记本。 有人试过吗?

【问题讨论】:

  • 通常你想在发布问题之前探索一些选项,看看它们为什么会失败。希望下面的回答有帮助!!!

标签: amazon-s3 biopython fasta object-storage data-science-experience


【解决方案1】:

从 biopython 下载示例数据集:- http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc49

将文件拖放到 Cloud Object Storage。

单击该文件旁边的向下箭头,然后单击 InsertStreamingBody 对象

这将插入一个 streamingBody 对象(例如 streaming_body_1),请运行该单元格。

接下来在字节对象中读取它

fastareadbytes = streaming_body_1.read()

现在我们需要将字节解码为字符串,然后将其转换为 StringIO,以便我们可以在 SeqIO.parse() 中使用它来读取它

from io import StringIO
from Bio import SeqIO
for seq_record in SeqIO.parse(StringIO(fastareadbytes.decode('utf-8')), "fasta"):
    print(seq_record.id)
    print(repr(seq_record.seq))
    print(len(seq_record))

您将看到如下响应:-

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    相关资源
    最近更新 更多