【问题标题】:Biopython - String assigning error [closed]Biopython - 字符串分配错误[关闭]
【发布时间】:2014-05-23 12:06:06
【问题描述】:

我尝试从 Biopython 开始。这样我就可以在里面做我的论文了。但这真的让我三思而后行。缺少显示功能,当我尝试整数值时,它不起作用,字符串也是如此。请帮忙。谢谢。

链接:

http://imgur.com/87Gw9E5

【问题讨论】:

  • “它不起作用”是一个非常模糊的错误描述。
  • 您的while 条件是检查 0 是否大于某物的长度。您实际上并没有显示 features 的定义位置,但除非它是一些可怕的组合对象,以某种方式返回负长度,否则您的循环将永远不会运行。

标签: python biopython


【解决方案1】:

Biopython 对我来说似乎很健壮,错误可能是由于您对它的缺乏经验。

您有几个错误,其中之一是您忘记以“”结束字符串。以下几行

print "location start, features[ftNum].location.start # note location.start"
print "feature qualifiers,features[ftNum].qualifiers"

应该改正为

print "location start", features[ftNum].location.start # note location.start
print "feature qualifiers", features[ftNum].qualifiers

此外,正如 Wooble 指出的那样,您的 while 循环中的条件是错误的。我猜你的意思是反转“>”,也就是说,特征的数量应该大于零。

请添加一些示例数据和错误消息。

【讨论】:

    【解决方案2】:

    Biopython 的人实际上让处理这些功能变得很容易。您的问题是字符串管理(普通 python)。我用过format,但你可以使用% 运算符。

    同样在 python 中,你很少需要在循环时保持计数。 Python 不是 C。

    from Bio import SeqIO
    
    for record in SeqIO.parse("NG_009616.gb", "genbank"):
    
        # You don't have to take care of the number of features with a while
        # Loop all of them.
        for feature in record.features:
            print "Attributes of feature"
            print "Type {0}".format(feature.type)
            print "Start {0}".format(feature.location.start)
            print "End {0}".format(feature.location.end)
            print "Qualifiers {0}".format(feature.qualifiers)
            # This is the right way to extract the sequence:
            print "Sequence {0}".format(feature.location.extract(record).seq)
            print "Sub-features {0}".format(feature.sub_features)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多