Created
November 1, 2023 21:50
-
-
Save chasemc/36a6873db24e0f5aa8f3b8037dce0f00 to your computer and use it in GitHub Desktop.
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
library(IDBacApp) | |
library(dplyr) | |
library(DBI) | |
library(pool) | |
library(coop) | |
# Change this to be the full file path to your sqlite file | |
sqlite_filepath <- "/home/chase/Downloads/NK_Library_Full_Up_To_2023-10-02-Copy.sqlite" | |
db_pool <- IDBacApp::idbac_connect(fileName = tools::file_path_sans_ext(basename(sqlite_filepath)), | |
filePath = dirname(sqlite_filepath))[[1]] | |
# Update the database to the latest version | |
idbac_update_db(pool = db_pool, copy_overwrite = "overwrite") | |
# Reconnect to the database | |
db_pool <- IDBacApp::idbac_connect(fileName = tools::file_path_sans_ext(basename(sqlite_filepath)), | |
filePath = dirname(sqlite_filepath))[[1]] | |
# Peak at the tables in the SQLite database | |
sapply(DBI::dbListTables(conn = db_pool), | |
function(x){ | |
print(dplyr::tbl(db_pool, x ) %>% head()) | |
}, simplify = F) | |
tbl(db_pool, "spectra") %>% filter(max_mass > 6000) %>% pull("strain_id") %>% unique -> sample_ids | |
# Enter your sample IDs here or comment/delete and then it will compare all samles in the DB using the sample_ids from the line above | |
#sample_ids <- c("A1", "MHB") | |
# Adjust the variables for mass cutoffs etc, below | |
temp <- lapply(sample_ids, | |
function(ids){ | |
IDBacApp::idbac_get_peaks(pool = db_pool, | |
sampleIDs = ids, | |
minFrequency = 0, | |
minNumber = NA, | |
lowerMassCutoff=3000, | |
upperMassCutoff = 15000, | |
minSNR = 3, | |
tolerance = 0.002, | |
type = "protein", | |
mergeReplicates = TRUE)[[1]] | |
}) | |
names(temp) <- c(sample_ids) | |
# Adjust the variables for mass cutoffs etc, below. It's complicated but ppm isn't a direct cutoff, it controls how the peaks are "fuzzified" | |
fuzzy_vec <- IDBacApp::createFuzzyVector( | |
massStart =3000, | |
massEnd = 15000, | |
ppm = 1000, | |
massList = lapply(temp, function(x) x@mass), | |
intensityList = lapply(temp, function(x) x@intensity) | |
) | |
# Print distance matrix between samples | |
write.csv(round(as.data.frame((1 - coop::cosine(fuzzy_vec))), 2), "results.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Created on 2023-11-01 with reprex v2.0.2
Session info