Repository navigation
Add function for feature prioritization - #17
AbhirupaGhosh wants to merge 43 commits into
Conversation
This function computes feature improvement by reading and processing feature data from parquet files, applying various transformations and calculations to derive insights on feature importance and contributions.
Added computeFeatureScore function to calculate feature scores based on various metrics and cluster information.
…ion and introducing wide table functions for global score calculations
…update parameters for clarity
… feature and cluster analysis
|
This script introduces a workflow for prioritizing molecular features associated with resistance across drugs and drug classes. This workflow identifies features that are consistently important across repeated model fits (seeds), making the results less noisy and more interpretable. The workflow:
The run would be |
|
Minor suggestions for now or later:
@AbhirupaGhosh, can you clarify the following:
|
Standardize feature column names across the codebase (Variable -> variable, Importance -> importance, Sign -> sign) and update all uses (mutate, group_by, joins, transmute, distinct). Rename summariseFeatureAcrossSeeds -> summariseFeaturesAcrossSeeds, buildSignalNetwork -> buildFeatureNetwork, and plotSignalNetworkD3 -> plotFeatureNetworkD3. Adjust join keys (variable == feature), grouping and summarise calls, examples, and roxygen docs to match the new names. Includes minor formatting and whitespace cleanups. These changes unify naming and clarify the feature/cluster network API.
jananiravi
left a comment
There was a problem hiding this comment.
Added a few minor fixes inline + some comments for clarification.
All other scripts are named do_something. so 'prioritize_features' or 'rescore_features' or something like that?
Note from Slack
In summariseClusters() and buildFeatureNetwork(), when a top-ranked domain/COG feature gets joined to cluster_feature, it fans out into every cluster carrying that domain — including clusters with no real connection to the resistance signal, just shared domain architecture.
Concretely:
- A single promiscuous COG (fan-out up to 189) inflates frequency/n_variables/cluster_mean_rank_score for up to 189 different clusters in summariseClusters(), none of which may be the true driver.
- In buildFeatureNetwork(), feature_cluster_edges will make that one feature a hub node connected to up to ~189 cluster nodes, which will dominate/clutter plotFeatureNetworkD3()'s output and overstate specificity.
So, is this fan-out intentional (i.e., "show all plausible clusters a domain could implicate"), or should there be a cap/weighting (e.g., down-weight edges by 1/n_clusters, or exclude domains above some fan-out threshold) so ubiquitous COGs/Pfams don't swamp the network? This is a modeling decision, not a coding bug.
| protein_scale_realization <- ranked_features |> | ||
| dplyr::filter(!is.na(cluster), shuffled == FALSE) |> | ||
| top_clusters <- top_features |> | ||
| dplyr::left_join(cluster_feature, by = dplyr::join_by(Variable == feature)) |> |
There was a problem hiding this comment.
In dplyr::left_join(top_features, cluster_feature, by = dplyr::join_by(variable == :
Detected an unexpected many-to-many relationship between `x` and `y`.
ℹ Row 1 of `x` matches multiple rows in `y`.
ℹ Row 54683 of `y` matches multiple rows in `x`.
ℹ If a many-to-many relationship is expected, set `relationship = "many-to-many"` to silence this warning.
|
|
||
| cluster_table <- top_clusters |> | ||
| dplyr::mutate(model_id = make_model_id(drug_label, drug_or_class)) |> | ||
| dplyr::left_join( |
There was a problem hiding this comment.
In dplyr::left_join(feature_table, cluster_feature, by = dplyr::join_by(variable == :
Detected an unexpected many-to-many relationship between `x` and `y`.
ℹ Row 1 of `x` matches multiple rows in `y`.
ℹ Row 151601 of `y` matches multiple rows in `x`.
ℹ If a many-to-many relationship is expected, set `relationship = "many-to-many"` to silence this warning.
| dplyr::ungroup() |> | ||
| dplyr::group_by(drug_label, drug_or_class) |> | ||
| dplyr::filter( | ||
| # n_seeds == max(n_seeds), |
There was a problem hiding this comment.
intentionally left out? what's the consistency across seeds you're looking for?
There was a problem hiding this comment.
yes, I am using the threshold_sd_rank as a proxy for consistency.
max(n_seeds) is too stringent
…ng core membership checks
There was a problem hiding this comment.
Comments based on a quick pass of your recent changes alone. @AbhirupaGhosh @epbrenner
| #' @param all_top_features_parquet The path to the Parquet file containing all top features with their importance scores. | ||
| #' @param core_contribution_threshold The cumulative-contribution cutoff (default 0.75, i.e. 75%) used to flag whether a feature falls within the "core" set of features that jointly account for that share of a seed's total importance. | ||
| #' @param exclude_feature_types Feature types to drop before any scoring happens (default \code{"struct"}). struct variables are composite IDs (e.g. \code{polA.group_211.group_2176}, three dot-joined gene/domain identifiers) representing a co-occurrence/structural motif rather than a single molecular entity like the other five scales, and its candidate-variable count (tens of thousands per group) dwarfs the other scales by orders of magnitude — pooling it into this rank_score/contribution machinery would compare a compound signal against five primary ones on an incomparable scale. struct is reserved for post-hoc biological annotation once top clusters are identified, not for scoring/ranking/thresholding here. | ||
| #' @param filter_model Logical whether to filter the optimal model based on MCC and comparison to shuffled data (default is TRUE). If TRUE function will call \code{filterOptimalModel()} |
There was a problem hiding this comment.
MCC and comparison to shuffled? OR MCC compared to shuffled?
| #' @param all_performance_parquet The path to the all performance parquet file (required if \code{filter_model = TRUE}) | ||
| #' @param MCC_threshold The minimum MCC threshold for filtering the optimal model (default is NULL) | ||
| #' @param compare_to_shuffled Logical whether to compare the model to shuffled data (default is TRUE) |
There was a problem hiding this comment.
suggesting minor, inline language edits
| scoreFeaturesWithinSeed <- function(all_top_features_parquet, core_contribution_threshold = 0.75, exclude_feature_types = "struct") { | ||
|
|
||
| scoreFeaturesWithinSeed <- function(all_top_features_parquet, | ||
| core_contribution_threshold = 0.75, |
There was a problem hiding this comment.
core or cumulative? Or do these refer to the same thing? why 'core'?
|
|
||
| scoreFeaturesWithinSeed <- function(all_top_features_parquet, | ||
| core_contribution_threshold = 0.75, | ||
| exclude_feature_types = "struct", |
There was a problem hiding this comment.
multiple select allowed -- is that why it's types?
| #' @param exclude_feature_types Feature types to drop before any scoring happens (default \code{"struct"}). struct variables are composite IDs (e.g. \code{polA.group_211.group_2176}, three dot-joined gene/domain identifiers) representing a co-occurrence/structural motif rather than a single molecular entity like the other five scales, and its candidate-variable count (tens of thousands per group) dwarfs the other scales by orders of magnitude — pooling it into this rank_score/contribution machinery would compare a compound signal against five primary ones on an incomparable scale. struct is reserved for post-hoc biological annotation once top clusters are identified, not for scoring/ranking/thresholding here. | ||
| #' @param filter_model Logical whether to filter the optimal model based on MCC and comparison to shuffled data (default is TRUE). If TRUE function will call \code{filterOptimalModel()} | ||
| #' @param all_performance_parquet The path to the all performance parquet file (required if \code{filter_model = TRUE}) | ||
| #' @param MCC_threshold The minimum MCC threshold for filtering the optimal model (default is NULL) |
There was a problem hiding this comment.
absolute MCC threshold? this is not relative to corresponding shuffled one, right?
| if (filter_model) { | ||
| filtered_model <- filterOptimalModel( |
There was a problem hiding this comment.
make sure you're keeping track of
filter_model
filtered_model
filterOptimalModel (well, at least this one is a function!)
| # Since the models are elastic net and have mix of models from lasso to ridge | ||
| # lasso shrinks the feature space to fewer selected variables and | ||
| # ridge retains variables (keeps correlated variables together). | ||
| # calculate the selection score to give advantage to lasso model variables. |
There was a problem hiding this comment.
'give advantage to lasso model variables' -- can you please clarify the text/intent here?
| scored_top_features <- all_top_features |> | ||
| dplyr::select( | ||
| species, drug_label, drug_or_class, seed, | ||
| feature_type, feature_subtype, variable=Variable, |
There was a problem hiding this comment.
were we systematically renaming vague 'Variable's to something more telling?
| median_rank = median(rank, na.rm = TRUE), | ||
| median_contribution = median(contribution, na.rm = TRUE), | ||
| mean_rank_score = mean(rank_score, na.rm = TRUE), | ||
| median_cum_contrib = median(cum_contrib, na.rm = TRUE), |
There was a problem hiding this comment.
Maybe I understand the difference between cumulative and core (or maybe I don't). Cumulative is more intuitive. Check terminologies for consistency
consistency, language, and other roxygen2 documentation fixes -- please check alongside local runs to make sure `returns` promises what is actually returned to the user. regenerated devtools::document()
jananiravi
left a comment
There was a problem hiding this comment.
@AbhirupaGhosh @eboyer221 @epbrenner, my most recent commit mostly has documentation suggestions/fixes. I started fixing clarity around language & what's promised to the user and went down the documentation rabbit hole with Claude. I added some notes to our Slack canvas, too. This will definitely need to be checked again once the score/metric has actually been updated.
…b/amRml into feature_rescoring_simple
…f clusters. This involved changing the function names and updating the documentation accordingly. The changes also include updates to the NAMESPACE file to reflect the new function names and their exports.
…class instead of globally, so low-signal drugs aren't crowded out; update docs to match
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.


This function computes feature improvement by reading and processing feature data from parquet files, applying various transformations and calculations to derive insights on feature importance and contributions.
Description
What kind of change(s) are included?
Checklist
Please ensure that all boxes are checked before indicating that this pull request is ready for review.