R,练习

第1题

根据R包org.Hs.eg.db找到下面ensembl 基因ID 对应的基因名(symbol)
> library(org.Hs.eg.db)
> g2s=toTable(org.Hs.egSYMBOL)
> g2e=toTable(org.Hs.egENSEMBL)
> match.id <- merge(g2s, g2e)
> head(match.id)
  gene_id symbol      ensembl_id
1       1   A1BG ENSG00000121410
2      10   NAT2 ENSG00000156006
3     100    ADA ENSG00000196839
4    1000   CDH2 ENSG00000170558
5   10000   AKT3 ENSG00000117020
6   10000   AKT3 ENSG00000275199

# 说明:
> ls("package:org.Hs.eg.db")
 [1] "org.Hs.eg"                "org.Hs.eg.db"            
 [3] "org.Hs.eg_dbconn"         "org.Hs.eg_dbfile"        
 [5] "org.Hs.eg_dbInfo"         "org.Hs.eg_dbschema"      
 [7] "org.Hs.egACCNUM"          "org.Hs.egACCNUM2EG"      
 [9] "org.Hs.egALIAS2EG"        "org.Hs.egCHR"            
[11] "org.Hs.egCHRLENGTHS"      "org.Hs.egCHRLOC"         
[13] "org.Hs.egCHRLOCEND"       "org.Hs.egENSEMBL"        
[15] "org.Hs.egENSEMBL2EG"      "org.Hs.egENSEMBLPROT"    
[17] "org.Hs.egENSEMBLPROT2EG"  "org.Hs.egENSEMBLTRANS"   
[19] "org.Hs.egENSEMBLTRANS2EG" "org.Hs.egENZYME"         
[21] "org.Hs.egENZYME2EG"       "org.Hs.egGENENAME"       
[23] "org.Hs.egGO"              "org.Hs.egGO2ALLEGS"      
[25] "org.Hs.egGO2EG"           "org.Hs.egMAP"            
[27] "org.Hs.egMAP2EG"          "org.Hs.egMAPCOUNTS"      
[29] "org.Hs.egOMIM"            "org.Hs.egOMIM2EG"        
[31] "org.Hs.egORGANISM"        "org.Hs.egPATH"           
[33] "org.Hs.egPATH2EG"         "org.Hs.egPFAM"           
[35] "org.Hs.egPMID"            "org.Hs.egPMID2EG"        
[37] "org.Hs.egPROSITE"         "org.Hs.egREFSEQ"         
[39] "org.Hs.egREFSEQ2EG"       "org.Hs.egSYMBOL"  
……

> org.Hs.egSYMBOL
SYMBOL map for Human (object of class "AnnDbBimap") 
##class一下对象,就知道具体名字##
> methods(class='AnnDbBimap') #操作函数
 [1] $                 [                 [[                as.character     
 [5] as.data.frame     as.list           colmetanames      colnames         
 [9] contents          count.links       count.mappedkeys  count.mappedLkeys
[13] count.mappedRkeys dbconn            dbfile            dbInfo           
[17] dbmeta            dbschema          dim               direction        
[21] direction<-       eapply            exists            get              
[25] getBimapFilters   isNA              keyname           keys             
[29] keys<-            length            links             Lkeyname         
[33] Lkeys             Lkeys<-           Llength           ls               
[37] mappedkeys        mappedLkeys       mappedRkeys       mget             
[41] ncol              nhit              nrow              Rattribnames     
[45] Rattribnames<-    revmap            Rkeyname          Rkeys            
[49] Rkeys<-           Rlength           sample            show             
[53] subset            summary           tagname           toTable 

第2题

根据R包hgu133a.db找到下面探针对应的基因名(symbol)

library(hgu133a.db)
ids=toTable(hgu133aSYMBOL)
head(ids)
# 出现如下提示:
> library(hgu133a.db)
Error in library(hgu133a.db) : 不存在叫‘hgu133a.db’这个名字的程辑包
> library(hgu133a.db)

# 根据提示解决问题。找到JM写的代码,修改一下下
rm(list = ls()) 
options()$repos  ## 我不知道这些代码啥意思,有空再查
options()$BioC_mirror
options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/")
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")) # 修改了镜像
options()$repos 
options()$BioC_mirror

if (!requireNamespace("hgu133a.db", quietly = TRUE))
  install.packages("hgu133a.db")
BiocManager::install("hgu133a.db",ask = F,update = F)

# 在运行之前的代码
> ids=toTable(hgu133aSYMBOL)
> head(ids)
   probe_id symbol
1   1053_at   RFC2
2    117_at  HSPA6
3    121_at   PAX8
4 1255_g_at GUCA1A
5   1316_at   THRA
6   1320_at PTPN21

第3题

找到R包CLL内置的数据集的表达矩阵里面的TP53基因的表达量,并且绘制在 progres.-stable分组的boxplot图。并思考如何通过 ggpubr 进行美化。
> rm(list = ls())
> suppressPackageStartupMessages(library(CLL))
> data(sCLLex)
> sCLLex
ExpressionSet (storageMode: lockedEnvironment)
assayData: 12625 features, 22 samples 
  element names: exprs 
protocolData: none
phenoData
  sampleNames: CLL11.CEL CLL12.CEL ... CLL9.CEL (22 total)
  varLabels: SampleID Disease
  varMetadata: labelDescription
featureData: none
experimentData: use 'experimentData(object)'
Annotation: hgu95av2 
> exprSet=exprs(sCLLex) 
> library(hgu95av2.db)



你可能感兴趣的:(R,练习)