-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/refactor_DIMS_CollectFilled #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mraves2
wants to merge
11
commits into
develop
Choose a base branch
from
feature/refactor_DIMS_CollectFilled
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+151
−66
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cbbf429
added unit tests for CollectFilled
mraves2 22d8347
added test_peakgroup_list.txt to fixtures folder for unit tests
mraves2 367a5e5
refactored CollectFilled, code moved to functions
mraves2 ac061ac
renamed function collapse in DIMS/preprocessing/collect_filled_functi…
mraves2 ad2232c
refactored function calculate_ppm_deviation in DIMS/preprocessing/col…
mraves2 20c6539
Code review suggestion applied in DIMS/CollectFilled
mraves2 11d49dc
fixed merge conflicts in DIMS/CollectFilled
mraves2 3cb60ad
fixed typo in DIMS/CollectFilled.R
mraves2 7180353
removed obsolete line from DIMS/preprocessing/collect_filled_functions.R
mraves2 4d2e6d4
changed function name for collapse in DIMS test_collect_filled.R
mraves2 fc5bfb4
New snapshot for unit testing
ALuesink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| "mzmed.pgrp" "nrsamples" "C101.1" "C102.1" "P2.1" "P3.1" "assi_HMDB" "all_hmdb_names" "iso_HMDB" "HMDB_code" "all_hmdb_ids" "sec_hmdb_ids" "theormz_HMDB" "avg.int" "avg.ctrls" "sd.ctrls" "C101.1_Zscore" "C102.1_Zscore" "P2.1_Zscore" "P3.1_Zscore" "ppmdev" | ||
| "1" 300.199680958642 0.451108327135444 1000 5000 10000 50000 "A" "A;X" NA "HMDB1234567" "HMDB1234567;HMDB1234567" NA 300.1996476 16500 3000 2828.42712474619 9000 13000 90000 130000 0.111112214857712 | ||
| "2" 300.000315890415 0.498603057814762 2000 6000 20000 60000 "B" "B;Y" NA "HMDB1234567_1" "HMDB1234567_1;HMDB1234567_1" NA 300.00017417 22000 4000 2828.42712474619 10000 14000 1e+05 140000 0.473299680976197 | ||
| "3" 300.254185894039 0.589562055887654 3000 7000 30000 70000 "C" "C;Z" NA "HMDB1234567_2" "HMDB1234567_2;HMDB1234567_2" NA 300.25413357 27500 5000 2828.42712474619 11000 15000 110000 150000 0.17426158930175 | ||
| "4" 300.755745105678 0.277923040557653 4000 8000 40000 80000 "D" "D;V" NA "HMDB1234567_7" "HMDB1234567_7;HMDB1234567_7" NA 300.75568892 33000 6000 2828.42712474619 12000 16000 120000 160000 0.186787674436346 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # unit tests for CollectFilled | ||
| # functions: collapse_information, merge_duplicate_rows, calculate_zscores_peakgrouplist, | ||
| # calculate_ppm_deviation, order_columns_peakgrouplist | ||
| source("../../preprocessing/collect_filled_functions.R") | ||
|
|
||
| testthat::test_that("Values for duplicate rows are correctly collapsed", { | ||
| test_matrix <- matrix(letters[1:8], nrow = 2, ncol = 4) | ||
| colnames(test_matrix) <- paste0("column", 1:4) | ||
|
|
||
| expect_equal(collapse_information("column1", test_matrix, c(1,2)), "a;b", TRUE) | ||
| }) | ||
|
|
||
| testthat::test_that("Duplicate rows in a peak group list are correctly merged", { | ||
| # Copy/symlink the files to the current location for the function | ||
| test_files <- list.files("fixtures/", "test_peakgroup_list", full.names = TRUE) | ||
| file.symlink(file.path(test_files), getwd()) | ||
|
|
||
| # read in peakgroup_list, create duplicate row | ||
| test_peakgroup_list <- read.table("./test_peakgroup_list.txt", sep = "\t") | ||
| test_peakgroup_list_dup <- test_peakgroup_list[c(1, 2, 2, 3), ] | ||
|
|
||
| # after merging duplicate rows, the test peak group list should have 3 rows | ||
| expect_equal(nrow(merge_duplicate_rows(test_peakgroup_list_dup)), 3, TRUE, tolerance = 0.001) | ||
| expect_equal(merge_duplicate_rows(test_peakgroup_list_dup)[3, "all_hmdb_ids"], | ||
| paste(test_peakgroup_list_dup[2, "all_hmdb_ids"], test_peakgroup_list_dup[3, "all_hmdb_ids"], sep = ";"), | ||
| TRUE) | ||
| }) | ||
|
|
||
| testthat::test_that("Z-scores are correctly calculated in CollectFilled", { | ||
| # read in peakgroup_list; remove avg.int, std.int, noise and Zscore columns | ||
| test_peakgroup_list <- read.table("./test_peakgroup_list.txt", sep = "\t") | ||
| # remove avg.ctrls, sd.ctrls and Z-score columns | ||
| test_peakgroup_list_noz <- test_peakgroup_list[ , -grep("avg.ctrls", colnames(test_peakgroup_list))] | ||
| test_peakgroup_list_noz <- test_peakgroup_list_noz[ , -grep("sd.ctrls", colnames(test_peakgroup_list_noz))] | ||
| test_peakgroup_list_noz <- test_peakgroup_list_noz[ , -grep("_Zscore", colnames(test_peakgroup_list_noz))] | ||
|
|
||
| # after calculate_zscores_peakgrouplist, there should be 4 columns with _Zscore in the name | ||
| expect_equal(length(grep("_Zscore", colnames(calculate_zscores_peakgrouplist(test_peakgroup_list_noz)))), 4, TRUE, tolerance = 0.001) | ||
|
|
||
| # after calculate_zscores_peakgrouplist, the 4 columns with _Zscore in the name should be filled non-zero | ||
| expect_equal(calculate_zscores_peakgrouplist(test_peakgroup_list_noz)$C101.1_Zscore[1], -0.7071, TRUE, tolerance = 0.00001) | ||
| expect_equal(calculate_zscores_peakgrouplist(test_peakgroup_list_noz)$P2.1_Zscore[4], 12.0208, TRUE, tolerance = 0.00001) | ||
|
|
||
| }) | ||
|
|
||
| testthat::test_that("ppm deviation values are correctly calculated in CollectFilled", { | ||
| # read in peakgroup_list | ||
| test_peakgroup_list <- read.table("./test_peakgroup_list.txt", sep = "\t") | ||
|
|
||
| # store ppm deviation values | ||
| test_ppm_values <- test_peakgroup_list$ppmdev | ||
|
|
||
| # after calculate_ppm_deviation, there ppm values in the new column should approximate the old ones | ||
| expect_equal(calculate_ppm_deviation(test_peakgroup_list)$ppmdev, test_ppm_values, TRUE, tolerance = 0.001) | ||
|
|
||
| # calculate_ppm_deviation should give NA if there is no value for theormz_HMDB | ||
| test_peakgroup_list$theormz_HMDB[1] <- NA | ||
| expect_identical(is.na(calculate_ppm_deviation(test_peakgroup_list)$ppmdev[1]), TRUE) | ||
|
|
||
| }) | ||
|
|
||
| testthat::test_that("columns in peak group list are corretly sorted", { | ||
| # read in peakgroup_list | ||
| test_peakgroup_list <- read.table("./test_peakgroup_list.txt", sep = "\t") | ||
| # original order of columns | ||
| original_column_order <- colnames(test_peakgroup_list) | ||
| # after ordering, column names should be re-ordered | ||
| test_column_order <- original_column_order[c(1, 2, 7:14, 21, 3:6, 15:20)] | ||
|
|
||
| expect_identical(colnames(order_columns_peakgrouplist(test_peakgroup_list)), test_column_order) | ||
|
|
||
| # Remove copied/symlinked files | ||
| files_remove <- list.files("./", "test_peakgroup_list.txt", full.names = TRUE) | ||
| file.remove(files_remove) | ||
|
|
||
| }) | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.