列表和限制类型从Biopython [英] List and RestrictionType from Biopython

查看:200
本文介绍了列表和限制类型从Biopython的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Bio.Restrictions 方法的一些问题,我不知道是由于python,biopython还是我对python的了解不足。



当我尝试在 RestrictionBatch /cookbook/Restriction.html#mozTocId32850rel =nofollow> cookbook ,我想从字典中使用酶I(从文件中读取),它说:


您可以通过传递一个酶
或酶名作为参数来启动限制批次。


在python 文档 for dict.keys 说:


返回字典的副本键列表


所以我试过这个:

 code> rb = RestrictionBatch(Enzymes.keys())

但是我收到一个错误: ValueError:< type'list'>不是RestrictionType



测试可能是我创建此代码的错误,以确定它是否真的是一个列表

 从Bio.Seq import Seq 

Enzymes = {'XhoI':Seq('CTCGAG' BsmBI':Seq('CGTCTC'),'SceI':Seq('AGTTACGCTAGGGATAACAGGGTAATATAG'),'BamHI':Seq('GGATCC')''BsaI':Seq('GGTCTC')''SacI' GAGCTC'),'BbsI':Seq('GAAGAC'),'AarI':Seq('CACCTGC'),'EcoRI':Seq('GAATTC')''SpeI':Seq('ACTAGT')''CeuI ':Seq('TTCGCTACCTTAGGACCGTTATAGTTACG')}

print Enzymes.keys()是list #prints False
print isinstance(Enzymes.keys(),list)#prints True
打印类型(Enzymes.keys())#prints< type'list'>

为什么会这样的行为?如何使用字典来运行 RestrictionBatch



我正在使用:

  Python 2.7.3 | EPD 7.3 -2(64位)| (默认,2012年4月11日17:52:16)
[GCC 4.1.2 20080704(Red Hat 4.1.2-44)] on linux2

import Bio
打印(Bio .__ version__)
1.59

次要问题:
我如何检查如果是否限制在数据库?有没有办法在这个数据库中添加一个酶(假设我有需要的信息)?

解决方案

食谱松散地使用单词表。他们谈论一个列出了有效酶的名称,这些列表已经在 import Bio.Restriction 中定义。您可以列出所有(以及其他实用程序):

 从生物进口限制作为rst 

dir(rst)

