我正在尝试使用 RStudio 中的 R ODBC 驱动程序连接到 PostgreSQL 数据库。出于某种原因,R 没有检测到驱动程序:
$ Rscript -e 'odbc::odbcListDrivers()'
[1] name attribute value
<0 rows> (or 0-length row.names)
Run Code Online (Sandbox Code Playgroud)
尽管据我所知,它们已正确安装(使用自制软件):
$ brew list
freetds gettext git icu4c libtool openssl pcre2 pkg-config
postgresql psqlodbc readline sqlite sqliteodbc unixodbc
$ odbcinst -j
unixODBC 2.3.6
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /Users/barthf/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
$ cat /etc/odbcinst.ini
[PostgreSQL Driver]
Driver = /usr/local/lib/psqlodbcw.so
[SQLite Driver]
Driver = …Run Code Online (Sandbox Code Playgroud) 我正在努力优化LEFT JOIN针对两个非常大的表的简单性,到目前为止,这些表已经花费了大约12个小时来完成和持续.
这是执行计划:
Gather (cost=1001.26..11864143.06 rows=8972234 width=133)
Workers Planned: 7
-> Nested Loop Left Join (cost=1.26..10773657.51 rows=1281748 width=133)
-> Parallel Index Scan using var_case_aliquot_aliquot_ind on var_case_aliquot vca (cost=0.56..464070.21 rows=1281748 width=103)
-> Index Scan using genotype_pos_ind on snv_genotypes gt (cost=0.70..8.01 rows=1 width=65)
Index Cond: ((vca.chrom = chrom) AND (vca.start = start) AND (vca.end = end) AND ((vca.alt)::text = (alt)::text))
Filter: (vca.aliquot_barcode = aliquot_barcode)
Run Code Online (Sandbox Code Playgroud)
这是查询:
SELECT vca.aliquot_barcode,
vca.case_barcode,
vca.gene_symbol,
vca.variant_classification,
vca.variant_type,
vca.chrom,
int4range(vca.start::integer, vca."end"::integer, '[]'::text) AS pos,
vca.alt,
gt.called AS …Run Code Online (Sandbox Code Playgroud) 我正在尝试编辑一个开源 C++ 程序以进行简单的调整,以便输入之一接受正则表达式字符串而不是字符串。我是一个完整的 C++ 菜鸟(从来没有写过任何东西)所以我希望有人能指出我一个可以工作的函数。取以下代码:
#include <iostream>
#include <string>
int main() {
std::string str1("ABCDEABCABD");
std::string pattern("A");
int count1 = 0;
size_t p1 = str1.find(pattern, 0);
while(p1 != std::string::npos)
{
p1 = str1.find(pattern,p1+pattern.size());
count1 += 1;
}
std::cout << count1 << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
我希望“模式”接受由管道符号分隔的几种模式的正则表达式,例如“A|D”(在这种情况下将输出 5)。
从我从这个 C++ 参考页面收集的信息来看,您不能向 string::find 函数提供这样的正则表达式。我可以在这里放置什么功能?
谢谢!
我正在尝试使用R将多对唯一ID链接在一起.鉴于下面的示例,我有两个ID(此处为ID1和ID2)表示链接.我正在尝试创建链接的行组.在这个例子中,A链接到B,链接到D,链接到E.因为这些都是连接的,我想把它们组合在一起.接下来,还有X链接到Y和Z.因为这两个也连接,我也想将它们分配给一个组.我如何使用R来解决这个问题?
谢谢!
示例数据:
ID1 ID2
A B
B D
D E
X Y
X Z
Run Code Online (Sandbox Code Playgroud)
DPUT R表示
structure(list(id1 = structure(c(1L, 2L, 3L, 4L, 4L), .Label = c("A", "B", "D", "X"), class = "factor"), id2 = structure(1:5,.Label = c("B", "D", "E", "Y", "Z"), class = "factor")), .Names = c("id1", "id2"), row.names = c(NA, -5L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
需要的输出:
ID1 ID2 GROUP
A B 1
B D 1
D E 1
X Y 2
X Z 2
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用R/tidyverse将整洁的表(例如下面的示例)转换为嵌套列表.使用一些tidyverse魔法我能够将它转换为嵌套深度为3的列表,但我无法弄清楚如何将其嵌套得更深.
采用以下示例输入:
library(tidyverse)
library(stringi)
n_patient = 2
n_samples = 3
n_readgroup = 4
n_mate = 2
df = data.frame(patient = rep(rep(LETTERS[1:n_patient], n_samples),2),
sample = rep(rep(seq(1:n_samples), each = n_patient),2),
readgroup = rep(stri_rand_strings(n_patient * n_samples * n_readgroup, 6, '[A-Z]'),2),
mate = rep(1:n_mate, each = n_patient * n_samples * n_readgroup)) %>%
mutate(file = sprintf("%s.%s.%s_%s", patient, sample, readgroup, mate)) %>%
arrange(file)
json = df %>%
nest(-patient, .key = samples) %>%
mutate(samples = map(samples, nest, -sample, .key=readgroups))
jsonlite::toJSON(json, pretty = T)
Run Code Online (Sandbox Code Playgroud)
这看起来像这样的例子
> head(df)
patient …Run Code Online (Sandbox Code Playgroud) 我想将具有三列的表转换为类型的二维数组integer[][]。有两列指示数组的两个维度中的每一维(x在y示例中),一integer列指示值。
数据中考虑了 x 和 y 的所有可能组合,但如果可能的解决方案可以替代和NULL的缺失组合,那就太好了。xy
该表看起来像这样:
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
x VARCHAR,
y VARCHAR,
val INT
);
INSERT INTO t1 (x, y, val)
VALUES ('A', 'A', 1),
('A', 'B', 2),
('A', 'C', 3),
('B', 'A', 4),
('B', 'B', 5),
('B', 'C', 6),
('C', 'A', 7),
('C', 'B', 8),
('C', 'C', 9);
SELECT * FROM t1
Run Code Online (Sandbox Code Playgroud)
如何编写此查询以返回二维数组?
例如。此特定查询的结果应为以下数组:
SELECT '{{1,2,3},{4,5,6},{7,8,9}}'::integer[][]
Run Code Online (Sandbox Code Playgroud) 我有一种情况,我有两个向量,1,0和NA.我想在每个指数上取最高的非NA值.
例如.取这两个向量v1和v2:
v1 = c(1,0,1,0,0,1,NA,NA,0,1)
v2 = c(1,NA,1,0,1,NA,1,NA,0,1)
Run Code Online (Sandbox Code Playgroud)
您可以将它们转换为布尔值,v1 | v2然后会出现以下问题:
1 | 0 = T
0 | 1 = T
1 | 1 = T
0 | 0 = F
NA | NA = NA <--- Good
1 | NA = T <-- Good
0 | NA = NA <--- I want this to return F
Run Code Online (Sandbox Code Playgroud)
还有另一个使用apply和的解决方案max,但问题是max(c(NA,NA), na.rm=T)返回-Inf.
有没有办法在一个班轮上做到这一点?