R包安利 ② pubmed.mineR—又一個(gè)PubMed利器

hmmmmm


1.1 關(guān)于 pubmed.mineR

Jyoti Rani, S.Ramachandan and Ab. Rauf Shah (2014). Text mining of PubMed abstracts. R package version 1.0.5

Find it with 'help(package=pubmed.mineR)'

最新版: 1.0.15 , 2019-05-06

從 Title 和 Description 看,“Text Mining of PubMed Abstracts (text and XML) ”,這是一個(gè)致力于從 Pubmed Abstarct 文件挖掘文本/數(shù)據(jù)的包,包里一大堆函數(shù)/數(shù)據(jù):

ls("package:pubmed.mineR")
# [1] "alias_fn"                       "altnamesfun"                   
# [3] "BWI"                            "cleanabs"                      
# [5] "cluster_words"                  "co_occurrence_fn"              
# [7] "combineabs"                     "common_words_new"              
# [9] "contextSearch"                  "cos_sim_calc"                  
# [11] "cos_sim_calc_boot"              "currentabs_fn"                 
# [13] "Find_conclusion"                "find_intro_conc_html"          
# [15] "gene_atomization"               "genes_BWI"                     
# [17] "GeneToEntrez"                   "Genewise"                      
# [19] "get_gene_sentences"             "get_MedlinePlus"               
# [21] "get_NMids"                      "get_original_term"             
# [23] "get_original_term2"             "get_PMCIDS"                    
# [25] "get_PMCtable"                   "get_Sequences"                 
# [27] "getabs"                         "getabsT"                       
# [29] "Give_Sentences"                 "Give_Sentences_PMC"            
# [31] "head_abbrev"                    "HGNC2UniprotID"                
# [33] "HGNCdata"                       "input_for_find_intro_conc_html"
# [35] "local_uniprotfun"               "names_fn"                      
# [37] "official_fn"                    "pmids_to_abstracts"            
# [39] "previousabs_fn"                 "prevsymbol_fn"                 
# [41] "printabs"                       "pubtator_function"             
# [43] "pubtator_result_list_to_table"  "readabs"                       
# [45] "readabsnew"                     "ready"                         
# [47] "removeabs"                      "searchabsL"                    
# [49] "searchabsT"                     "sendabs"                       
# [51] "SentenceToken"                  "space_quasher"                 
# [53] "subabs"                         "subsetabs"                     
# [55] "tdm_for_lsa"                    "uniprotfun"                    
# [57] "whichcluster"                   "word_associations"             
# [59] "word_atomizations"              "wordscluster"                  
# [61] "wordsclusterview"               "xmlgene_atomizations"          
# [63] "xmlreadabs"                     "xmlword_atomizations"          
# [65] "Yearwise"   

2.1 數(shù)據(jù)準(zhǔn)備

在 PubMed 搜索想要的內(nèi)容,創(chuàng)建 Abstract 文件。

3.1 Text Mining 技能點(diǎn)亮

3.1.1 讀取從 PubMed 下載的 Abstract 文件

利用函數(shù) readabs() 讀取。

得到的 pubmed_abstracts 是一種 S4 object, Journal , Abstract , PMID 分別是一個(gè) slot.

library(pubmed.mineR)
pubmed_abstracts <- readabs("pubmed_result.txt")
class(pubmed_abstracts)
# [1] "Abstracts"
# attr(,"package")
# [1] "pubmed.mineR"
printabs(pubmed_abstracts)  ## 顯示開頭和結(jié)尾部分

3.1.2 從 pubmed_abstracts 提取 PMID

pmid <- pubmed_abstracts@PMID
pmid
# [1] 31158748 31158746 31158660 31157709 31157548 31157505
class(pmid)
# [1] "numeric"

3.1.3 獲取注釋信息

函數(shù) pubtator_function() 只需輸入 PMID(數(shù)字或上一步得到的 pmid), 就可以給出相應(yīng)的信息,如 'Gene’, ’Chemical’, ’Disease’ 等。

pubtator_output <- pubtator_function(pmid)

也可以直接輸入PMID.

pubtator_ot6 <- pubtator_function(31157505)

然鵝有時(shí)……

pubtator_ot1 <- pubtator_function(31158748)
pubtator_ot1
# [1] " No Data "

