Repository navigation
Conversation
… left out of year/country modes with nothing recorded. .targetsInTooFewGroups() noe starts from every target in profile
Contributor
Author
|
Just noting here that this PR should not be merged before PR #17 is finished |
Bringing #53 up to par with previous rewrite branch commits before making feature changes.
First pass implementation of MAGIC scoring. Lots of old code needs to be updated and redundancies trimmed out. This is taking the basics of PR #17 and putting a weird new spin on them, so this will need testing and critique. See the design document for more deets.
Merging this PR in sync with `runner` to update upstream workflow to match. Otherwise, testing rescoring and network construction is using older functionality.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Export, feature rescoring, and recreating old amRml's results
This PR adds feature rescoring and recreates three outputs old amRml wrote that we did not:
exportMergedResults()writes our results in old amRml's merged format, which feature rescoring reads. This is a temporary solution, it goes once our column names match old amRml's or the feature rescoring and amRviz columns update.R/feature-rescoring.R, lifted from PR Add function for feature prioritization #17 with one bug fix (below).rescoreFeatures()runs it on a fit.speciescolumn inresults/, arun.jsonwith the run's settings, and saved model fits.Line references are to the original amRml. The feature rescoring code is from PR #17.
Export (
R/export.R)Feature rescoring reads old amRml's merged tables (
all_perf.parquet,all_top_features.parquet), whichmergeMLresults()built from per-model files. Currently we write one table per output instead, so the export rewrites our results in the merged format and feature rescoring runs unchanged. Once the open renames are done (unit/target/encoding,phenotype,labels), feature rescoring can readresults/directly and the export goes.runModelingWorkflow()callsexportMergedResults()(The temporary component) at the end of every run. It writes to<run>/merged/, one file per mode present, with old amRml's file names, columns and column order:vanillaall_perf.parquetall_top_features.parquetstratified_year,stratified_countryyear_perf.parquet,country_perf.parquetyear_top_features.parquet,country_top_features.parquetcross_drugcross_drug_perf.parquetcross_year,cross_countrycross_year_perf.parquet,cross_country_perf.parquetloto,logoLOO_year_perf.parquet,LOO_country_perf.parquetLOO_year_top_features.parquet,LOO_country_top_features.parquetdrug_label=unit,drug_or_class=target,feature_subtype=encoding,strat_value/drug=train_group,strat_value_test/leaveout_strat_value/test_drug=test_group,num_obs_test_data=n_test.shuffled, and every top-features file an integerseed.filename;train_prop,val_propand theprop_vibounds (they return with the three-way split and iterative feature elimination); ourtask_idandauprc.Problems I noticed in
mergeMLresults()that rewrite solves through the design:AMRFinder,COG,Pfam,DefenseCasorAMX-CLArows got NA metadata (R/merge_ml_results.R, lines 375, 407, 472)shuffled_files broke the stratified merge (lines 336-345) and were ignored by the cross and leave-one-out mergesshuffledis a column nowseedin every top-features fileFeature rescoring (
R/feature-rescoring.R,R/rescore.R)R/feature-rescoring.Ris PR #17's lines 1-387 and 702-1414, with one code change, a bug fix:models$summary)minimum_MCC_diffandmaximum_MCC_diffnamed, withNA_real_instead ofNULLbuildFeatureNetwork(),plotFeatureNetworkD3())topFeaturesPerDrugOrClass()andrunFeatureDyadDiscovery(), as in PR Add function for feature prioritization #17. Its other two exports are the network functions above.rescoreFeatures(fit, ...)checks that the fit has fitted vanilla models with real and shuffled labels, and that the ORB hasdyad_feature.parquet. It exports the merged files if they are missing, then runsrunFeatureDyadDiscovery(); its thresholds pass through.... It is a separate file for now so the feature rescoring code changes as little as possible while this PR shows the two connect; it will move intoR/feature-rescoring.Ronce feature rescoring reads our results directly.Recreating old amRml's results
R/merge_ml_results.R, lines 30-115)speciescolumn (the ORB'sdataset_id, e.g.Sfl) in everyresults/tableml_parameters.json: mode,n_fold, split, seed, timestamp (R/generate_matrices_ml.R, lines 1529-1545)run.json: the ORB and manifest, the modes, thresholds, seeds and labels asked for, versions, start and finish times, task counts.<name>_model_fit.rds, one per model, named by its matrix file,shuffled_prefix and seed (R/run_ML.R, lines 845-864)results/models/<task_id>.rds, one per fitted task, with the matrix's feature IDs. A task is one matrix x label kind x seed, so each fitted task is one model, the same unit old amRml savedrun.json, notml_parameters.json: old amRml read its file back as configuration (R/prep_ml.R, lines 20-45). Here its only a recordHow to use it
Verification
species, timings and dates. Every fit was saved, a saved fit reproduces its predictions, and the feature rescoring results are unchanged.Files
R/export.RexportMergedResults(), temporary stopgapR/feature-rescoring.RR/rescore.RrescoreFeatures(), will eventually go inR/feature-rescoring.RR/fit-models.Rspecies,save_fits,run.jsonR/tasks.RexpandTasks()keeps the seeds and labels asked forR/workflow.Rmerged/; passessave_fitsR/arg-checks.R,R/generate-matrices.Rmerged/andrun.jsonare protected outputsR/globals.R,DESCRIPTION,NAMESPACE,man/Future work