1- test_that(" Testing Metagenomics reading and writing of BIOM files" , {
2- # Loading hdf5 format
3- taxa_hdf5 <- metagenomics $ new(
4- biomData = " input/metagenomics/biom_with_taxonomy_hdf5.biom" ,
5- metaData = " input/metagenomics/metadata.tsv" ,
6- treeData = " input/metagenomics/rooted_tree.newick"
7- )
8-
9- taxa_ref <- metagenomics $ new(
10- countData = taxa_hdf5 $ countData ,
11- metaData = taxa_hdf5 $ metaData ,
12- treeData = taxa_hdf5 $ treeData ,
13- featureData = taxa_hdf5 $ featureData
1+ # # Load example data
2+ biom_hdf5 <- " input/metagenomics/biom_with_taxonomy_hdf5.biom"
3+ biom_json <- " input/metagenomics/biom_with_taxonomy_json.biom"
4+ tree <- " input/metagenomics/rooted_tree.newick"
5+
6+ test_that(" `metagenomics` -- Argument checks" , {
7+
8+ # # Ensuring `metaData` is supplied
9+ expect_snapshot(metagenomics $ new(), error = TRUE )
10+ expect_snapshot(metagenomics $ new(biomData = " nonexisting.biom" ), error = TRUE )
11+ expect_snapshot(metagenomics $ new(featureData = features_file ), error = TRUE )
12+ expect_snapshot(metagenomics $ new(countData = counts_sparse_file ), error = TRUE )
13+ expect_snapshot(metagenomics $ new(metaData = data.frame ()), error = TRUE )
14+ expect_snapshot(metagenomics $ new(metaData = data.table :: data.table()), error = TRUE )
15+
16+ # # Checking errors
17+ expect_snapshot(metagenomics $ new(metaData = metadata_file , featureData = data.frame ()), error = TRUE )
18+ expect_snapshot(metagenomics $ new(metaData = metadata_file , featureData = data.table :: data.table()), error = TRUE )
19+ expect_snapshot(metagenomics $ new(metaData = metadata_file , biomData = " nonexisting.biom" ), error = TRUE )
20+ expect_snapshot(metagenomics $ new(metaData = metadata_file , biomData = metadata_file ), error = TRUE )
21+
22+ expect_snapshot(metagenomics $ new(metaData = metadata_file , countData = data.frame ()), error = TRUE )
23+ expect_snapshot(metagenomics $ new(metaData = metadata_file , countData = data.table :: data.table()), error = TRUE )
24+ expect_snapshot(metagenomics $ new(metaData = metadata_file , countData = matrix (0 )), error = TRUE )
25+
26+ expect_snapshot(metagenomics $ new(metaData = metadata_file , treeData = data.frame ()), error = TRUE )
27+ expect_snapshot(metagenomics $ new(metaData = metadata_file , treeData = ape :: rtree(50 )), error = TRUE )
28+ expect_snapshot(metagenomics $ new(metaData = metadata_file , biomData = biom_hdf5 , treeData = ape :: rtree(50 )), error = TRUE )
29+ })
30+
31+ test_that(" `metagenomics` -- Behavioral checks" , {
32+ # Loading biom hdf5
33+ expect_snapshot(
34+ test <- metagenomics $ new(
35+ metaData = metadata_file ,
36+ biomData = biom_hdf5
37+ )
1438 )
15-
16- expect_snapshot(taxa_hdf5 )
17- expect_snapshot(taxa_ref )
18-
19- # Adding treeData after init
20- taxa_ref <- metagenomics $ new(
21- countData = taxa_hdf5 $ countData ,
22- metaData = taxa_hdf5 $ metaData ,
23- featureData = taxa_hdf5 $ featureData ,
39+ expect_equal(all(rownames(test $ countData ) == test $ featureData $ FEATURE_ID ), TRUE )
40+ expect_equal(all(colnames(test $ countData ) == test $ metaData $ SAMPLE_ID ), TRUE )
41+ expect_equal(inherits(test $ countData , " sparseMatrix" ), TRUE )
42+ expect_equal(class(test $ metaData )[1 ], " data.table" )
43+ expect_equal(class(test $ featureData )[1 ], " data.table" )
44+
45+ # Loading biom json
46+ expect_snapshot(
47+ test <- metagenomics $ new(
48+ biomData = biom_json ,
49+ metaData = data.table :: data.table(SAMPLE_ID = c(
50+ " Sample1" , " Sample2" , " Sample3" ,
51+ " Sample4" , " Sample5" , " Sample6" ))
52+ )
2453 )
54+ expect_equal(all(rownames(test $ countData ) == test $ featureData $ FEATURE_ID ), TRUE )
55+ expect_equal(all(colnames(test $ countData ) == test $ metaData $ SAMPLE_ID ), TRUE )
56+ expect_equal(inherits(test $ countData , " sparseMatrix" ), TRUE )
57+ expect_equal(class(test $ metaData )[1 ], " data.table" )
58+ expect_equal(class(test $ featureData )[1 ], " data.table" )
2559
26- expect_error(taxa_ref $ treeData <- taxa_hdf5 $ countData )
27- expect_no_error(taxa_ref $ treeData <- taxa_hdf5 $ treeData )
60+ # Loading biom hdf5 with tree
61+ expect_snapshot(
62+ test <- metagenomics $ new(
63+ metaData = metadata_file ,
64+ biomData = biom_hdf5 ,
65+ treeData = tree
66+ )
67+ )
68+ expect_equal(all(rownames(test $ countData ) == test $ featureData $ FEATURE_ID ), TRUE )
69+ expect_equal(all(rownames(test $ countData ) == test $ treeData $ tip.label ), TRUE )
70+ expect_equal(all(test $ treeData $ tip.label == test $ featureData $ FEATURE_ID ), TRUE )
71+ expect_equal(all(colnames(test $ countData ) == test $ metaData $ SAMPLE_ID ), TRUE )
72+ expect_equal(inherits(test $ countData , " sparseMatrix" ), TRUE )
73+ expect_equal(class(test $ metaData )[1 ], " data.table" )
74+ expect_equal(class(test $ featureData )[1 ], " data.table" )
2875
29- # Loading JSON format
30- taxa_json <- metagenomics $ new(
31- biomData = " input/metagenomics/biom_with_taxonomy_json.biom" ,
32- metaData = data.table :: data.table(SAMPLE_ID = c(
33- " Sample1" , " Sample2" , " Sample3" ,
34- " Sample4" , " Sample5" , " Sample6" ))
76+ # Checking loading metagenomics from pre-loaded test
77+ expect_snapshot(
78+ taxa_ref <- metagenomics $ new(
79+ countData = test $ countData ,
80+ metaData = test $ metaData ,
81+ treeData = test $ treeData ,
82+ featureData = test $ featureData
83+ )
3584 )
36- expect_snapshot(taxa_json )
37- })
85+ expect_equal(all(rownames(test $ countData ) == rownames(taxa_ref $ countData )), TRUE )
86+ expect_equal(all(colnames(test $ countData ) == colnames(taxa_ref $ countData )), TRUE )
87+ expect_equal(all(test $ featureData $ FEATURE_ID == taxa_ref $ featureData $ FEATURE_ID ), TRUE )
88+ expect_equal(all(test $ treeData $ tip.label == taxa_ref $ treeData $ tip.label ), TRUE )
89+ expect_equal(all(test $ metaData $ SAMPLE_ID == taxa_ref $ metaData $ SAMPLE_ID ), TRUE )
90+ expect_equal(inherits(test $ countData , " sparseMatrix" ), inherits(taxa_ref $ countData , " sparseMatrix" ))
91+ expect_equal(class(test $ metaData )[1 ], class(taxa_ref $ metaData )[1 ])
92+ expect_equal(class(test $ featureData )[1 ], class(taxa_ref $ featureData )[1 ])
93+ })
0 commit comments