我有一个像这样的 tsv 文件。
读取ID | V_段 |
---|---|
abc | IGHV3-18-F(2695) |
定义 | IGHV3-9-F(2714),IGHV3-12-F(2656) |
吉 | IGHV3-9-F(2840) |
jkl | IGHV3-10-F(2666),IGHV3-18-F(2666) |
使用 R,我需要过滤,一方面,那些包含“V_segment”列中的值的行,另一方面,那些包含“V_segment”列中的两个或多个值的行(用逗号分隔的值) )。并创建两个表,其中一个表的行在“V_segment”列中具有一个值,而其他表则包含其他行。
我到现在为止写的代码是:
df <- read_tsv('alignments.tsv')
alignments_v <- data.frame(df$readId, df$V_segment,
stringsAsFactors = FALSE)
x <- alignments_v %>% separate(df.V_segment, c('V segment', 'Combinations V segment'), sep = ',')
但是我没有得到我需要的东西......
你能帮我吗?
提前谢谢您!
在基本 R 中,您可以使用
grepl
来过滤分隔多个条目的逗号:
V_one <- df[!grepl("\\,", df$V_segment),]
# readId V_segment
# 1 abc IGHV3-18-F(2695)
# 3 ghi IGHV3-9-F(2840)
V_twoplus <- df[grepl("\\,", df$V_segment),]
# readId V_segment
# 2 def IGHV3-9-F(2714),IGHV3-12-F(2656)
# 4 jkl IGHV3-10-F(2666),IGHV3-18-F(2666)