- 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/
我需要为打开的 xlsx 文件取消隐藏工作表 TAB,为此,我使用 VBS 文件打开 xlsm 文件并激活宏(位于模块中)。 当我手动运行宏时,它可以工作。 当它通过vbs激活时,它只能看到包含宏的x
我正在使用 Google Cloud Compute Engine 安装气流并使其保持正常运行。安装很好,现在它在主机上运行:0.0.0.0:8080 我有此 VM 实例的外部 IP 地址,但是我无法
我们可以在 GWT 中使用这个 $entry 方法来允许外部 javascript 执行 java 方法。 你可以在他们的文档 https://developers.google.com/web-to
在 Cython 的“Hello World”和 C 数学库中调用函数的示例之后 here ,我真正想做的是将我自己的 C 代码放在一个单独的文件中,并在 Cython 中使用它。关注 this ,我
我一直在试验 JSON Pointers引用和重用 JSON schemas . 按照示例,我能够引用在另一个 JSON 模式中声明的特定属性,一切都按预期进行,但是我还没有找到一种方法来扩展基本 J
我正在使用 X.jar 并添加到我的 AspectJ 项目(在 eclipse 中)。我已经为 X.jar 中的 myMethod() 方法编写了切入点和建议。 但是aspectj 并没有拦截这个方法
我正在 Controller 中创建一个自定义指令,并在 ng-repeat 中调用它,如下所示: HTML: JS: 在测试指令中,我按如下方式调用 loadDat
我正在尝试加载服务器上本地存在的 HTML 页面,位于名为 HTML-FIles 的文件夹中。 我想使用 jquery 加载一个文件并将其内容显示在 div 中。 现在,我可以加载文件,但在 div
我正在尝试根据初始选择从 JSON 文件生成选择菜单。我见过很多不同的方式,人们为此编写了一个函数,但想要一些非常简单的东西。 HTML: Please select Practis
我的目标是从 HTML 文档中获取文本,该文档不会调用 .jsp 文件中的任何函数。 我环顾四周,我以为我已经找到了问题的答案,但它似乎不起作用,其他答案包括使用 jQuery(我既不熟悉也不允许使用
我正在尝试从外部 JSON 文件获取文件内容,但我一直在警报中收到 null。 JS: function getText() { var result = null; var file
我正在加载一个外部 javascript 文件,该文件仅填充有 int 或字符串或 bool 值或数组的变量。类似... varBool=false; var1="var1"; var2="var2:
我的数据存储在外部 Javascript 文件中。 看起来像这样, window.videos = [{ "name": "Sample data", "duration": 154,
我有一个包含 Google ADWords 的 HTML 页面,以及来自外部 URL 的 ajax 调用,我想获取 json 来自 url 的数据。外部API也是我做的。API Controller
我试图看看是否有一种简单的方法可以通过外部 JavaScript 函数访问 Controller 的内部范围(与目标 Controller 完全无关) 我在这里看到了其他几个问题 angular.el
我尝试在运行外部命令时终止脚本,结果出现错误。考虑这个简单的代码: try { where.exe Test-App } catch { Write-Error "Exception
我在 test.js 中定义了一个外部 JS 函数 function InvokeSupport(ID, TimeStamp, Hash) { var sUrl = '' + "?uid="
如果我想将变量从外部 js 文件提取到另一个外部 js 文件。我该怎么做? 例如,如果我有一个名为 example1.js 的文件,其中包含以下代码 var test = 1; 如何获取变量 tes
我正在尝试使用 java 从外部 jar 中读取文件..例如,我有两个 jar 文件。一个是“foo.jar”,另一个是“bar.jar”。 “bar.jar”内部是文件“foo-bar.txt”。如
在我的 Java 应用程序中,我希望从未实际加载的类文件以及也未加载的 jar 文件中读取字节码内容。理想情况下,我需要能够获取任何给定的 jarfile,并找到其中的所有类。因此,考虑以下情况: 我
我是一名优秀的程序员,十分优秀!