@@ -48,7 +48,7 @@ clean <- function(graph,adduct_rules_table){
4848 cleaned_graph <- cleaned_graph %> %
4949 bind_graphs()
5050 }
51-
51+
5252 return (cleaned_graph )
5353}
5454
@@ -60,14 +60,14 @@ nComponents <- function(graph){
6060
6161componentMetrics <- function (component ,max_add_iso_total ){
6262 component %> %
63- mutate(Size = graph_size(),
64- Nodes = n(),
65- Degree = avg_degree(Nodes ,Size ),
66- Density = (2 * Size ) / (Nodes * (Nodes - 1 )),
67- Weight = sum(Weight ) / Nodes ,
68- AIS = sum(AIS ) / max_add_iso_total ,
69- `Component Plausibility` = plausibility(Degree ,AIS ,Weight )
70- )
63+ mutate(Size = graph_size(),
64+ Nodes = n(),
65+ Degree = avg_degree(Nodes ,Size ),
66+ Density = (2 * Size ) / (Nodes * (Nodes - 1 )),
67+ Weight = sum(Weight ) / Nodes ,
68+ AIS = sum(AIS ) / max_add_iso_total ,
69+ `Component Plausibility` = plausibility(Degree ,AIS ,Weight )
70+ )
7171}
7272
7373componentFilters <- function (){
@@ -77,6 +77,38 @@ componentFilters <- function(){
7777 Direction = c(rep(' max' ,2 ),' min' ))
7878}
7979
80+ # ' @importFrom dplyr join_by
81+
82+ deduplicate <- function (graph ){
83+ dedup_nodes <- graph %> %
84+ activate(nodes ) %> %
85+ as_tibble() %> %
86+ group_split(
87+ Component ,
88+ Feature
89+ ) %> %
90+ future_map_dfr(
91+ ~ .x %> %
92+ arrange(
93+ desc(
94+ AIS
95+ )
96+ ) %> %
97+ slice(1 )
98+ )
99+
100+ graph %> %
101+ activate(nodes ) %> %
102+ inner_join(
103+ dedup_nodes ,
104+ by = join_by(
105+ name , Feature , RetentionTime ,
106+ Isotope , Adduct , MF , `Theoretical M` , `Measured M` ,
107+ `Theoretical m/z` , `Measured m/z` , `PPM error` ,
108+ `MF Plausibility (%)` , AIS , ID , Component )
109+ )
110+ }
111+
80112# ' @importFrom tidygraph as_tbl_graph activate morph unmorph graph_size group_components tbl_graph
81113# ' @importFrom magrittr set_names
82114
@@ -88,6 +120,7 @@ calcComponents <- function(graph_nodes,
88120 activate(nodes ) %> %
89121 left_join(graph_nodes ,by = c(' name' = ' Name' )) %> %
90122 mutate(Component = group_components()) %> %
123+ deduplicate() %> %
91124 clean(adductRules(assignment ))
92125
93126 if (nComponents(graph ) > 0 ){
@@ -102,6 +135,7 @@ calcComponents <- function(graph_nodes,
102135 filter(Component == .x ) %> %
103136 edges() %> %
104137 . $ coefficient %> %
138+ abs() %> %
105139 mean() %> %
106140 tibble(Weight = . )
107141 },graph = graph ) %> %
0 commit comments