但是RestrictionType比名字和序列的dict有点复杂。这是EcoRI的完整定义:

  rest_dict [EcoRI] = {
'compsite': '(ΔP GAATTC)|(ΔP GAATTC)',
'results':None,
'site':'GAATTC',
'substrat' 'DNA',
'fst3':-1,
'fst5':1,
'freq':4096,
'size':6,
' opt_temp':37,
'dna':无,
'inact_temp':65,
'ovhg':-4,
'scd3':无,
'''('B','C','F','H','I','J','K','M','N','O' R'
'scd5':None,
'charac':(1,-1,None,None,'GAATTC'),
'ovhgseq':'AATT',
}

加上供应商的一套,例如



pre> 供应商[B] =(
'Invitrogen Corporation',
['MluI','HpaII','SalI','NcoI ,'ClaI','DraI','SstII','AvaI',...)

并且打字:

  typedict [212] =(
('NonPalindromic','OneCut' Ov5','Defined','Meth_Dep',...),
['BssHII','BsrFI','DpnII','MluI','NgoMIV','HpaII','TspMI' ...],

这些定义在 Bio。 Restriction.Restriction_Dictionary



使用我之前放在另一个 anwer

  from Bio.Restriction import限制作为rst 
来自Bio.Restriction.Restriction_Dictionary import rest_dict,typedict

def create_enzyme(name):
e_types = [x for t,(x,y )in typedict.items()if name in y] [0]
enzyme_types = tuple(getattr(rst,x)for e in e_types)

return rst.RestrictionType(name,enzyme_types,rest_dict [name])

enzyme_list = [EcoRI,MstI]
rb = reduce(lambda x,y: x + y,map(create_enzyme,enzyme_list))

当菜谱说通过传递一个列表的酶或酶名称,他们正在简化的事情。在源代码中可以看到 /Bio/Restriction/Restriction.py ,当对象RestrictionBatch初始化时, __ init __ 调用 self.format self.format 检查列表中的每个项目是否为 RestrictionType



次要问题的次要答案是:

 >>>从生物进口限制作为rst 
>>>> rst.hasattr(rst,EcoRI)
True
>>> rst.hasattr(rst,FakeEnzyme)
False

 >>>来自Bio.Restriction.Restriction_Dictionary import rest_dict 
>>> rest_dict.keys()中的EcoRI
True
>>> rest_dict.keys()中的FakeEnzyme
False


I am experimenting some problems using the Bio.Restrictions methods, I am not sure if it is due to python, biopython or my poor understanding of python.

When I try to crate a RestrictionBatch following the cookbook, I want to use enzymes I from a dictionary (read from files), and it says:

You can initiate a restriction batch by passing it a list of enzymes or enzymes name as argument.

In the python documentation for dict.keys says:

Return a copy of the dictionary’s list of keys

So I tried this:

rb = RestrictionBatch(Enzymes.keys())

But I get an error: ValueError: <type 'list'> is not a RestrictionType

Testing where could be the error I created this code, to know if it is really a list or not

from Bio.Seq import Seq

Enzymes = {'XhoI': Seq('CTCGAG'), 'BsmBI': Seq('CGTCTC'), 'SceI': Seq('AGTTACGCTAGGGATAACAGGGTAATATAG'), 'BamHI': Seq('GGATCC'), 'BsaI': Seq('GGTCTC'), 'SacI': Seq('GAGCTC'), 'BbsI': Seq('GAAGAC'), 'AarI': Seq('CACCTGC'), 'EcoRI': Seq('GAATTC'), 'SpeI': Seq('ACTAGT'), 'CeuI': Seq('TTCGCTACCTTAGGACCGTTATAGTTACG')}

print Enzymes.keys() is list           #prints False
print isinstance(Enzymes.keys(), list) #prints True
print type(Enzymes.keys())             #prints <type 'list'>

Why this behaviour? And how can I use the dictionary to run the RestrictionBatch?

I am using:

Python 2.7.3 |EPD 7.3-2 (64-bit)| (default, Apr 11 2012, 17:52:16) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2

import Bio
print(Bio.__version__)
1.59

Minor question: How can I check if it is or not in the database of Restriction? Is there any way to add one enzyme to this database (assuming I have the information needed)?

解决方案

The cookbook uses loosely the word "list". They talk about a list with the names of valid enzymes, that are already defined in the import Bio.Restriction. You can list all of them (along with other utilities) with:

from Bio import Restriction as rst

dir(rst)

But the RestrictionType is a bit more complex than a dict with names and seqs. This is the full definition for "EcoRI":

rest_dict["EcoRI"] = {
    'compsite' : '(?P<EcoRI>GAATTC)|(?P<EcoRI_as>GAATTC)',
    'results' : None,
    'site' : 'GAATTC',
    'substrat' : 'DNA',
    'fst3' : -1,
    'fst5' : 1,
    'freq' : 4096,
    'size' : 6,
    'opt_temp' : 37,
    'dna' : None,
    'inact_temp' : 65,
    'ovhg' : -4, 
    'scd3' : None,
    'suppl' : ('B', 'C', 'F', 'H', 'I', 'J', 'K', 'M', 'N', 'O', 'Q', 'R'
    'scd5' : None, 
    'charac' : (1, -1, None, None, 'GAATTC'),
    'ovhgseq' : 'AATT',
}

Plus a set with the suppliers, e.g.

suppliers["B"] = (
    'Invitrogen Corporation',
    ['MluI', 'HpaII', 'SalI', 'NcoI', 'ClaI', 'DraI', 'SstII', 'AvaI', ...)

And the typedict:

typedict["212"] = (
    ('NonPalindromic', 'OneCut', 'Ov5', 'Defined', 'Meth_Dep', ...),
    ['BssHII', 'BsrFI', 'DpnII', 'MluI', 'NgoMIV', 'HpaII', 'TspMI', ...],
)

These definitions are in Bio.Restriction.Restriction_Dictionary

Using the code I previously put in another anwer:

from Bio.Restriction import Restriction as rst
from Bio.Restriction.Restriction_Dictionary import rest_dict, typedict

def create_enzyme(name):
    e_types = [x for t, (x, y) in typedict.items() if name in y][0]
    enzyme_types = tuple(getattr(rst, x) for x in e_types)

    return rst.RestrictionType(name, enzyme_types, rest_dict[name])

enzyme_list = ["EcoRI", "MstI"]
rb = reduce(lambda x, y: x + y, map(create_enzyme, enzyme_list))

When the cookbook says "by passing it a list of enzymes or enzymes name", they are simplifying the things. As you can see in the source, /Bio/Restriction/Restriction.py, when the object RestrictionBatch is initialized, __init__ calls self.format, and self.format checks that every item in the "list" is an instance of RestrictionType.

The minor answer for the minor question is:

>>> from Bio import Restriction as rst
>>> rst.hasattr(rst, "EcoRI")
True
>>> rst.hasattr(rst, "FakeEnzyme")
False

Or

>>> from Bio.Restriction.Restriction_Dictionary import rest_dict
>>> "EcoRI" in rest_dict.keys()
True
>>> "FakeEnzyme" in rest_dict.keys()
False 

这篇关于列表和限制类型从Biopython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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