Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
shinyscreen
Manage
Activity
Members
Labels
Plan
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Environmental Cheminformatics
shinyscreen
Commits
f99bf3ec
Commit
f99bf3ec
authored
2 years ago
by
Todor Kondić
Browse files
Options
Downloads
Patches
Plain Diff
extract_spectra: Extract full MS2 spectra.
parent
8d829d08
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
R/api.R
+8
-10
8 additions, 10 deletions
R/api.R
R/data-model.R
+10
-0
10 additions, 0 deletions
R/data-model.R
R/extraction.R
+29
-0
29 additions, 0 deletions
R/extraction.R
with
47 additions
and
10 deletions
R/api.R
+
8
−
10
View file @
f99bf3ec
...
...
@@ -374,24 +374,22 @@ extr_data <-function(m) {
idx
=
integer
(
0
),
rt
=
numeric
(
0
),
intensity
=
numeric
(
0
))
spectra
=
empty_spectra_table
()
for
(
fn
in
names
(
lfdata
))
{
## x = lfdata[[fn]]$ms2[cgram_ms1,
## .(an,
## ce,
## precid=i.precid,
## rt,
## intensity),
## on=c(prec_idx="idx"),
## nomatch=NULL,
## allow.cartesian=T]
rtab
=
relate_ms2_to_precid
(
coarse
=
coarse
,
ms2
=
lfdata
[[
fn
]]
$
ms2
,
cgram_ms1
=
cgram_ms1
)
sptab
=
extract_spectra
(
lms
[[
fn
]],
rtab
)
cgram_ms2
=
rbind
(
cgram_ms2
,
rtab
)
spectra
=
rbind
(
spectra
,
sptab
)
}
setkey
(
cgram_ms1
,
precid
,
rt
)
setkey
(
cgram_ms2
,
precid
,
ce
,
rt
)
setkey
(
spectra
,
precid
,
scan
)
m
$
db
$
extr
$
cgm
$
ms1
=
cgram_ms1
m
$
db
$
extr
$
cgm
$
ms2
=
cgram_ms2
browser
()
m
$
db
$
extr
$
spectra
=
spectra
m
}
...
...
This diff is collapsed.
Click to expand it.
R/data-model.R
+
10
−
0
View file @
f99bf3ec
...
...
@@ -103,3 +103,13 @@ make_db_precursors <- function(m) {
m
$
db
$
precursors
=
masses
m
}
empty_spectra_table
<-
function
()
{
r
=
data.table
(
precid
=
integer
(
0
),
scan
=
character
(
0
),
mz
=
numeric
(
0
),
intensity
=
numeric
(
0
))
setkey
(
r
,
precid
,
scan
)
r
}
This diff is collapsed.
Click to expand it.
R/extraction.R
+
29
−
0
View file @
f99bf3ec
...
...
@@ -700,8 +700,19 @@ get_fdata <- function(ms) {
relate_ms2_to_precid
<-
function
(
coarse
,
ms2
,
cgram_ms1
)
{
## Take `coarse' table (the one with coarse mass limits), ms2
## fData and ms1 chromatogram, then relate precids from cgram_ms1
## to ms2 data.
## Select those MS2 entries the parents of which coarsely match
## compound lists masses.
res
=
ms2
[
coarse
,
on
=
.
(
prec_mz
>
iso_coarse_min
,
prec_mz
<
iso_coarse_max
),
.
(
prec_mz
=
x.prec_mz
,
precid
,
prec_idx
,
scan
,
idx
,
ce
,
rt
,
intensity
),
nomatch
=
NULL
]
setkey
(
res
,
precid
,
prec_idx
)
## Now, make sure those coarsely matched MS2 actually have a
## parent that finely matches something in the chromatogram (and
## this is by ensuring that a `precid' with the correct scan (idx)
## shows up in the chromatogram.
cgram_ms1
[
res
,
on
=
.
(
precid
,
idx
==
prec_idx
),
.
(
precid
,
ce
,
scan
=
i.scan
,
idx
=
i.idx
,
rt
=
i.rt
,
...
...
@@ -709,3 +720,21 @@ relate_ms2_to_precid <- function(coarse,ms2,cgram_ms1) {
}
extract_spectra
<-
function
(
ms
,
cgram_ms2
)
{
## This will extract full MS2 spectra based on ms2 chromatogram entries.
indices
=
cgram_ms2
[,
.SD
,
.SDcol
=
c
(
"precid"
,
"scan"
,
"idx"
)]
res
=
empty_spectra_table
()
selind
=
indices
[,
unique
(
.SD
),
.SDcol
=
c
(
"scan"
,
"idx"
)]
sel
=
ms
[
selind
$
idx
]
masses
=
mz
(
sel
)
intensities
=
intensity
(
sel
)
res
=
selind
setkey
(
res
,
scan
)
res
=
res
[,
data.table
(
mz
=
masses
[[
scan
]],
intensity
=
intensities
[[
scan
]]),
keyby
=
c
(
"scan"
)]
res
[
indices
,
on
=
.
(
scan
),
precid
:=
i.precid
]
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment