我正在尝试更改以前的脚本,该脚本利用 biopython 获取有关物种门的信息。编写此脚本是为了一次检索一个物种的信息。我想修改脚本,以便我可以一次对 100 个生物执行此操作。这是初始代码
import sys
from Bio import Entrez
def get_tax_id(species):
"""to get data from ncbi taxomomy, we need to have the taxid. we can
get that by passing the species name to esearch, which will return
the tax id"""
species = species.replace(" ", "+").strip()
search = Entrez.esearch(term = species, db = "taxonomy", retmode = "xml")
record = Entrez.read(search)
return record['IdList'][0]
def get_tax_data(taxid):
"""once we have the taxid, we can fetch the record"""
search = Entrez.efetch(id = taxid, …Run Code Online (Sandbox Code Playgroud) 当我尝试运行 Biopython 提供的用于 NCBIWWW.qblast 在线搜索的测试文件时,它只是一直挂着,从不响应。当我尝试自己运行任何包含 NCBIWWW.qblast 的脚本时,也会发生同样的情况:它刚刚到达此行并停止。不会发出任何错误消息,不会收到任何结果,并且该过程永远不会以任何方式结束。
产生问题的脚本之一是:
from Bio.Blast import NCBIWWW
result_handle=qblast('blastn', 'nt', 'AGAAAGGGTATATAAAATCAAGAATCTGGGGTGTTTGTGTTGACTTGTATAATTCTTGATTTTTTCAGGTAGTTGAAAAGGTGGGAGAAAAGTGGAGAAGCCTAAGCTGATATTGAAATTCATATGGATGGAAGAACATTGGTTTAGGATTGGATCAAAAAATAGGTGGACATGGAACTGTA')
Run Code Online (Sandbox Code Playgroud)
可能是什么问题?
使用biopython库,我想删除列表中列出的残留物,如下所示。该线程(http://pelican.rsvs.ulaval.ca/mediawiki/index.php/Manipulated_PDB_files_using_BioPython)提供了一个去除残留物的示例。我有以下代码来去除残留物
residue_ids_to_remove = [105, 5, 8, 10, 25, 48]
structure = pdbparser.get_structure("3chy", "./3chy.pdb")
first_model = structure[0]
for chain in first_model:
for residue in chain:
id = residue.id
if id[1] in residue_ids_to_remove:
chain.detach_child(id[1])
modified_first_model = first_model
Run Code Online (Sandbox Code Playgroud)
但这段代码不起作用并引发了错误
def detach_child(self, id):
"Remove a child."
child=self.child_dict[id]
KeyError: '105'
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题?
或者,我可以使用accept_residue()并将其写入PDB。我不想这样跟踪,因为我想在内存中执行此操作以进行进一步处理。
尝试在 Fedora 21、Python 2.7 上安装 Biopython。我做了以下
[mike@localhost Downloads](17:32)$ sudo pip2.7 install biopython
You are using pip version 6.1.1, however version 7.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting biopython
/usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading biopython-1.65.tar.gz (12.6MB)
100% |????????????????????????????????| 12.6MB 33kB/s
Installing collected packages: biopython
Running setup.py install …Run Code Online (Sandbox Code Playgroud) 我希望能够在Seq对象中搜索seq对象来解释模糊代码.例如,以下内容应为真:
from Bio.Seq import Seq
from Bio.Alphabet.IUPAC import IUPACAmbiguousDNA
amb = IUPACAmbiguousDNA()
s1 = Seq("GGAAAAGG", amb)
s2 = Seq("ARAA", amb) # R = A or G
print s1.find(s2)
Run Code Online (Sandbox Code Playgroud)
如果考虑到歧义代码,答案应该是
>>> 2
Run Code Online (Sandbox Code Playgroud)
但我得到的答案是找不到匹配,或者
>>> -1
Run Code Online (Sandbox Code Playgroud)
查看biopython源代码,似乎没有考虑歧义代码,因为使用private _get_seq_str_and_check_alphabet方法将子序列转换为字符串,然后使用内置字符串方法find().当然,如果是这种情况,"R"模糊度代码将被视为文字"R",而不是A或G.
我可以弄清楚如何用自制方法做到这一点,但似乎应该在使用其Seq对象的biopython包中处理.这里有什么我想念的东西.
有没有办法搜索模糊代码的子序列成员资格?
我正在尝试使用Entrez将发布数据导入数据库.搜索部分工作正常,但当我尝试解析时:
from Bio import Entrez
def create_publication(pmid):
handle = Entrez.efetch("pubmed", id=pmid, retmode="xml")
records = Entrez.parse(handle)
item_data = records.next()
handle.close()
Run Code Online (Sandbox Code Playgroud)
...我收到以下错误:
文件"/venv/lib/python2.7/site-packages/Bio/Entrez/Parser.py",第296行,解析引发ValueError("XML文件不代表列表.请使用Entrez.read而不是Entrez .parse")ValueError:XML文件不代表列表.请使用Entrez.read而不是Entrez.parse
这段代码以前一直工作到几天前.有什么想法可能会出错吗?
此外,查看源代码(http://biopython.org/DIST/docs/api/Bio.Entrez-pysrc.html)并尝试按照列出的示例,给出相同的错误:
from Bio import Entrez
Entrez.email = "Your.Name.Here@example.org"
handle = Entrez.efetch("pubmed", id="19304878,14630660", retmode="xml")
records = Entrez.parse(handle)
for record in records:
print(record['MedlineCitation']['Article']['ArticleTitle'])
handle.close()
Run Code Online (Sandbox Code Playgroud) 我正在寻找伏击终止密码子。我已经得到了我的代码,可以从我的embl文件中提取我需要的序列。然而,我对如何添加两个上游和两个下游核苷酸感到有些困惑,所以我最终得到了 -2、-1、0、1、2 个阅读框。
for rec in SeqIO.parse("CP002701.embl", "embl"):
if rec.features:
for feature in rec.features:
if feature.type == "CDS":
print(feature.location)
print(feature.qualifiers["protein_id"])
print(feature.location.extract(rec).seq)
Run Code Online (Sandbox Code Playgroud)
是我想更改但不确定如何更改.location以选择我感兴趣的额外 4 个碱基的部分。
仅供参考:这不是重复的!
在运行python代码之前,我在cmd提示符下安装了biopython:
pip install biopython
Run Code Online (Sandbox Code Playgroud)
然后,当我尝试将其导入python时,我收到一条错误消息:“没有名为Bio的模块”
import Bio
Run Code Online (Sandbox Code Playgroud)
同样的事情发生
import biopython
Run Code Online (Sandbox Code Playgroud)
应当指出,我已经更新了PIP并运行python 3.5.2
,感谢任何人的帮助。
我是一名新近自学成才的(减去 1 节非常基础的课程)程序员,在生物实验室工作。我有一个脚本,它遍历来自两种不同细胞类型的 RNAseq 数据,并在另一个数据集中运行 ttest。它适用于这个应用程序,但代码感觉非常粗鲁,我知道我会写很多类似的脚本。
如何更好地编写以下代码以使其更高效?
计划目标:
:
import pandas as pd
from scipy.stats import ttest_ind
rnatest = {'Gene symbol':["GeneA","GeneB"],"rnaseq1A":[1,1.5],"rnaseq1B":[1.3,1.2],"rnaseq2A":[2.3,2.7],"rnaseq2B":[2,2.6]}
df = pd.DataFrame(rnatest)
GOIlist = ["GeneA","GeneB"]
GOI = []
mu = []
pval = []
for index, row in df.iterrows():
if row['Gene symbol'] in GOIlist:
t, p = ttest_ind([row["rnaseq1A"],row["rnaseq1B"]],[row["rnaseq2A"],row["rnaseq2B"]])
GOI.append(row['Gene symbol'])
mu.append(t)
pval.append(p)
df2 = {'Gene symbol':GOI,"tVAL":mu, "pVAL":pval}
df2 = pd.DataFrame(df2)
print(df2)
Run Code Online (Sandbox Code Playgroud) 我有一个包含数千个登录号的文件:
看起来像这样..
>NC_033829.1 Kallithea virus isolate DrosEU46_Kharkiv_2014, complete genome
AGTCAGCAACGTCGATGTGGCGTACAATTTCTTGATTACATTTTTGTTCCTAACAAAATGTTGATATACT
>NC_020414.2 Escherichia phage UAB_Phi78, complete genome
TAGGCGTGTGTCAGGTCTCTCGGCCTCGGCCTCGCCGGGATGTCCCCATAGGGTGCCTGTGGGCGCTAGG
Run Code Online (Sandbox Code Playgroud)
如果想将其拆分为多个文件,每个文件都有一个登录号,那么我可以使用以下代码
awk -F '|' '/^>/ {F=sprintf("%s.fasta",$2); print > F;next;} {print >> F;}' < yourfile.fa
Run Code Online (Sandbox Code Playgroud)
我有一个包含数千个登录号(又名 >NC_*)的文件,并希望将其拆分,例如每个文件包含约 5000 个登录号。因为我是 awk/bash/python 的新手,所以我很难找到一个巧妙的解决方案
任何想法或评论表示赞赏