Skip to content

Commit ed01ac4

Browse files
committed
Initial implementation of ALStructure wrapper
1 parent 24ba751 commit ed01ac4

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/Rscript
2+
# Copyright 2019 Francisco Pina Martins <[email protected]>
3+
# This file is part of structure_threader.
4+
# structure_threader is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
9+
# structure_threader is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
14+
# You should have received a copy of the GNU General Public License
15+
# along with structure_threader. If not, see <http://www.gnu.org/licenses/>.
16+
17+
ll = Sys.getenv()[ grep("R_LIBS_USER", names(Sys.getenv())) ]
18+
local_lib = gsub("^.*\t", "", ll)
19+
20+
if(!require("alstructure")){
21+
if(!require("devtools")){
22+
install.packages("devtools", lib=.libPaths()[1])
23+
}
24+
library("devtools")
25+
install_github("storeylab/alstructure", build_vignettes=FALSE, ref="e355411", lib=.libPaths()[1])
26+
library(alstructure)
27+
}
28+
29+
if(!require(lfa)){
30+
if (!requireNamespace("BiocManager", quietly = TRUE))
31+
install.packages("BiocManager", lib=.libPaths()[1])
32+
33+
BiocManager::install("lfa", lib=.libPaths()[1])
34+
library(lfa)
35+
}
36+
37+
alstructure_wrapper = function(input_prefix, K) {
38+
#' ALStructure wrapper
39+
#'
40+
#' Small wrapper function that wraps ALStructure
41+
#' Takes an input prefix (file minus the extension) and value of K
42+
#' as arguments and returns a q-matrix
43+
44+
K = as.numeric(K)
45+
input_data = lfa::read.bed(input_prefix)
46+
fit <- alstructure(X = input_data, d_hat=K)
47+
q_matrix = t(fit$Q_hat)
48+
49+
return(q_matrix)
50+
}
51+
52+
args = commandArgs(trailingOnly=TRUE)
53+
54+
if (sys.nframe() == 0){
55+
Q_matrix = alstructure_wrapper(args[1], args[2])
56+
write.csv(Q_matrix, args[3])
57+
}

0 commit comments

Comments
 (0)