PoonLab / clustuneR

Implementing clustering algorithms on genetic data and finding optimal parameters through the performance of predictive growth models.
GNU General Public License v3.0
0 stars 0 forks source link

pull.headers not returning anything #9

Closed ArtPoon closed 2 years ago

ArtPoon commented 2 years ago

To reproduce (using commit 46fc1baa019960f052eabed6f5406db2a258c2eb):

> seq.info <- pull.headers(alignment.ex, var.names=c("ID", "CollectionDate", "Subtype"), var.transformations=list(as.character, as.Date, as.factor))
New names:
* x -> x...1
* x -> x...2
* x -> x...3
> seq.info
>
ArtPoon commented 2 years ago

I can walk through the function code without the same problem:

> var.names=c("ID", "CollectionDate", "Subtype")
> var.transformations=list(as.character, as.Date, as.factor)
> sep='_'
> seqs <- alignment.ex
>   # Split and transform data from headers
>   split.headers <- sapply(names(seqs), function(x) {
+     strsplit(x, sep)[[1]]
+   })
>   seq.info <- lapply(1:nrow(split.headers), function(i) {
+     x <- unname(split.headers[i, ])
+     x <- var.transformations[[i]](x)
+     data.table::data.table(x)
+   })
>   seq.info <- dplyr::bind_cols(seq.info)
New names:
* x -> x...1
* x -> x...2
* x -> x...3
>   colnames(seq.info) <- var.names
>   seq.info[, "Header" := names(seqs)]
> seq.info
            ID CollectionDate Subtype                     Header
 1: KU190546.1     2011-09-27    subB KU190546.1_2011-09-27_subB
 2: KU190384.1     2010-02-23    subB KU190384.1_2010-02-23_subB
 3: KU190294.1     2009-07-06    subB KU190294.1_2009-07-06_subB
 4: KU190419.1     2010-06-15    subB KU190419.1_2010-06-15_subB
 5: KU190347.1     2009-11-25    subB KU190347.1_2009-11-25_subB
 6: KU190221.1     2009-01-06    subB KU190221.1_2009-01-06_subB
 7: KU190698.1     2012-10-18    subB KU190698.1_2012-10-18_subB
 8: KU190731.1     2013-01-02    subB KU190731.1_2013-01-02_subB
 9: KU190643.1     2012-04-09    subB KU190643.1_2012-04-09_subB
10: KU190710.1     2012-11-15    subB KU190710.1_2012-11-15_subB
ArtPoon commented 2 years ago

Problem resolved by ditching the data.table := syntax

diff --git a/R/sequence.setup.R b/R/sequence.setup.R
index 74fac1b..ece98c5 100644
--- a/R/sequence.setup.R
+++ b/R/sequence.setup.R
@@ -46,8 +46,9 @@ pull.headers <- function(seqs, var.names, var.transformations = 
list(), sep = "_

   seq.info <- dplyr::bind_cols(seq.info)
   colnames(seq.info) <- var.names
-
-  seq.info[, "Header" := names(seqs)]
-
+  
+  seq.info$Header <- names(seqs)
+  #seq.info[, "Header" := names(seqs)]
+  
   return(seq.info)
 }