Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cAmpSeqR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Simeon Rossmann
cAmpSeqR
Commits
e1761832
Commit
e1761832
authored
1 year ago
by
Simeon
Browse files
Options
Downloads
Patches
Plain Diff
clustering threshold test for meshclust
parent
2a6eb09c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
R/test_clustering_thresholds.R
+39
-17
39 additions, 17 deletions
R/test_clustering_thresholds.R
man/test_clustering_thresholds.Rd
+15
-1
15 additions, 1 deletion
man/test_clustering_thresholds.Rd
with
54 additions
and
18 deletions
R/test_clustering_thresholds.R
+
39
−
17
View file @
e1761832
...
...
@@ -7,6 +7,11 @@
#' @param step_size The step size for the threshold values. Default is 0.01.
#' @param step_max The maximum threshold value. Default is 0.99.
#' @param ncores The number of cores to use for parallel processing. Default is 1.
#' @param method Method used for clustering, can be "Clusterize" (default) or a
#' file path to the location of meshclust on the users machine, e.g. obtained by
#' running `which meshclust`, see also \code{\link{meshclustR}}.
#' @param meshclust_temp_dir temporary directory for meshclust files.
#' Temporary files will be removed after running the function.
#'
#' @return A list of clustering results, where each element in the list corresponds to a specific threshold value.
#'
...
...
@@ -22,28 +27,45 @@
#' results <- test_clustering_thresholds(my_sequences, step_size = 0.1, step_max = 0.9, ncores = 2)
#' @export
test_clustering_thresholds
<-
function
(
MyDNAstring
,
step_size
,
step_max
=
0.99
,
ncores
=
1
)
{
step_max
=
0.99
,
ncores
=
1
,
method
=
"Clusterize"
,
meshclust_temp_dir
=
"tmp"
)
{
#DECIPHER removed the 'type' argument from IdClusters around v2.24. Currently (Feb23), the function is renamed "Clusterize"
if
(
numeric_version
(
packageVersion
(
"DECIPHER"
))
<
2.24
){
clus_tbl
<-
IdClusters
(
method
=
"inexact"
,
myXStringSet
=
MyDNAstring
,
cutoff
=
seq
(
0
,
step_max
,
step_size
),
processors
=
ncores
,
verbose
=
FALSE
)
if
(
method
==
"Clusterize"
){
#DECIPHER removed the 'type' argument from IdClusters around v2.24. Currently (Feb23), the function is renamed "Clusterize"
if
(
numeric_version
(
packageVersion
(
"DECIPHER"
))
<
2.24
){
clus_tbl
<-
IdClusters
(
method
=
"inexact"
,
myXStringSet
=
MyDNAstring
,
cutoff
=
seq
(
0
,
step_max
,
step_size
),
processors
=
ncores
,
verbose
=
FALSE
)
}
else
{
clus_tbl
<-
Clusterize
(
MyDNAstring
,
cutoff
=
seq
(
0
,
step_max
,
step_size
),
processors
=
ncores
,
verbose
=
FALSE
)
}
clus_tbl_list
<-
as_tibble
(
clus_tbl
,
rownames
=
"seqnames"
)
%>%
pivot_longer
(
cols
=
-
seqnames
,
names_to
=
"cutoff"
,
values_to
=
"cluster"
)
%>%
group_by
(
cutoff
)
%>%
group_split
(
.keep
=
FALSE
)
}
else
if
(
dir.exists
(
method
)){
preexisting
<-
dir.exists
(
meshclust_temp_dir
)
dir.create
(
meshclust_temp_dir
)
clust_tbl_list
<-
lapply
(
seq
(
0
,
step_max
,
step_size
),
meshclustR
,
seqs
=
MyDNAstring
,
filepath
=
meshclust_temp_dir
,
meshclust_bin
=
method
)
if
(
!
preexisting
){
unlink
(
meshclust_temp_dir
)
}
}
else
{
clus_tbl
<-
Clusterize
(
MyDNAstring
,
cutoff
=
seq
(
0
,
step_max
,
step_size
),
processors
=
ncores
,
verbose
=
FALSE
)
stop
(
"'method' argument needs to be 'Clusterize' or the file path to the meshclust bin ('which meshclust' in shell)."
)
}
steps_temp
<-
seq
(
0
,
step_max
,
step_size
)
clus_tbl_list
<-
as_tibble
(
clus_tbl
,
rownames
=
"seqnames"
)
%>%
pivot_longer
(
cols
=
-
seqnames
,
names_to
=
"cutoff"
,
values_to
=
"cluster"
)
%>%
group_by
(
cutoff
)
%>%
group_split
(
.keep
=
FALSE
)
steps_temp
<-
seq
(
0
,
step_max
,
step_size
)
names
(
clus_tbl_list
)
<-
steps_temp
return
(
clus_tbl_list
)
}
This diff is collapsed.
Click to expand it.
man/test_clustering_thresholds.Rd
+
15
−
1
View file @
e1761832
...
...
@@ -4,7 +4,14 @@
\alias{test_clustering_thresholds}
\title{Iterate over threshold values}
\usage{
test_clustering_thresholds(MyDNAstring, step_size, step_max = 0.99, ncores = 1)
test_clustering_thresholds(
MyDNAstring,
step_size,
step_max = 0.99,
ncores = 1,
method = "Clusterize",
meshclust_temp_dir = "tmp"
)
}
\arguments{
\item{MyDNAstring}{A DNAStringSet object containing the DNA sequences to be clustered.}
...
...
@@ -14,6 +21,13 @@ test_clustering_thresholds(MyDNAstring, step_size, step_max = 0.99, ncores = 1)
\item{step_max}{The maximum threshold value. Default is 0.99.}
\item{ncores}{The number of cores to use for parallel processing. Default is 1.}
\item{method}{Method used for clustering, can be "Clusterize" (default) or a
file path to the location of meshclust on the users machine, e.g. obtained by
running `which meshclust`, see also \code{\link{meshclustR}}.}
\item{meshclust_temp_dir}{temporary directory for meshclust files.
Temporary files will be removed after running the function.}
}
\value{
A list of clustering results, where each element in the list corresponds to a specific threshold value.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment