我正在处理一些遗传数据,但我的一栏内容不是我想要的格式。我不知道在这里谈论了多少生物学,但我正在尝试固定氨基酸在数据中的显示方式。
氨基酸显然有一个名称,但也有3个字母的缩写和1个字母的缩写。我的数据包含3个字母形式的氨基酸,但我想将其更改为1个字母的缩写。这是我的数据示例。
chr location effect impact AA_change
1 12543 missense_variant MODERATE p.Ala12Val
1 52367 missense_variant MODERATE p.Leu54Pro
1 752347 missense_variant MODERATE p.Met99Ser
1 984645 missense_variant MODERATE p.Lys34Ile
1 989845 missense_variant MODERATE p.Arg4Cys
1 999854 missense_variant MODERATE p.His43Gly
1 999855 missense_variant MODERATE p.Glu14Phe
dat <- structure(list(chr = c(1L, 1L, 1L, 1L, 1L, 1L, 1L), location = c(12543L,
52367L, 752347L, 984645L, 989845L, 999854L, 999855L), effect = c("missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant"), impact = c("MODERATE",
"MODERATE", "MODERATE", "MODERATE", "MODERATE", "MODERATE", "MODERATE"
), AA_change = c("Ala12Val", "Leu54Pro", "Met99Ser", "Lys34Ile",
"Arg4Cys", "His43Gly", "Glu14Phe")), .Names = c("chr", "location",
"effect", "impact", "AA_change"), row.names = c(NA, -7L), class = "data.frame")
以下是3个字母的氨基酸及其更好的缩写的列表。
Ala == A
Arg == R
Asn == N
Asp == D
Cys == C
Glu == E
Gln == Q
Gly == G
His == H
Ile == I
Leu == L
Lys == K
Met == M
Phe == F
Pro == P
Ser == S
Thr == T
Trp == W
Tyr == Y
Val == V
我觉得可以做一个简单的功能来做到这一点,但是我正在努力做到这一点。我习惯于只更改列的一部分而不是一次更改两件事。所以我要问的是我该如何改变
Ala12Val
Leu54Pro
Met99Ser
Lys34Ile
Arg4Cys
His43Gly
Glu14Phe
对此
A12V
L54P
M99S
K32I
R4C
E14F
这可以做吗?
答案 0 :(得分:2)
查找氨基酸,然后获取子字符串的前3个字母并映射,提取数字,子字符串的后3个字母并映射。然后将所有粘贴在一起。
scalaVersion := "2.11.12"
libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.3.0"
libraryDependencies += "com.microsoft.sqlserver" % "mssql-jdbc" % "6.2.1.jre8"
libraryDependencies += "org.scalafx" %% "scalafx" % "8.0.144-R12"
libraryDependencies += "org.apache.ignite" % "ignite-core" % "2.5.0"
libraryDependencies += "org.apache.ignite" % "ignite-spring" % "2.5.0"
libraryDependencies += "org.apache.ignite" % "ignite-indexing" % "2.5.0"
libraryDependencies += "org.apache.spark" % "spark-streaming_2.11" % "2.3.0"
libraryDependencies += "org.apache.spark" % "spark-streaming-kafka-0-10_2.11" % "2.3.0"
libraryDependencies += "org.apache.spark" % "spark-sql-kafka-0-10_2.11" % "2.3.0"
libraryDependencies += "org.apache.kafka" % "kafka-streams" % "1.1.0"
libraryDependencies += "com.101tec" % "zkclient_2.11" % "0.10"
libraryDependencies += "org.apache.kafka" % "kafka_2.11" % "1.1.0"
答案 1 :(得分:2)
b=which(adist(dat2$V1,dat$AA_change,partial = T)==0,T)
dat$AA_change1=`regmatches<-`(dat$AA_change,gregexpr("\\D+",dat$AA_change),
value=split(dat2$V3[b[,1]],b[,2]))
dat
chr location effect impact AA_change AA_change1
1 1 12543 missense_variant MODERATE Ala12Val A12V
2 1 52367 missense_variant MODERATE Leu54Pro L54P
3 1 752347 missense_variant MODERATE Met99Ser M99S
4 1 984645 missense_variant MODERATE Lys34Ile I34K
5 1 989845 missense_variant MODERATE Arg4Cys R4C
6 1 999854 missense_variant MODERATE His43Gly G43H
7 1 999855 missense_variant MODERATE Glu14Phe E14F
dat2 = read.table(text="Ala == A
Arg == R
Asn == N
Asp == D
Cys == C
Glu == E
Gln == Q
Gly == G
His == H
Ile == I
Leu == L
Lys == K
Met == M
Phe == F
Pro == P
Ser == S
Thr == T
Trp == W
Tyr == Y
Val == V")[-2]
答案 2 :(得分:2)
如果它始终为{acid,numbers,acid}形式,则可以将其分为三列,并用match
或连接进行替换。使用data.table,看起来就像...
library(data.table)
setDT(dat)
# put your mapping into a nicer format
abbrDT = fread(header = FALSE,"
Ala == A
Arg == R
Asn == N
Asp == D
Cys == C
Glu == E
Gln == Q
Gly == G
His == H
Ile == I
Leu == L
Lys == K
Met == M
Phe == F
Pro == P
Ser == S
Thr == T
Trp == W
Tyr == Y
Val == V")[, .(abbr3 = V1, abbr1 = V3)]
# split the column
patt = "(?<=\\d)(?=\\D)|(?<=\\D)(?=\\d)"
dat[, c("AA1", "num", "AA2") := tstrsplit(AA_change, patt, perl=TRUE)]
# substitute for each part
dat[abbrDT, on=.(AA1 = abbr3), AA1 := abbr1]
dat[abbrDT, on=.(AA2 = abbr3), AA2 := abbr1]
给出
chr location effect impact AA_change AA1 num AA2
1: 1 12543 missense_variant MODERATE Ala12Val A 12 V
2: 1 52367 missense_variant MODERATE Leu54Pro L 54 P
3: 1 752347 missense_variant MODERATE Met99Ser M 99 S
4: 1 984645 missense_variant MODERATE Lys34Ile K 34 I
5: 1 989845 missense_variant MODERATE Arg4Cys R 4 C
6: 1 999854 missense_variant MODERATE His43Gly H 43 G
7: 1 999855 missense_variant MODERATE Glu14Phe E 14 F
(可选)再次合并各列,然后删除不需要的列:
dat[, AA_change := paste0(AA1, num, AA2)]
dat[, c("AA1", "num", "AA2") := NULL]