Skip to content

Commit

Permalink
handle case when no edge is above threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
Adafede committed Jan 23, 2025
1 parent d03e819 commit b8ab74c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
42 changes: 23 additions & 19 deletions R/create_edges.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,19 @@ create_edges <- function(frags,
.f = function(index) {
target_indices <- (index + 1):nspecs

scores <- vapply(
target_indices,
function(target) {
msentropy::calculate_entropy_similarity(
peaks_a = frags[[index]],
peaks_b = frags[[target]],
min_mz = 0,
max_mz = 5000,
noise_threshold = 0,
ms2_tolerance_in_da = ms2_tolerance,
ms2_tolerance_in_ppm = ppm_tolerance,
max_peak_num = -1,
clean_spectra = TRUE
)
},
numeric(1)
)
scores <- vapply(target_indices, function(target) {
msentropy::calculate_entropy_similarity(
peaks_a = frags[[index]],
peaks_b = frags[[target]],
min_mz = 0,
max_mz = 5000,
noise_threshold = 0,
ms2_tolerance_in_da = ms2_tolerance,
ms2_tolerance_in_ppm = ppm_tolerance,
max_peak_num = -1,
clean_spectra = TRUE
)
}, numeric(1))

valid_indices <- which(scores >= threshold)

Expand All @@ -56,6 +52,14 @@ create_edges <- function(frags,
}
}
)

tidytable::bind_rows(edges[!sapply(edges, is.null)])
edges <- edges[!sapply(edges, is.null)]
if (length(edges) > 0) {
tidytable::bind_rows(edges)
} else {
tidytable::tidytable(
feature_id = NA_integer_,
target_id = NA_integer_,
score = NA_real_
)
}
}
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@
"SystemRequirements": null
},
"keywords": ["metaboliteannotation", "chemotaxonomy", "scoringsystem", "naturalproducts", "computationalmetabolomics", "taxonomicdistance", "specializedmetabolome"],
"fileSize": "2389.028KB",
"fileSize": "2389.15KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand Down

0 comments on commit b8ab74c

Please sign in to comment.