Skip to content

Commit

Permalink
Merge pull request #47 from aberHRML/devel
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
jasenfinch committed Nov 13, 2023
2 parents 88537c0 + 3b02dae commit 2e386a4
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: assignments
Title: Molecular Formula Assignment For High Resolution ESI-MS Based Metabolomics Data
Version: 1.0.0
Version: 1.0.1
Authors@R: person("Jasen", "Finch", email = "jsf9@aber.ac.uk", role = c("aut", "cre"))
Description: A molecular formula assignment approach for electrospray ionisation high resolution mass spectrometry based metabolomics data.
Depends: R (>= 3.5.0),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
importFrom(dplyr,group_split)
importFrom(dplyr,inner_join)
importFrom(dplyr,join_by)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,mutate_at)
Expand Down
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# assignments 1.0.1

* The default ppm threshold has been reduced to 4.

* The importance of the ^37^Cl adduct has been increased in the default negative mode adducts.

* The ^13^C2 isotope has been removed from the default isotopes.

* The default retention time difference limit for relationships has been changed to 2 seconds for RP-LC-HRMS and NP-LC-HRMS.

* The absolute values of correlation coefficients are now used to calculate average component weights.

* Where components contain a feature represented by more than one adduct and isotope combination, only the node with the highest AIS is now retained.

# assignments 1.0.0

* Added a `NEWS.md` file to track changes to the package.
Expand Down
52 changes: 43 additions & 9 deletions R/components.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ clean <- function(graph,adduct_rules_table){
cleaned_graph <- cleaned_graph %>%
bind_graphs()
}

return(cleaned_graph)
}

Expand All @@ -60,14 +60,14 @@ nComponents <- function(graph){

componentMetrics <- function(component,max_add_iso_total){
component %>%
mutate(Size = graph_size(),
Nodes = n(),
Degree = avg_degree(Nodes,Size),
Density = (2 * Size) / (Nodes * (Nodes - 1)),
Weight = sum(Weight) / Nodes,
AIS = sum(AIS) / max_add_iso_total,
`Component Plausibility` = plausibility(Degree,AIS,Weight)
)
mutate(Size = graph_size(),
Nodes = n(),
Degree = avg_degree(Nodes,Size),
Density = (2 * Size) / (Nodes * (Nodes - 1)),
Weight = sum(Weight) / Nodes,
AIS = sum(AIS) / max_add_iso_total,
`Component Plausibility` = plausibility(Degree,AIS,Weight)
)
}

componentFilters <- function(){
Expand All @@ -77,6 +77,38 @@ componentFilters <- function(){
Direction = c(rep('max',2),'min'))
}

#' @importFrom dplyr join_by

deduplicate <- function(graph){
dedup_nodes <- graph %>%
activate(nodes) %>%
as_tibble() %>%
group_split(
Component,
Feature
) %>%
future_map_dfr(
~.x %>%
arrange(
desc(
AIS
)
) %>%
slice(1)
)

graph %>%
activate(nodes) %>%
inner_join(
dedup_nodes,
by = join_by(
name, Feature, RetentionTime,
Isotope, Adduct, MF, `Theoretical M`, `Measured M`,
`Theoretical m/z`, `Measured m/z`, `PPM error`,
`MF Plausibility (%)`, AIS, ID, Component)
)
}

#' @importFrom tidygraph as_tbl_graph activate morph unmorph graph_size group_components tbl_graph
#' @importFrom magrittr set_names

Expand All @@ -88,6 +120,7 @@ calcComponents <- function(graph_nodes,
activate(nodes) %>%
left_join(graph_nodes,by = c('name' = 'Name')) %>%
mutate(Component = group_components()) %>%
deduplicate() %>%
clean(adductRules(assignment))

if (nComponents(graph) > 0){
Expand All @@ -102,6 +135,7 @@ calcComponents <- function(graph_nodes,
filter(Component == .x) %>%
edges() %>%
.$coefficient %>%
abs() %>%
mean() %>%
tibble(Weight = .)
},graph = graph) %>%
Expand Down
16 changes: 8 additions & 8 deletions R/parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ setClass('AssignmentParameters',
maxCor = Inf),
max_M = 800,
MF_rank_threshold = 3,
ppm = 6,
ppm = 4,
limit = 0.001,
RT_diff_limit = numeric(),
isotopes = c('13C','18O','13C2'),
adducts = list(n = c("[M-H]1-", "[M+Cl]1-", "[M+K-2H]1-",
"[M-2H]2-", "[M+Cl37]1-","[2M-H]1-"),
isotopes = c('13C','18O'),
adducts = list(n = c("[M-H]1-", "[M+Cl]1-", "[M+Cl37]1-", "[M+K-2H]1-",
"[M-2H]2-", "[2M-H]1-"),
p = c('[M+H]1+','[M+K]1+','[M+Na]1+','[M+K41]1+',
'[M+2H]2+','[2M+H]1+')),
transformations = transformation_rules()$`MF Change`,
Expand Down Expand Up @@ -548,12 +548,12 @@ assignmentParameters <- function(technique = availableTechniques()){
`FIE-HRMS` = new('AssignmentParameters'),
`RP-LC-HRMS` = new('AssignmentParameters',
technique = 'RP-LC-HRMS',
RT_diff_limit = 1/60),
RT_diff_limit = 2/60),
`NP-LC-HRMS` = new('AssignmentParameters',
technique = 'NP-LC-HRMS',
RT_diff_limit = 1/60,
adducts = list(n = c("[M-H]1-", "[M+Cl]1-", "[M+K-2H]1-",
"[M-2H]2-", "[M+Cl37]1-","[2M-H]1-"),
RT_diff_limit = 2/60,
adducts = list(n = c("[M-H]1-", "[M+Cl]1-", "[M+Cl37]1-", "[M+K-2H]1-",
"[M-2H]2-","[2M-H]1-"),
p = c('[M+H]1+','[M+K]1+','[M+Na]1+','[M+K41]1+',
'[M+NH4]1+','[M+2H]2+','[2M+H]1+'))))

Expand Down

0 comments on commit 2e386a4

Please sign in to comment.