也有歪果友人發(fā)生這樣的問題,但直接輸入 3.1.2 得到的 pmid 是沒問題的ヾ(?ω?`)o

想獲取其中一項(xiàng):

pubtator_output$Genes
#  [1] "nuclear factor kappa B>81736" "NF-kB>81736"                 
#  [3] "cyclooxygenase-2>29527"       "COX-2>29527"                 
#  [5] "p53>301300"                   "CTr>116506"                  
#  [7] "NF- kB>81736"                 "P53>301300"                  
#  [9] "p16>1029"                     "p53>7157"                    
# [11] "p53>22060"                    "p16>13088"                   
# [13] "mPTP>19273"                  
pubtator_output$Genes[1]
# [1] "nuclear factor kappa B>81736"

3.1.5 函數(shù)SentenceToken() 獲取信息

SentenceToken() 可以從 3.1.1 得到的 pubmed_abstracts 中提取語句。

abstractstc <- pubmed_abstracts@Abstract
SentenceToken(abstractstc[1])
# [1] "ahead of print]  The synthesis and anticancer activity of 2-styrylquinoline derivatives." 
# ……

3.1.6 將獲得的信息輸出為 .txt 文件

這時(shí)要用到這個(gè)函數(shù):sendabs()

sendabs(pubmed_abstracts,"mypba.txt")

4.1 一些可視化玩法

4.1.1 統(tǒng)計(jì)詞頻

函數(shù) word_atomizations 可以將整個(gè)文本拆分成單詞,除去空格、標(biāo)點(diǎn)符號(hào)、常用單詞,統(tǒng)計(jì)剩下的單詞出現(xiàn)的頻率。

p53_words <- word_atomizations(pubmed_abstracts)
p53_words[1:10,]  ## 只下載了6篇文章的abstract, 樣本有點(diǎn)少惹
#          words Freq
# 139     cancer   13
# 385        p53   11
# 146       cell   10
# 147      cells   10
# 221 expression    9
# 83    activity    8
# 111  apoptosis    8
# 382        p16    8
# 226         fd    7
# 304      level    7

4.1.2 統(tǒng)計(jì)"基因頻"

函數(shù) gene_atomization() 基于包內(nèi)自帶的 HGNC 數(shù)據(jù)庫,可以從文本提取 Gene Symbol 和其出現(xiàn)的頻率。

p53_gene <- gene_atomization(pubmed_abstracts)
p53_gene
#      Gene_symbol    Genes                           Freq
# [1,] "TP53"      "tumor protein p53"                "2" 
# [2,] "ADC"       "arginine decarboxylase"           "1" 
# [3,] "NQO1"      "NAD(P)H dehydrogenase, quinone 1" "1" 

4.1.3 兩個(gè)新技能

以 ”關(guān)鍵詞“ 和 "年份" 兩個(gè)參數(shù),得到 PubMed 中相關(guān)文章的數(shù)量,并可視化。

參考代碼來自這里這里

library(RISmed)
library(dplyr)
library(ggplot2)
library(tidytext)
library(wordcloud)
result <- EUtilsSummary("(p53) AND cancer", 
                         type = "esearch", 
                         db = "pubmed",
                         datetype = "pdat",
                         retmax = 10000,
                         mindate = 1970, 
                         maxdate = 2019)
fetch <- EUtilsGet(result, type = "efetch", db = "pubmed") 
abstracts <- data.frame(title = fetch@ArticleTitle,
                        abstract = fetch@AbstractText, 
                        journal = fetch@Title,
                        DOI = fetch@PMID, 
                        year = fetch@YearPubmed) 
abstracts <- abstracts %>% mutate(abstract = as.character(abstract))
abstracts %>%
  group_by(year) %>%
  count() %>%
  filter(year > 1969) %>%
  ggplot(aes(year, n)) +
  geom_point() +
  geom_line() +
  labs(title = "Pubmed articles with search terms (p53) AND cancer \n1970-2019", hjust = 0.5,
       y = "Articles")

## 然而不知道為什么畫出來的圖只有2016-2019...(+_+)?

繪制詞云圖:

cloud <- abstracts %>%
  unnest_tokens(word, abstract) %>%
  anti_join(stop_words) %>%
  count(word, sort = TRUE)
cloud %>%
  with(wordcloud(word, n, min.freq = 15, max.words = 500, colors = brewer.pal(8, "Dark2")), scale = c(8,.3), per.rot = 0.4)

得到了一張又方又丑的圖。(:з)∠)_

References


最后,向大家隆重推薦生信技能樹的一系列干貨!

  1. 生信技能樹全球公益巡講:https://mp.weixin.qq.com/s/E9ykuIbc-2Ja9HOY0bn_6g
  2. B站公益74小時(shí)生信工程師教學(xué)視頻合輯:https://mp.weixin.qq.com/s/IyFK7l_WBAiUgqQi8O7Hxw
  3. 招學(xué)徒:https://mp.weixin.qq.com/s/KgbilzXnFjbKKunuw7NVfw
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容