r - 使用关键字列表从数据表中提取完整行
问题描述
我需要使用关键字列表提取大型数据集的子集。此处显示的大型数据集(gene_infoNCBI)包含关键字
> head(gene_infoNCBI)
X.tax_id GeneID Symbol LocusTag Synonyms dbXrefs chromosome map_location
1 7 5692769 NEWENTRY - - - - -
2 9 1246500 At1g00930 pLeuDn_01 - - - -
3 9 1246501 repA2 At1g13580 - - - -
4 9 1246502 leuA pLeuDn_04 - - - -
5 9 1246503 leuB pLeuDn_05 - - - -
6 9 1246504 leuC pLeuDn_06 - - - -
description
1 Record to support submission of GeneRIFs for a gene not in Gene (Azotirhizobium caulinodans. Use when strain, subtype, isolate, etc. is unspecified, or when different from all specified ones in Gene.).
2 putative replication-associated protein
3 putative replication-associated protein
4 2-isopropylmalate synthase
5 3-isopropylmalate dehydrogenase
6 isopropylmalate isomerase large subunit
type_of_gene Symbol_from_nomenclature_authority Full_name_from_nomenclature_authority
1 other - -
2 protein-coding - -
3 protein-coding - -
4 protein-coding - -
5 protein-coding - -
6 protein-coding - -
Nomenclature_status Other_designations Modification_date Feature_type
1 - - 20190202 -
2 - - 20180129 -
3 - - 20180129 -
4 - - 20180129 -
5 - - 20180129 -
6 - - 20180129 -
keyword.txt 的关键字与gene_infoNCBI 文件的“Symbol”和“LocusTag”值的列值匹配。
1 At1g00930 NA NA
2 At1g00930 NA NA
3 At1g00930 NA NA
4 At1g00930 NA NA
5 At1g00930 NA NA
6 At1g13580 NA NA
解决方案
这里没什么可做的,但你可以做这样的事情:
library(tidyverse)
set.seed(10)
keywords <- c("a", "c", "d", "e", "f")
key_vec <- str_c(keywords, collapse = "|")
dat <- tibble(z = seq(1, 100, 1),
y = runif(100, 0, 50),
x = sample(letters, 100, replace = T))
dat %>%
filter(str_detect(x, key_vec))
推荐阅读
- webgl - Render several graphs from single vertex buffer
- r - 计算特定元素是否在给定范围内?
- java - 如何让eclipse在打开时将依赖的maven项目部署到tomcat?
- raku - Raku(即Perl6)中是否有范围/ Num等的“钳位”方法/子?
- angular - 自定义指令 - 解析器错误:得到插值 ({{}}) 表达式应为
- c# - 在 WPF 中的 DataGrid 列中获取 button_click 事件的行
- python - 如何找到离散傅里叶变换的幅度?
- laravel - 如何使用 vuejs 从 SPA 访问 /storage -laravel- 中的图像
- sql - T-SQL 中的数据透视表分区
- sql - 如果为假,则忽略某些行