在fasta.gz上的SeqIO.parse [英] SeqIO.parse on a fasta.gz

查看:171
本文介绍了在fasta.gz上的SeqIO.parse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编码新手. Pytho/biopython的新手;这是我有史以来第一个在线问题. 如何打开压缩的fasta.gz文件以提取信息并在函数中执行计算.这是我正在尝试做的简化示例(我尝试了不同的方式)以及错误是什么.我正在使用的gzip命令似乎不起作用.

New to coding. New to Pytho/biopython; this is my first question online, ever. How do I open a compressed fasta.gz file to extract info and perform calcuations in my function. Here is a simplified example of what I'm trying to do (I've tried different ways), and what the error is. The gzip command I'm using doesn't seem to work.?

with gzip.open("practicezip.fasta.gz", "r") as handle:
    for record in SeqIO.parse(handle, "fasta"):
        print(record.id)

Traceback (most recent call last):

  File "<ipython-input-192-a94ad3309a16>", line 2, in <module>
    for record in SeqIO.parse(handle, "fasta"):

  File "C:\Users\Anaconda3\lib\site-packages\Bio\SeqIO\__init__.py", line 600, in parse
    for r in i:

  File "C:\Users\Anaconda3\lib\site-packages\Bio\SeqIO\FastaIO.py", line 122, in FastaIterator
    for title, sequence in SimpleFastaParser(handle):

  File "C:\Users\Anaconda3\lib\site-packages\Bio\SeqIO\FastaIO.py", line 46, in SimpleFastaParser
    if line[0] == ">":

IndexError: index out of range

推荐答案

您使用的是python3吗?

Are you using python3?

这个("r"->"rt")可以解决您的问题.

This ("r" --> "rt") could solve your problem.

import gzip
from Bio import SeqIO

with gzip.open("practicezip.fasta.gz", "rt") as handle:
    for record in SeqIO.parse(handle, "fasta"):
        print(record.id)

这篇关于在fasta.gz上的SeqIO.parse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