Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LC-MS-RT-prediction
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Léo Schneider
LC-MS-RT-prediction
Commits
6230382b
Commit
6230382b
authored
6 months ago
by
Schneider Leo
Browse files
Options
Downloads
Patches
Plain Diff
local integration working
parent
6c178905
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
local_integration_msms.py
+51
-12
51 additions, 12 deletions
local_integration_msms.py
with
51 additions
and
12 deletions
local_integration_msms.py
+
51
−
12
View file @
6230382b
...
@@ -27,23 +27,28 @@ def get_df(expe, long: bool = False):
...
@@ -27,23 +27,28 @@ def get_df(expe, long: bool = False):
"""
"""
cols
=
[
"
RT
"
,
"
mzarray
"
,
"
intarray
"
,
'
MSlevel
'
,
'
MS1
MZ
'
]
cols
=
[
"
RT
"
,
"
mzarray
"
,
"
intarray
"
,
'
MSlevel
'
,
'
MS1
_mz_min
'
,
'
MS1_mz_max
'
]
df
=
pd
.
DataFrame
(
data
=
((
spec
.
getRT
(),
*
spec
.
get_peaks
(),
spec
.
getMSLevel
(),
spec
.
getPrecursors
()[
0
].
getMZ
()
if
spec
.
getMSLevel
()
==
2
else
None
)
for
spec
in
expe
),
columns
=
cols
)
df
=
pd
.
DataFrame
(
data
=
((
spec
.
getRT
(),
*
spec
.
get_peaks
(),
spec
.
getMSLevel
(),
spec
.
getPrecursors
()[
0
].
getMZ
()
-
spec
.
getPrecursors
()[
0
].
getIsolationWindowLowerOffset
()
if
spec
.
getMSLevel
()
==
2
else
None
,
spec
.
getPrecursors
()[
0
].
getMZ
()
+
spec
.
getPrecursors
()[
0
].
getIsolationWindowUpperOffset
()
if
spec
.
getMSLevel
()
==
2
else
None
)
for
spec
in
expe
),
columns
=
cols
)
if
long
:
if
long
:
RT
=
[]
RT
=
[]
mz
=
[]
mz
=
[]
inty
=
[]
inty
=
[]
ms_lv
=
[]
ms_lv
=
[]
ms1_mz
=
[]
ms1_mz_min
=
[]
ms1_mz_max
=
[]
for
index
,
row
in
df
.
iterrows
():
for
index
,
row
in
df
.
iterrows
():
mz
.
extend
(
row
[
'
mzarray
'
])
mz
.
extend
(
row
[
'
mzarray
'
])
inty
.
extend
(
row
[
'
intarray
'
])
inty
.
extend
(
row
[
'
intarray
'
])
RT
.
extend
([
row
[
'
RT
'
]]
*
len
(
row
[
'
intarray
'
]))
RT
.
extend
([
row
[
'
RT
'
]]
*
len
(
row
[
'
intarray
'
]))
ms_lv
.
extend
([
row
[
'
MSlevel
'
]]
*
len
(
row
[
'
intarray
'
]))
ms_lv
.
extend
([
row
[
'
MSlevel
'
]]
*
len
(
row
[
'
intarray
'
]))
ms1_mz
.
extend
([
row
[
'
MS1 MZ
'
]]
*
len
(
row
[
'
intarray
'
]))
ms1_mz_min
.
extend
([
row
[
'
MS1_mz_min
'
]]
*
len
(
row
[
'
intarray
'
]))
dico
=
{
"
RT
"
:
RT
,
"
mz
"
:
mz
,
"
inty
"
:
inty
,
"
MSlevel
"
:
ms_lv
,
"
MS1 MZ
"
:
ms1_mz
}
ms1_mz_max
.
extend
([
row
[
'
MS1_mz_max
'
]]
*
len
(
row
[
'
intarray
'
]))
dico
=
{
"
RT
"
:
RT
,
"
mz
"
:
mz
,
"
inty
"
:
inty
,
"
MSlevel
"
:
ms_lv
,
"
MS1_mz_min
"
:
ms1_mz_min
,
"
MS1_mz_max
"
:
ms1_mz_max
}
return
pd
.
DataFrame
(
dico
)
return
pd
.
DataFrame
(
dico
)
else
:
else
:
...
@@ -71,13 +76,21 @@ def generate_RT_int_imgs(exp,star_mz,stop_mz):
...
@@ -71,13 +76,21 @@ def generate_RT_int_imgs(exp,star_mz,stop_mz):
plt
.
savefig
(
'
fig/rt_local/{}_to_{}.png
'
.
format
(
mz_range
[
i
]
,
mz_range
[
i
+
1
]))
plt
.
savefig
(
'
fig/rt_local/{}_to_{}.png
'
.
format
(
mz_range
[
i
]
,
mz_range
[
i
+
1
]))
plt
.
clf
()
plt
.
clf
()
def
integrate_ms_ms
(
time_start
,
time_end
,
df
):
def
integrate_ms_ms
(
df
,
mz_bin
,
output
=
'
temp.png
'
,
display
=
False
):
df_useful
=
df
[(
df
[
'
MS1 RT
'
]
>
time_start
)
&
(
df
[
'
MS1 RT
'
]
<
time_end
)
&
(
df
[
'
MSlevel
'
]
==
2
)].
reset_index
(
inplace
=
True
)
# df_useful = df[(df['MS1 RT']>time_start) & (df['MS1 RT']<time_end) & (df['MSlevel']==2)].reset_index(inplace=True)
min_mz
,
max_mz
=
min
(
df
[
'
mz
'
]),
max
(
df
[
'
mz
'
])
value
=
0
mz_list
=
np
.
linspace
(
min_mz
,
max_mz
,
num
=
int
((
max_mz
-
min_mz
)
//
mz_bin
)
+
1
)
int_list
=
np
.
zeros
(
int
((
max_mz
-
min_mz
)
//
mz_bin
)
+
1
)
for
index
,
row
in
df
.
iterrows
():
return
value
int_list
[
int
((
row
[
'
mz
'
]
-
min_mz
)
//
mz_bin
)]
+=
row
[
'
inty
'
]
if
display
:
plt
.
clf
()
fig
,
ax
=
plt
.
subplots
()
ax
.
plot
(
mz_list
,
int_list
,
linewidth
=
0.1
)
ax
.
set_xlim
(
200
,
1800
)
plt
.
savefig
(
output
)
plt
.
clf
()
return
mz_list
,
int_list
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
e
=
oms
.
MSExperiment
()
e
=
oms
.
MSExperiment
()
...
@@ -97,4 +110,30 @@ if __name__ == "__main__":
...
@@ -97,4 +110,30 @@ if __name__ == "__main__":
ax
.
plot
(
mz_sorted
,
inty_sorted
)
ax
.
plot
(
mz_sorted
,
inty_sorted
)
plt
.
savefig
(
'
temp.png
'
)
plt
.
savefig
(
'
temp.png
'
)
#pic d'étude 462-468
#mz 750.13
df_peak
=
df
[
df
[
'
MSlevel
'
]
==
2
]
df_peak
=
df_peak
[
750.1
<
df_peak
[
'
MS1_mz_max
'
]]
df_peak
=
df_peak
[
750.1
>
df_peak
[
'
MS1_mz_min
'
]]
df_peak
=
df_peak
[
465
<
df_peak
[
'
RT
'
]]
df_peak
=
df_peak
[
466
>
df_peak
[
'
RT
'
]]
df_peak2
=
df
[
df
[
'
MSlevel
'
]
==
2
]
df_peak2
=
df_peak2
[
750.1
<
df_peak2
[
'
MS1_mz_max
'
]]
df_peak2
=
df_peak2
[
750.1
>
df_peak2
[
'
MS1_mz_min
'
]]
df_peak2
=
df_peak2
[
463
<
df_peak2
[
'
RT
'
]]
df_peak2
=
df_peak2
[
467
>
df_peak2
[
'
RT
'
]]
mz1
,
inty1
=
integrate_ms_ms
(
df_peak
,
1
)
mz2
,
inty2
=
integrate_ms_ms
(
df_peak2
,
1
)
plt
.
clf
()
fig
,
ax
=
plt
.
subplots
()
ax
.
plot
(
mz1
,
inty1
,
linewidth
=
0.3
)
ax
.
plot
(
mz2
,
inty2
,
linewidth
=
0.3
)
ax
.
set_xlim
(
200
,
1800
)
plt
.
savefig
(
'
spec_combined.png
'
)
plt
.
clf
()
#358.1 358.32
#358.1 358.32
\ No newline at end of file
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