У меня ошибка при попытке перебрать таблицу, выполняя операцию, реализованную с помощью пакета bio3d
. Я совершенно уверен, что проблема не в пакете. Давайте посмотрим.
Во-первых, давайте подготовим то, что работает.
# load libraries
library(bio3d)
library(tidyverse)
# preparing files
ids <- c("1XVL_A", "4HMO_A", "4C0R_A", "4ONY_A", "4HN9_A", "4R6H_A",
"1UIV_A", "3RY3_A", "5BRA_A", "3EJW_A")
raw.files <- get.pdb(ids)
files <-pdbsplit(raw.files, ids)
to_ali <- tidyr::crossing( fixed=files, mobile=files)
to_ali
# A tibble: 100 x 2
fixed mobile
<chr> <chr>
1 split_chain/1UIV_A.pdb split_chain/1UIV_A.pdb
2 split_chain/1UIV_A.pdb split_chain/1XVL_A.pdb
3 split_chain/1UIV_A.pdb split_chain/3EJW_A.pdb
4 split_chain/1UIV_A.pdb split_chain/3RY3_A.pdb
5 split_chain/1UIV_A.pdb split_chain/4C0R_A.pdb
6 split_chain/1UIV_A.pdb split_chain/4HMO_A.pdb
7 split_chain/1UIV_A.pdb split_chain/4HN9_A.pdb
8 split_chain/1UIV_A.pdb split_chain/4ONY_A.pdb
9 split_chain/1UIV_A.pdb split_chain/4R6H_A.pdb
10 split_chain/1UIV_A.pdb split_chain/5BRA_A.pdb
# … with 90 more rows
Теперь давайте определим нашу функцию
my_rmsd <- function(fixed,mobile){
print(class(fixed))
a <- read.pdb(fixed)
b <- read.pdb(mobile)
r <- struct.aln(a, b)
#paste("struct.aln(read.pdb(",fixed,"), read.pdb(",mobile,")")
min(r$rmsd)
}
Поскольку files
является вектором символов,посмотрим, работает ли функция
> my_rmsd(files[1],files[2])
[1] "character"
PDB has ALT records, taking A only, rm.alt=TRUE
Initial RMSD (267 atoms): 13.712
Cycle 1: 11 atoms rejected
Mean: 11.8 Std: 5.9 Cut: 23.5
RMSD (256 of 267 atoms): 12.863
Cycle 2: 12 atoms rejected
Mean: 10.8 Std: 5.4 Cut: 21.7
RMSD (244 of 267 atoms): 12.085
Cycle 3: 13 atoms rejected
Mean: 10.2 Std: 5 Cut: 20.2
RMSD (231 of 267 atoms): 11.359
Cycle 4: 9 atoms rejected
Mean: 9.6 Std: 4.5 Cut: 18.7
RMSD (222 of 267 atoms): 10.86
Cycle 5: 11 atoms rejected
Mean: 9.3 Std: 4.2 Cut: 17.7
RMSD (211 of 267 atoms): 10.329
Cycle 6: 6 atoms rejected
Mean: 9 Std: 3.8 Cut: 16.6
RMSD (205 of 267 atoms): 10.046
Cycle 7: 6 atoms rejected
Mean: 8.9 Std: 3.6 Cut: 16.1
RMSD (199 of 267 atoms): 9.786
Cycle 8: 5 atoms rejected
Mean: 8.7 Std: 3.5 Cut: 15.6
RMSD (194 of 267 atoms): 9.572
Cycle 9: 3 atoms rejected
Mean: 8.5 Std: 3.4 Cut: 15.2
RMSD (191 of 267 atoms): 9.451
Cycle 10: 2 atoms rejected
Mean: 8.4 Std: 3.3 Cut: 15.1
RMSD (189 of 267 atoms): 9.371
[1] 9.371
Сработало!
Затем давайте используем его для создания нового столбца в нашем фрейме данных.
> to_ali %>%
mutate(
rmsd = my_rmsd(fixed, mobile)
)
Error in .read_pdb(file, multi = multi, hex = hex, maxlines = maxlines, :
Expecting a single string value: [type=character; extent=100].
In addition: Warning messages:
1: In if (substr(file, 1, 4) == "http") { :
the condition has length > 1 and only the first element will be used
2: In if (toread & basename(file) != file) { :
the condition has length > 1 and only the first element will be used
3: In if (!toread) { :
Error in .read_pdb(file, multi = multi, hex = hex, maxlines = maxlines, :
Expecting a single string value: [type=character; extent=100].
15.
stop(structure(list(message = "Expecting a single string value: [type=character; extent=100].",
call = .read_pdb(file, multi = multi, hex = hex, maxlines = maxlines,
atoms_only = ATOM.only), cppstack = NULL), class = c("Rcpp::not_compatible",
"C++Error", "error", "condition")))
14.
.read_pdb(file, multi = multi, hex = hex, maxlines = maxlines,
atoms_only = ATOM.only)
13.
read.pdb(fixed)
12.
my_rmsd(fixed, mobile)
11.
mutate_impl(.data, dots, caller_env())
10.
mutate.tbl_df(., rmsd = my_rmsd(fixed, mobile))
9.
mutate(., rmsd = my_rmsd(fixed, mobile))
8.
function_list[[k]](value)
7.
withVisible(function_list[[k]](value))
6.
freduce(value, `_function_list`)
5.
`_fseq`(`_lhs`)
4.
eval(quote(`_fseq`(`_lhs`)), env, env)
3.
eval(quote(`_fseq`(`_lhs`)), env, env)
2.
withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
1.
to_ali %>% mutate(rmsd = my_rmsd(fixed, mobile))
Это не сработало. Почему?
Я не понимаю эту ошибку. Кто-нибудь знает, что, возможно, происходит? Или может предложить другую стратегию, вместо этого использовать dplyr::mutate
?
. Мне нужен был фрейм данных типа to_ali
, но с 3-м столбцом с результатом rmsd
между столбцами fixed
и mobile
.
На самом деле, я поступил странным образом:
sapply(files[1:3], function(x) sapply(files[1:3], function(y) my_rmsd(x,y))) %>%
cbind(fixed=rownames(.)) %>%
as_tibble() %>%
gather(key=mobile, value = "rmsd", -fixed)
Но любая помощь или улучшение приветствуются.
Также, если возможно, было бы приятно понять, почему я не могу выступитьэта операция с dplyr::mutate
.
Я бы хотел выполнять каждую строку параллельно, чтобы ускорить операцию. Я не знаю, как это сделать с помощью подхода sapply
, описанного выше. По крайней мере, с mutate
есть несколько альтернатив, чтобы парализовать его.
Заранее спасибо