Skip to content
Merged

Dev #62

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
5cae88f
Added unit test and created a easy opticluster function
GregJohnsonJr Apr 24, 2024
37ec06d
Release v0.0.1 (#1)
GregJohnsonJr Apr 29, 2024
931b70b
Add cpp test (#3)
GregJohnsonJr May 17, 2024
9efe436
RMD Check is able to run successfully!
GregJohnsonJr May 31, 2024
678d5a3
Correcting the paths of my cpp files, should fix the action errors.
GregJohnsonJr May 31, 2024
2c99c18
Update to the cluster command test fixture
GregJohnsonJr May 31, 2024
8f3cbc1
Modifying the test for opticluster
GregJohnsonJr Jun 3, 2024
626e70a
Ensuring everything works with c++11
GregJohnsonJr Jun 3, 2024
5b1bdb0
Removing code issues from cluster command
GregJohnsonJr Jun 3, 2024
e35e710
Adding the build ignore
GregJohnsonJr Jun 3, 2024
11a41dd
Founds some issue where I am using c++ 17 syntax and not 11.
GregJohnsonJr Jun 5, 2024
8fcff5d
Github action fixes, needed to update syntax towards cpp 11
GregJohnsonJr Jun 6, 2024
6eb79ec
Modified the testing structure by removing the "Opticluster returns p…
GregJohnsonJr Jun 6, 2024
50c3a7c
Fix cluster unit test (#5)
GregJohnsonJr Jun 10, 2024
b717404
Printing out the metrics after you perform a cluster and added a true…
GregJohnsonJr Jun 10, 2024
77ebc1c
Release polish (#6)
GregJohnsonJr Jun 14, 2024
58a4056
Added a depends for lazy-loading and other R related issues.
GregJohnsonJr Jun 14, 2024
d958121
More cluster features (#7)
GregJohnsonJr Jul 12, 2024
12aaa2e
Merge branch 'master' into dev
GregJohnsonJr Jul 12, 2024
2682ec5
The fix for github actions.
GregJohnsonJr Jul 12, 2024
b7a77be
Change to the include file.
GregJohnsonJr Jul 12, 2024
869656e
Removing srand from Utils, going to attempt to set seeds inside of R.
GregJohnsonJr Jul 12, 2024
fc8b722
Fix for race condition issue.
GregJohnsonJr Jul 15, 2024
8603183
Fix for RCMD check warnings
GregJohnsonJr Jul 15, 2024
79fb369
The fix for the windows version of RMD Check!
GregJohnsonJr Jul 16, 2024
1a4256b
Adding dependency for time.
GregJohnsonJr Jul 16, 2024
8e0ae22
Make shared (#9)
GregJohnsonJr Aug 30, 2024
7564d48
Forgot a unit test. (#10)
GregJohnsonJr Sep 3, 2024
3bd7dea
Fix results (#11)
GregJohnsonJr Sep 10, 2024
2be797e
Removing and fixing check issues.
GregJohnsonJr Sep 10, 2024
a445421
Fix compilation warnings (#12)
GregJohnsonJr Sep 11, 2024
e7d8625
Fix for negative index value
GregJohnsonJr Sep 11, 2024
ad47beb
Cleaning up build notes.
GregJohnsonJr Sep 11, 2024
ba93c19
Merge branch 'master' into dev
GregJohnsonJr Sep 11, 2024
e6a4c9f
lintr fixes
GregJohnsonJr Sep 11, 2024
386a0c7
Fix for lintr
GregJohnsonJr Sep 11, 2024
7ea9c0b
Read phylip files (#14)
GregJohnsonJr Sep 12, 2024
fa25af7
Initial push
GregJohnsonJr Sep 12, 2024
25a357d
Adding r documentation about mothur and clustur
GregJohnsonJr Sep 12, 2024
e6f00a8
Added functionality for column distance file reading!
GregJohnsonJr Sep 13, 2024
6f830c6
Column distance files work!
GregJohnsonJr Sep 13, 2024
3d8015f
Adding read column feature (#15)
GregJohnsonJr Sep 16, 2024
42162e1
Documentation (#16)
GregJohnsonJr Sep 16, 2024
d7dc294
Fix for opticluster clustering.
GregJohnsonJr Sep 16, 2024
37cdb7e
Fixing up the documentation
GregJohnsonJr Sep 16, 2024
48a0f38
I am getting the same number of bins!
GregJohnsonJr Sep 16, 2024
4c63f8c
example data
GregJohnsonJr Sep 17, 2024
58a7e8e
Fix for test error
GregJohnsonJr Sep 17, 2024
0d3e798
Testing values to RMD file
GregJohnsonJr Sep 17, 2024
3bddc53
Small changes
GregJohnsonJr Sep 18, 2024
d486604
Added sorting by bin size to cluster output and fixed the clustering …
GregJohnsonJr Sep 18, 2024
d89afb5
Modification to the test!
GregJohnsonJr Sep 18, 2024
60d16f5
Updates to test file
GregJohnsonJr Sep 18, 2024
acfbc9a
Cleaning up test
GregJohnsonJr Sep 18, 2024
585736e
Small change
GregJohnsonJr Sep 18, 2024
1623601
Method to check if each cluster exist in the dataframe
GregJohnsonJr Sep 21, 2024
d08a209
Using content paths instead of absolutes
GregJohnsonJr Sep 21, 2024
a745510
Create 96_sq_column_results_mac.list
GregJohnsonJr Sep 23, 2024
5af269d
Pushing results for different operating systems
GregJohnsonJr Sep 23, 2024
3cb0ba4
Updating documentation
GregJohnsonJr Sep 24, 2024
7c694e3
Added inst folders
GregJohnsonJr Sep 24, 2024
0b5a145
Update Cluster.R
GregJohnsonJr Sep 24, 2024
7eec4fb
Pushing the temporary fix!
GregJohnsonJr Sep 24, 2024
63d515e
Pushing spare_matrix data file
GregJohnsonJr Sep 24, 2024
6a5df20
Squashed commit of the following:
GregJohnsonJr Sep 24, 2024
a714b7d
Creating vignettes
GregJohnsonJr Sep 25, 2024
4a4fcfa
Created base pkgdown structure
GregJohnsonJr Sep 25, 2024
05c8a07
Base structure of documentation and website
GregJohnsonJr Sep 25, 2024
8c648bd
Small optimzation to clustur
GregJohnsonJr Sep 25, 2024
e87319e
Fixing unit test
GregJohnsonJr Sep 25, 2024
1251c3c
Removing comments
GregJohnsonJr Sep 25, 2024
2c642f3
Changed the name of the package to clustur
GregJohnsonJr Sep 25, 2024
3f04170
Removing unneeded data and fixing issue to validate count_table
GregJohnsonJr Sep 25, 2024
3f2d399
Fixing check errors.
GregJohnsonJr Sep 25, 2024
10c2ad9
Consistent randomization (#17)
GregJohnsonJr Sep 26, 2024
45ba179
Consistent randomization (#18)
GregJohnsonJr Sep 26, 2024
6d30db8
Squashed commit of the following:
GregJohnsonJr Sep 26, 2024
00b5013
Merge branch 'Documentation' into dev
GregJohnsonJr Sep 26, 2024
439668a
Documentation (#16) (#19) (#20)
GregJohnsonJr Sep 26, 2024
e2e52c4
Removing old vignette
GregJohnsonJr Sep 26, 2024
ea4d749
Adding additional documentation
GregJohnsonJr Sep 29, 2024
d62037b
Adding links (#22)
GregJohnsonJr Sep 30, 2024
012fc12
Moving RDS file
GregJohnsonJr Sep 30, 2024
3471ba2
Small changes to test
GregJohnsonJr Sep 30, 2024
7501509
Merge branch 'master' into dev
GregJohnsonJr Sep 30, 2024
c1cab5b
Adding a vignette, fixed the test that were failing, and removed old …
GregJohnsonJr Sep 30, 2024
a9e8095
Small change to test
GregJohnsonJr Sep 30, 2024
69b13c4
Pushing lintr fixes
GregJohnsonJr Sep 30, 2024
4f758f2
Distance files to sparse matrix (#23)
GregJohnsonJr Oct 3, 2024
43b21cf
Unify clustering (#25)
GregJohnsonJr Oct 4, 2024
64812ba
Refactor package methods (#26)
GregJohnsonJr Oct 11, 2024
a8a0863
Added tests for the validate_count_table function
GregJohnsonJr Oct 11, 2024
aca2d2e
Removing R profile from tracking
GregJohnsonJr Oct 13, 2024
cfa9e93
Merge branch 'master' into dev
GregJohnsonJr Oct 13, 2024
f2b152f
Delete .Rprofile
GregJohnsonJr Oct 13, 2024
4a8a2cf
Fix lintr and pkgdown issues
GregJohnsonJr Oct 13, 2024
ca49407
Fix for pkgdown and lintr
GregJohnsonJr Oct 13, 2024
046ed48
Change to test in cluster_object-getters.
GregJohnsonJr Oct 13, 2024
4a5b787
Squashed commit of the following:
GregJohnsonJr Oct 14, 2024
8e509d9
Sync branches (#29)
GregJohnsonJr Oct 14, 2024
3d7cddb
Fix for reading column and phylip files.
GregJohnsonJr Oct 14, 2024
8ad307c
removing data files
GregJohnsonJr Oct 14, 2024
dc9c807
Code profiling (#31)
GregJohnsonJr Oct 14, 2024
b93d89a
Removing extra storage files and merge issues
GregJohnsonJr Oct 14, 2024
1b26f74
Added New test for determining if the file is a phylip or column file…
GregJohnsonJr Oct 15, 2024
9c59c09
Merge branch 'master' into dev
GregJohnsonJr Oct 15, 2024
82de80a
lintr fix
GregJohnsonJr Oct 15, 2024
f8f524a
Merge branch 'dev' of https://github.com/SchlossLab/Clustur into dev
GregJohnsonJr Oct 15, 2024
4e4ffd2
Added new function for creating sparse matrices, and added test
GregJohnsonJr Oct 16, 2024
898c67d
Package documentation (#36)
GregJohnsonJr Oct 21, 2024
7df91d7
Merge branch 'master' into dev
GregJohnsonJr Oct 21, 2024
b461a46
lintr fixes
GregJohnsonJr Oct 21, 2024
bd9082b
Squashed commit of the following:
GregJohnsonJr Nov 6, 2024
862ed7c
Fix for sparse matrix failing
GregJohnsonJr Nov 7, 2024
f52e9b6
Sparse matrix fix (#42)
GregJohnsonJr Nov 7, 2024
c45262e
Fixing readme/readme.rmd
GregJohnsonJr Nov 7, 2024
e3bc2cb
Merge branch 'master' into dev
GregJohnsonJr Nov 7, 2024
756717e
Fix for lintr
GregJohnsonJr Nov 7, 2024
385bff8
Merge branch 'master' into dev
GregJohnsonJr Nov 7, 2024
f6ce50f
Merge branch 'master' into dev
GregJohnsonJr Nov 8, 2024
57bd9d4
Finishing touches (#47)
GregJohnsonJr Nov 8, 2024
72a0564
Removing old function and fixing the lintr issues.
GregJohnsonJr Nov 8, 2024
0f8c7dc
Merge branch 'master' into dev
GregJohnsonJr Mar 19, 2025
6659211
Merge branch 'master' into dev
GregJohnsonJr Apr 15, 2025
c2c27b6
Fix duplicated names during opticluster (#57)
GregJohnsonJr Apr 15, 2025
f2be0d7
Running through the cran release checklist to ensure everything is re…
GregJohnsonJr Apr 15, 2025
dd166ec
Updating gitignore after using revdep functions
GregJohnsonJr Apr 15, 2025
80b8f05
Merge branch 'master' into dev
GregJohnsonJr Apr 15, 2025
ef6e9f5
Merge branch 'master' into dev
GregJohnsonJr Apr 22, 2025
437fa20
Merge branch 'master' into dev
GregJohnsonJr Nov 20, 2025
19d1750
Fix valgrind errors (#60)
GregJohnsonJr Nov 25, 2025
6749141
Update to new mothur version (#61)
GregJohnsonJr Dec 12, 2025
90d7cbc
Increment version number to 0.1.4
GregJohnsonJr Dec 12, 2025
98a3517
Updates to news.md and description
GregJohnsonJr Dec 12, 2025
6420425
Fix for ubuntu devel failing
GregJohnsonJr Dec 12, 2025
00bc4ee
Lets see if insert fixes the valgrind issue.
GregJohnsonJr Dec 12, 2025
432a31c
Code should now be compiling on linux devel
GregJohnsonJr Dec 12, 2025
94a9568
Lets try using emplace to fix the valgrind issue.
GregJohnsonJr Dec 12, 2025
8098009
Removing pointers from shared file test fixture.
GregJohnsonJr Dec 15, 2025
abb4294
Changing the way we generate shared data
GregJohnsonJr Dec 15, 2025
48af80e
Revert "Changing the way we generate shared data"
GregJohnsonJr Dec 15, 2025
e1e88fd
adding an error before an invalid matrix is inputted
GregJohnsonJr Dec 17, 2025
fe30a17
Fix for valgrind issue and unexpected 1index vs 0index issue when usi…
GregJohnsonJr Dec 18, 2025
b324c04
Creating a count table twice is what I believe the valgrind issue is.
GregJohnsonJr Dec 18, 2025
81c3e9b
Removing functions in DistanceFileReader abstract class. The belief i…
GregJohnsonJr Dec 18, 2025
78b2849
Adding a move and copy constructor, lets see if this works.
GregJohnsonJr Dec 18, 2025
8d325dd
Removing zombie code, spliting our sections of code into different fi…
GregJohnsonJr Dec 19, 2025
c23eff4
Adding back the `SetCountTableAdapter()` function in cpp. Hopefully t…
GregJohnsonJr Dec 19, 2025
ce9f412
Going to see if creating a counttable with a datatable fixes the valg…
GregJohnsonJr Jan 5, 2026
e318a9c
Revert "Going to see if creating a counttable with a datatable fixes …
GregJohnsonJr Jan 5, 2026
b7c76ba
Changing vector doubles to rcpp::numericvector in counttable adapter.
GregJohnsonJr Jan 6, 2026
ca9d15c
Revert "Changing vector doubles to rcpp::numericvector in counttable …
GregJohnsonJr Jan 6, 2026
9c743ee
Lets try changing to value
GregJohnsonJr Jan 6, 2026
8c98165
Adjusting test to see if this fixes memory leak.
GregJohnsonJr Jan 6, 2026
7364fd4
Updating the test
GregJohnsonJr Jan 6, 2026
3db69f6
Removing try catch statement, lets see if this works.
GregJohnsonJr Jan 6, 2026
8e66e47
We are going to stop outside of the function instead of inside the fu…
GregJohnsonJr Jan 7, 2026
085a09c
Changing object classes to separate return objects from base R object…
GregJohnsonJr Jan 7, 2026
0315ffc
Updating news.md
GregJohnsonJr Jan 7, 2026
f1a79df
Fixed lints
GregJohnsonJr Jan 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: clustur
Type: Package
Title: Clustering
Version: 0.1.3.9000
Date: 2025-04-15
Version: 0.1.4
Date: 2025-12-12
Authors@R: c(
person("Gregory", "Johnson", , "grejoh@umich.edu", role = c("aut"),
comment = c(ORCID = "0009-0008-3890-0297")),
Expand Down
9 changes: 7 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# clustur (development version)
# clustur 0.1.4
* Updated the `cluster()` function to change the current clustering metric it is using if it is not suitable for your data.

* `read_dist()` and `cluster()` will now return objects with class name "distance_object", and "mothur_cluster" respectively. This will ensure the returned object can be differentiated between other R objects.

* Fixed memory leaks that were found using Valgrind.

# clustur 0.1.3

* Fixed `Cluster()` returning duplicate cluster names when using method = "opticlust."
* Fixed `cluster()` returning duplicate cluster names when using method = "opticlust."
39 changes: 25 additions & 14 deletions R/cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,27 @@
read_dist <- function(distance_file, count_table,
cutoff, is_similarity_matrix = FALSE) {
count_table <- validate_count_table(count_table)

if ("character" %in% class(distance_file)) {
if (inherits(distance_file, "character")) {
if (!file.exists(distance_file)) {
stop("Invalid file path: please enter a new file path.")
}
return(ProcessDistanceFiles(distance_file,
count_table, cutoff, is_similarity_matrix))
result <- ProcessDistanceFiles(distance_file,
count_table, cutoff, is_similarity_matrix)
class(result) <- "distance_object"
return(result)
}

# Its a sparse matrix not a path
# filter out the sparse matrix
return(ProcessSparseMatrix(distance_file@i, distance_file@j, distance_file@x,
count_table, cutoff, is_similarity_matrix))
if (!inherits(distance_file, "dgTMatrix")) {
stop("If you are not using a file, ensure the sparse matrix is created from
the `create_sparse_matrix()` function")
}
result <- ProcessSparseMatrix(distance_file@i, distance_file@j,
distance_file@x,
count_table, cutoff, is_similarity_matrix)
class(result) <- "distance_object"
result
}


Expand Down Expand Up @@ -99,7 +107,7 @@ read_dist <- function(distance_file, count_table,
cluster <- function(distance_object, cutoff, method = "opticlust",
feature_column_name_to = "feature",
bin_column_name_to = "bin", random_seed = 123) {
if (!("externalptr" %in% class(distance_object))) {
if (!inherits(distance_object, "distance_object")) {
stop("`distance_object` must be generated using the `read_dist` function")
}
if (!(method %in% c("opticlust",
Expand All @@ -108,9 +116,10 @@ cluster <- function(distance_object, cutoff, method = "opticlust",
average, or weighted.")
}
set.seed(random_seed)
df <- data.frame()
if (method != "opticlust") {
return(Cluster(distance_object, method,
feature_column_name_to, bin_column_name_to, cutoff))
df <- Cluster(distance_object, method,
feature_column_name_to, bin_column_name_to, cutoff)
} else {
df <- OptiCluster(distance_object, feature_column_name_to,
bin_column_name_to, cutoff)
Expand All @@ -121,8 +130,10 @@ cluster <- function(distance_object, cutoff, method = "opticlust",
"specificity", "ppv",
"npv", "fdr", "accuracy",
"mcc", "f1score")]
return(df)

}
class(df) <- "mothur_cluster"
df
}

#' Validate Count Table
Expand All @@ -148,7 +159,7 @@ validate_count_table <- function(count_table_df) {
count_table_df <- cbind(count_table_df, totals)
names(count_table_df)[3] <- "no_group"
count_table_df[[1]] <- as.character(count_table_df[[1]])
return(count_table_df)
count_table_df
}

#' Example Path
Expand All @@ -172,7 +183,7 @@ example_path <- function(file = NULL) {
} else {
path <- system.file("extdata", file, package = "clustur", mustWork = TRUE)
}
return(path)
path
}


Expand All @@ -196,7 +207,7 @@ read_count <- function(count_table_path) {
ct <- CreateDataFrameFromSparseCountTable(count_table_sparse)
return(validate_count_table(ct))
}
return(validate_count_table(read.delim(count_table_path, sep = "\t")))
validate_count_table(read.delim(count_table_path, sep = "\t"))
}

#' Create Sparse Matrix
Expand All @@ -217,5 +228,5 @@ read_count <- function(count_table_path) {
#' @export
create_sparse_matrix <- function(i_index, j_index, distances) {
size <- max(i_index, j_index)
return(spMatrix(size, size, i_index, j_index, distances))
spMatrix(size, size, i_index, j_index, distances)
}
2 changes: 1 addition & 1 deletion R/cluster_data_converters.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ split_clusters_to_list <- function(cluster) {
ls[[cluster_df[[2]][[i]]]] <-
as.list(el(strsplit(cluster_df[[1]][[i]], ",")))
}
return(ls)
ls
}
18 changes: 9 additions & 9 deletions R/cluster_object-getters.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#' @export

get_cutoff <- function(cluster_data) {
if (!("list" %in% class(cluster_data)) ||
if (!inherits(cluster_data, "mothur_cluster") ||
is.null(cluster_data$label)) {
stop("Ensure `cluster_data` is the object generated from the
`cluster` function.")
}
return(cluster_data$label)
cluster_data$label
}


Expand All @@ -41,12 +41,12 @@ get_cutoff <- function(cluster_data) {
#'
#' @return the created cluster `data.frame`.
get_bins <- function(cluster_data) {
if (!("list" %in% class(cluster_data)) ||
if (!inherits(cluster_data, "mothur_cluster") ||
is.null(cluster_data$cluster)) {
stop("Ensure `cluster_data` is the object generated from the
`cluster` function.")
}
return(cluster_data$cluster)
cluster_data$cluster
}


Expand All @@ -67,12 +67,12 @@ get_bins <- function(cluster_data) {
#'
#' @return a shared data.frame
get_abundance <- function(cluster_data) {
if (!("list" %in% class(cluster_data)) ||
if (!inherits(cluster_data, "mothur_cluster") ||
is.null(cluster_data$abundance)) {
stop("Ensure `cluster_data` is the object generated from the
`cluster` function.")
}
return(cluster_data$abundance)
cluster_data$abundance
}


Expand All @@ -93,11 +93,11 @@ get_abundance <- function(cluster_data) {
#'
#' @return a list of metric data.frames
get_metrics <- function(cluster_data) {
if (!("list" %in% class(cluster_data)) ||
if (!inherits(cluster_data, "mothur_cluster") ||
is.null(cluster_data$cluster_metrics)) {
stop("Can only use the get_metrics function when an
object is clustered using the opticluster method")
}
return(list(metrics = cluster_data$cluster_metrics,
iteration_metrics = cluster_data$iteration_metrics))
list(metrics = cluster_data$cluster_metrics,
iteration_metrics = cluster_data$iteration_metrics)
}
8 changes: 4 additions & 4 deletions R/distance_object-getters.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#'
#' @return a count_table `data.frame`.
get_count_table <- function(distance_object) {
if (!inherits(distance_object, "externalptr"))
if (!inherits(distance_object, "distance_object"))
stop("The distance object must be the object generated when
calling the `read_dist` function.")
return(GetCountTable(distance_object))
GetCountTable(distance_object)
}

#' Get Distance Data Frame
Expand All @@ -36,9 +36,9 @@ get_count_table <- function(distance_object) {
#'
#' @return a distance `data.frame`.
get_distance_df <- function(distance_object) {
if (!inherits(distance_object, "externalptr"))
if (!inherits(distance_object, "distance_object"))
stop("The distance object must be the object generated when
calling the `read_dist` function.")
df <- GetDistanceDataFrame(distance_object)
return(df)
df
}
16 changes: 4 additions & 12 deletions src/Adapters/CountTableAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,26 @@
#include <set>



class CountTableAdapter {
public:
CountTableAdapter() = default;
bool CreateDataFrameMap(const Rcpp::DataFrame& countTable);
bool CreateDataFrameMap(const Rcpp::DataFrame& count);
bool CreateDataFrameMapFromSparseCountTable(const Rcpp::DataFrame& countTable);
std::vector<std::string> GetSamples() const {return sampleNames;}
std::vector<std::string> GetSequences() const {return sequenceNames;}
// Going to ensure that each count_table atleast has a group
// And if there is no count table inputted, I will create a base one.
double FindAbundanceBasedOnGroup(const std::string& group, const std::string& sampleName) const;
double FindTotalAbundance(const std::string& sampleName) const;
std::string GetNameByIndex(int) const;
std::string GetNameByIndex(size_t) const;
std::vector<double> GetColumnByName (const std::string& name) const;
std::vector<std::string> GetGroups() const;
Rcpp::DataFrame GetCountTable() const {return countTable;}
Rcpp::DataFrame ReCreateDataFrame() const;
private:
void CreateNameToIndex();
struct IndexAbundancePair {
int groupIndex;
int sequenceIndex;
double abundance;
};
std::unordered_map<std::string, size_t> nameToRowIndex;
std::vector<std::string> sampleNames;
std::vector<std::string> sequenceNames;
std::unordered_map<std::string, std::vector<double>> dataFrameMap;
std::vector<std::string> groups;
Rcpp::DataFrame countTable{};
};


Expand Down
19 changes: 11 additions & 8 deletions src/Adapters/DistanceFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,33 @@
class DistanceFileReader {
public:
virtual ~DistanceFileReader() = default;
DistanceFileReader() = default;
// We need to deduce type, the easy way to do that is to see if there is a number for the first item read.
// Phylip files have a number of sequences located at the top. We can use that to our advantage.
virtual bool Read(const std::string& filePath) {return false;}
DistanceFileReader(SparseDistanceMatrix*, ListVector*, double, bool);
DistanceFileReader() = default;
virtual std::set<std::string> GetFailureParameters() {return failureParameters;};
DistanceFileReader(const SparseDistanceMatrix&, const ListVector&, CountTableAdapter , double, bool);
DistanceFileReader(const SparseDistanceMatrix&, const ListVector&, double, bool);
explicit DistanceFileReader(CountTableAdapter);
// Phylip files do not need a count table
SparseDistanceMatrix* GetSparseMatrix() const {return new SparseDistanceMatrix(*sparseMatrix);}
ListVector* GetListVector() const {return new ListVector(*list);}
void SetCountTable(CountTableAdapter data);
SparseDistanceMatrix* GetSparseMatrix() const {return new SparseDistanceMatrix(sparseMatrix);}
ListVector* GetListVector() const {return new ListVector(list);}
Rcpp::DataFrame SparseMatrixToDataFrame() const;
void SetCountTableAdapter(const CountTableAdapter& adapter);
Rcpp::DataFrame GetCountTable() const;
CountTableAdapter GetCountTableAdapter() const {return countTable;}
double GetCutoff() const {return cutoff;}
bool GetIsSimularity() const {return sim;}
void CreateCountTableAdapter(const Rcpp::DataFrame&);



protected:
SparseDistanceMatrix* sparseMatrix{};
SparseDistanceMatrix sparseMatrix{};
CountTableAdapter countTable;
ListVector* list{};
ListVector list{};
double cutoff = 0;
bool sim = true;
std::set<std::string> failureParameters; //If we fail to read the file or anything else
private:


Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/MatrixAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MatrixAdapter {
MatrixAdapter(const std::vector<int> &iIndexes, const std::vector<int> &jIndexes,
const std::vector<double> &dataValues, double cutOff, bool isSimularity, CountTableAdapter table);
~MatrixAdapter() = default;
SparseDistanceMatrix CreateSparseMatrix();
SparseDistanceMatrix CreateSparseMatrix() const;
ListVector CreateListVector() const;

private:
Expand Down
32 changes: 18 additions & 14 deletions src/ClusterCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ ClusterExport* ClusterCommand::runOptiCluster(OptiMatrix *optiMatrix, const doub
cutoffs.insert(std::to_string(cutoff));

OptiData *matrix = optiMatrix;
if (!matrix->mccValidCalc()) {
Rcpp::warning("[WARNING]: The mcc metric is not suitible for your data with a cutoff of " +
std::to_string(cutoff) + " using tptn instead.");
delete metric;
metric = new TPTN();
}
for (auto it = cutoffs.begin(); it != cutoffs.end(); it++) {
OptiCluster cluster(matrix, metric, 0);
int iters = 0;
Expand Down Expand Up @@ -107,21 +113,21 @@ ClusterExport* ClusterCommand::runOptiCluster(OptiMatrix *optiMatrix, const doub
}
util.AddRowToDataFrameMap(dataframeMapClusterMetrics, clusterMetrics, clusterMetricsHeaders);
}
ListVector *list = nullptr;
// ListVector *list = nullptr;
// clusterMetrics += "\n\n";
list = cluster.getList();
list->setLabel(std::to_string(cutoff));
ListVector list = cluster.getList();
list.setLabel(std::to_string(cutoff));
//
if (printHeaders) {
//only print headers the first time
printHeaders = false;
} else { list->setPrintedLabels(printHeaders); }
} else { list.setPrintedLabels(printHeaders); }
OptiClusterInformation clusterInformation;
clusterInformation.label = std::to_string(cutoff);
clusterInformation.numberOfOtu = static_cast<int>(numBins);
clusterInformation.clusterBins = list->print(listFile);
clusterInformation.clusterBins = list.print(listFile);
data->AddToData(clusterInformation);
data->SetListVector(*list, std::to_string(cutoff));
data->SetListVector(list, std::to_string(cutoff));
stats = cluster.getStats(tp, tn, fp, fn);

sensFile += std::to_string(cutoff) + ',' + std::to_string(cutoff) + ',' + std::to_string(tp) + ',' +
Expand All @@ -130,7 +136,6 @@ ClusterExport* ClusterCommand::runOptiCluster(OptiMatrix *optiMatrix, const doub
for (double result: stats) { sensFile += std::to_string(result) + ','; }
util.AddRowToDataFrameMap(dataframeMapSensMetrics, sensFile, sensfileHeaders);
}
delete matrix;
return data;
}

Expand Down Expand Up @@ -175,13 +180,13 @@ ClusterExport* ClusterCommand::runMothurCluster(const std::string &clusterMethod

if(!data.label.empty()) {
data.clusterBins = oldList.print(listFile);
auto* vec = new ListVector(oldList);
ListVector listVec(oldList);
list->setPrintedLabels(false);
clusterData->AddToData(data);
if(rndPreviousDist > highestDistLabel) {
highestDistLabel = rndPreviousDist;
vec->setLabel(std::to_string(highestDistLabel));
clusterData->SetListVector(*vec, std::to_string(highestDistLabel)); // vec might be a shallow copy
listVec.setLabel(std::to_string(highestDistLabel));
clusterData->SetListVector(listVec, std::to_string(highestDistLabel)); // vec might be a shallow copy
}
}
oldList = *list;
Expand All @@ -201,13 +206,12 @@ ClusterExport* ClusterCommand::runMothurCluster(const std::string &clusterMethod

if(!data.label.empty()) {
data.clusterBins = oldList.print(listFile);
auto* vec = new ListVector(oldList);

ListVector listVec(oldList);
clusterData->AddToData(data);
if(rndPreviousDist > highestDistLabel) {
highestDistLabel = rndPreviousDist;
vec->setLabel(std::to_string(highestDistLabel));
clusterData->SetListVector(*vec, std::to_string(highestDistLabel));
listVec.setLabel(std::to_string(highestDistLabel));
clusterData->SetListVector(listVec, std::to_string(highestDistLabel));
}
}
delete(cluster);
Expand Down
Loading
Loading