如何将自定义函数带有正则表达式列表映射到大型数据集以生成单个数据集? [R]

问题描述

我的问题: 我有一个包含数千个单列 csv 的文件夹,我已经构建了一个自定义函数来处理。保存清洁过程重复非常有效,但现在我发现我只是在每组复制品上使用该功能名称末尾的数字 1-5)。 IE。为了数据保证而复制的细胞成像结果 - 但它们不相同

但是每组重复都有一个组合爆炸标签。例如:

  • 有“F1-F8”静音,但还有“ror”、“con”、“F1-8+ ror”、“F1-8+ ror con”、“ror con”、“ror os”、“+” ror os con”...等等,最后有两个蛋白质它们自己的组合 - 所以手动编写每个正则表达式是限制因素

我所做的和正在做的 - 这里的一些示例数据:

set.seed(1234)

library(tidyverse)
library(fs)
n = 100000
source = factor(c("f1 con npd1 wnt5a1","nc con5","f4+ror os wnt5a3","f2+ror os npd1 wnt5a2"))
source = rep(source,n)
intensity = sample(4000:10000,n)

big_ole_df <- cbind(source,intensity)
big_ole_df$source <- source


################# and here's my clunk of a func:
sort_combine_clean <- function(combined_df,id_phrase,before_target,label){
  #verify it's a DF
  combined_df <- as.data.frame(combined_df)
  
  #store new df from combined:
  out_df <- 
    subset(combined_df,grepl(id_phrase,combined_df$source))
  out_df$source <- 
    as.factor(out_df$source)
  
  #detect silencing before target string
  out_df$silencing <-
    sub(before_target,"",out_df$source)
  out_df$silencing <-
    as.factor(out_df$silencing)
  
  #label the protein
  out_df$protein <-
    as.factor(label)
  
  out_df <<- out_df
}

然后,我基本上正在经历和做:

sort_combine_clean(big_ole_df,id_phrase = c("some regex to identify the set,needs to be exclusive to the grouping!"),before target = c("the name of the FirsT protein if more than 1"),label = c("the name of the LAST protein,and if not a protein,label as NONE"))

f1_bagillionth_combination <- out_df
rm(out_df)

冲洗并重复

请帮我找到一种更程序化的方法来做到这一点! 谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)