- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 PubmedID 从 Pubmed 中提取 60K 篇文章的摘要。我正在尝试将摘要导出到字典中。我想我正在使用的代码存在一些问题,尤其是在解析 pubmed ID 时。请帮助更正代码并让我知道哪里出了问题。
from Bio import Entrez
import sys
Entrez.email = 'anonymous@gmail.com'
abstract_dict = {}
without_abstract = []
pub_ids = sys.argv[1]
f = open(pub_ids, "r")
for i in f:
handle = Entrez.efetch(db="pubmed", id=','.join(map(str, i)),
rettype="xml", retmode="text")
records = Entrez.read(handle)
abstracts = [pubmed_article['MedlineCitation']['Article']['Abstract']['AbstractText'][0]
if 'Abstract' in pubmed_article['MedlineCitation']['Article'].keys()
else pubmed_article['MedlineCitation']['Article']['ArticleTitle']
for pubmed_article in records['PubmedArticle']]
abstract_dict = dict(zip(i, abstracts))
print(abstract_dict)
一些示例 Pubmed ID 是:
17284678
15531828
11791095
10708056
我得到的结果只有几行摘要或空字典。是否可以将结果从字典导出到制表符分隔的文本文件中?
任何建议将不胜感激
谢谢
最佳答案
请注意,Entrez.efetch
只会返回 1000 条记录。既然你说要下载60K的摘要,我修改了你的代码,实现了批量下载摘要。
from Bio import Entrez
import sys
import csv
Entrez.email = 'anonymous@gmail.com'
def fetch_abstracts(pub_ids, retmax=1000, output_file='abstracts.csv'):
# Make sure requests to NCBI are not too big
for i in range(0, len(pub_ids), retmax):
j = i + retmax
if j >= len(pub_ids):
j = len(pub_ids)
print(f"Fetching abstracts from {i} to {j}.")
handle = Entrez.efetch(db="pubmed", id=','.join(pub_ids[i:j]),
rettype="xml", retmode="text", retmax=retmax)
records = Entrez.read(handle)
abstracts = [pubmed_article['MedlineCitation']['Article']['Abstract']['AbstractText'][0]
if 'Abstract' in pubmed_article['MedlineCitation']['Article'].keys()
else pubmed_article['MedlineCitation']['Article']['ArticleTitle']
for pubmed_article in records['PubmedArticle']]
abstract_dict = dict(zip(pub_ids[i:j], abstracts))
with open(output_file, 'a', newline='') as csvfile:
fieldnames = ['pub_id', 'abstract']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames, delimiter='\t')
if i == 0:
writer.writeheader()
for pub_id, abstract in abstract_dict.items():
writer.writerow({'pub_id': pub_id, 'abstract': abstract})
if __name__ == '__main__':
filename = sys.argv[1]
pub_ids = open(filename, "r").read().splitlines()
fetch_abstracts(pub_ids)
如果你这样运行:
stack73000220.py pubids.txt
pubids.txt
看起来像:
17284678
15531828
11791095
10708056
然后您将在 abstracts.csv
中获得以下输出:
pub_id abstract
17284678 Eimeria tenella is an intracellular protozoan parasite that infects the intestinal tracts of domestic fowl and causes coccidiosis, a serious and sometimes lethal enteritis. Eimeria falls in the same phylum (Apicomplexa) as several human and animal parasites such as Cryptosporidium, Toxoplasma, and the malaria parasite, Plasmodium. Here we report the sequencing and analysis of the first chromosome of E. tenella, a chromosome believed to carry loci associated with drug resistance and known to differ between virulent and attenuated strains of the parasite. The chromosome--which appears to be representative of the genome--is gene-dense and rich in simple-sequence repeats, many of which appear to give rise to repetitive amino acid tracts in the predicted proteins. Most striking is the segmentation of the chromosome into repeat-rich regions peppered with transposon-like elements and telomere-like repeats, alternating with repeat-free regions. Predicted genes differ in character between the two types of segment, and the repeat-rich regions appear to be associated with strain-to-strain variation.
15531828 To study the occurrence of nosocomial diarrhea in pediatric wards and the role of infections in its causation.
11791095 Based on single case reports, parvovirus B19 (B19) has repeatedly been proposed as an etiologic agent in patients with Henoch-Schönlein purpura (HSP), perhaps causing vasculitis by direct invasion of vascular endothelial cells because of the tissue distribution of the cellular B19 receptor. A cohort of children with HSP and other vasculitic diseases was investigated and compared with healthy control children to assess the role of B19 as well as parvovirus V9 (a putative emerging B19-like virus).
10708056 The effects of chemokine and chemokine receptor genetic polymorphisms such as stromal derived factor 1 (SDF1-3'A), CCR2-64I, and CCR5-delta32 associated with HIV-1 transmission and/or rate of disease progression in infected study subjects remain highly controversial and have been analyzed primarily only in adults. We have investigated whether these polymorphisms may provide similar beneficial effects in children exposed to HIV-1 perinatally. The prevalence of CCR2-64I allele was significantly increased (p = .03) and the CCR2-64I genotype distribution was not in Hardy-Weinberg equilibrium, among HIV-1-exposed uninfected infants. Moreover, in the HIV-1-infected group, a delay to AIDS progression was observed among carriers of CCR2-64I allele. This is the first report that suggests a protective role of CCR2-64I allele in mother-to-infant HIV-1 transmission and documents a delay in disease progression, after the child has been infected with HIV-1. However, SDFI-3'A and CCR5-delta32 alleles did not modify the rate of HIV-1 transmission or disease progression in HIV-1-infected children.
关于python - 使用 biopython 从外部 pubmed ID 列表中提取多个摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73000220/
出现在 python 2.7.8 中。 3.4.1 不会发生这种情况。 示例: >>> id(id) 140117478913736 >>> id(id) 140117478913736 >>> id
好吧,我对动态创建的控件的 ID 很困惑。 Public Class TestClass Inherits Panel Implements INamingContainer
我收到下面的错误,说有堆栈溢出。发生这种情况是因为带有 IN (id, id, id...id) 的 SQL 语句有大量参数。有没有什么办法解决这一问题?这是在我使用 Eclipse 的本地环境中发生
为什么 CPython(不知道其他 Python 实现)有以下行为? tuple1 = () tuple2 = ()
为什么 CPython(对其他 Python 实现一无所知)有以下行为? tuple1 = () tuple2 = ()
非常简单的问题:当我有一个持久对象时,它通常有一个名为 ID 的属性(对于抽象类)。 那么..命名约定是ID还是Id? 例如。 public int ID { get; set; } 或 public
知道为什么我会收到此错误,我已经尝试了所有命名约定(小写/大写) 我正在使用 Vaadin,这是我的代码片段: public class Usercontainer extends BeanI
为什么 CPython(不知道其他 Python 实现)有以下行为? tuple1 = () tuple2 = ()
我需要改变表的所有主键 UPDATE TODO SET id = id + 1 但我做不到(Demo 来自 Ahmad Al-Mutawa 的回答)描述了原因。主键不能这样改。 我也不能根据这是 sq
我正在尝试列出与用户相关的讨论列表。 想象一下,如果你愿意的话: posts -------------------------------------------------------------
我有一个表,其中包含一些具有自己的 ID 和共享 SKU key 的文章。我尝试使用左连接进行查询,并使用组结果获取从查询返回的所有 id。 我的数据结构是这样的: id - name -
在下表People中: id name 1 James 2 Yun 3 Ethan 如果我想找到最大 ID,我可以运行此查询 select max(id) id from People; 结果是
我正在产品页面上创建评论模块,其中显示垃圾评论选项,并显示 onclick 显示和隐藏弹出窗口。现在它在单个评论中工作正常但是当评论是两个时它同时打开两个因为类是相同的。现在这就是为什么我想要获取父
根据 REST 哲学,PUT操作应该(取自维基百科): PUT http://example.com/resources/142 Update the address member of the co
我想知道如何在使用 PHP 或 JavaScript 进行身份验证后从 Google Analytics 获取 Property Id、View Id 和 Account Id?因为我希望能够将它们存
我想使用所选按钮的 ID 进行删除。但我不知道如何从中获取/获取 id。我尝试了 this.id 但不起作用。 这是我创建按钮的地方: var deleteEmployer= document.cre
我有一个具有以下结构的表“表” ID LinkedWith 12 13 13 12 14 13 15 14 16
请不要在未阅读问题的情况下将问题标记为重复。我确实发布了一个类似的问题,但 STACKOVERFLOW 社区成员要求我单独重新发布修改后的问题,因为考虑到一个小而微妙的修改,解决方案要复杂得多。 假设
在 Android Studio 中,我创建了一个 Person.java 类。我使用Generate 创建了getter 和setter 以及构造函数。 这是我的 Person.java 类: pu
如何在 jQuery 中制作这样的东西: //这是显示的主体 ID //当我悬停 #hover-id 时,我希望 #principal-id 消失并更改 。但是当我将光标放在 #this-id 上时
我是一名优秀的程序员,十分优秀!