Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jass
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Value stream analytics
Contributor 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
Statistical-Genetics
jass
Commits
56313c79
Commit
56313c79
authored
3 months ago
by
Veronique Legrand
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'remotes/origin/vero_global_plot' into fixing_py312
parents
9295db10
15608902
No related branches found
No related tags found
1 merge request
!108
Fixing py 3.12
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
jass/models/plots.py
+16
-12
16 additions, 12 deletions
jass/models/plots.py
jass/test/expected_graphs/expected_global_plot.png
+0
-0
0 additions, 0 deletions
jass/test/expected_graphs/expected_global_plot.png
jass/test/test_plots.py
+14
-1
14 additions, 1 deletion
jass/test/test_plots.py
with
30 additions
and
13 deletions
jass/models/plots.py
+
16
−
12
View file @
56313c79
...
@@ -17,10 +17,10 @@ from matplotlib import colors
...
@@ -17,10 +17,10 @@ from matplotlib import colors
import
matplotlib.patches
as
mpatches
import
matplotlib.patches
as
mpatches
from
scipy.stats
import
norm
,
chi2
from
scipy.stats
import
norm
,
chi2
import
seaborn
as
sns
import
seaborn
as
sns
import
os
from
pandas
import
DataFrame
,
read_hdf
from
pandas
import
DataFrame
,
read_hdf
import
pandas
as
pd
import
pandas
as
pd
default_chunk_size
=
50
def
replaceZeroes
(
df
):
def
replaceZeroes
(
df
):
"""
"""
...
@@ -32,30 +32,34 @@ def replaceZeroes(df):
...
@@ -32,30 +32,34 @@ def replaceZeroes(df):
df
.
values
[
df
.
values
==
0
]
=
min_nonzero
df
.
values
[
df
.
values
==
0
]
=
min_nonzero
return
df
return
df
def
create_global_plot
(
work_file_path
:
str
,
global_plot_path
:
str
):
def
get_info_4_global_plot
(
work_file_path
:
str
):
regions
=
read_hdf
(
work_file_path
,
"
Regions
"
,
columns
=
[
'
Region
'
,
'
CHR
'
,
'
MiddlePosition
'
])
print
(
regions
.
dtypes
)
N_reg
=
regions
.
Region
.
max
()
# Keep biggest element in Region column
binf
=
regions
.
Region
.
iloc
[
0
]
chr_considered
=
regions
.
CHR
.
unique
()
length_chr
=
regions
.
groupby
(
"
CHR
"
).
MiddlePosition
.
max
()
/
10
**
6
length_chr
.
loc
[
0
]
=
0
return
N_reg
,
binf
,
chr_considered
,
length_chr
def
create_global_plot
(
work_file_path
:
str
,
global_plot_path
:
str
,
chunk_size
:
int
=
default_chunk_size
):
"""
"""
create_global_plot
create_global_plot
generate genome-wide manhattan plot for a given set of phenotypes
generate genome-wide manhattan plot for a given set of phenotypes
"""
"""
regions
=
read_hdf
(
work_file_path
,
"
Regions
"
)
N_reg
,
binf
,
chr_considered
,
length_chr
=
get_info_4_global_plot
(
work_file_path
)
chr_length
=
regions
.
groupby
(
'
CHR
'
).
max
().
position
N_reg
=
regions
.
Region
.
max
()
maxy
=
0
maxy
=
0
fig
=
plt
.
figure
(
figsize
=
(
30
,
12
))
fig
=
plt
.
figure
(
figsize
=
(
30
,
12
))
ax
=
fig
.
add_subplot
(
111
)
ax
=
fig
.
add_subplot
(
111
)
chunk_size
=
50
colors
=
[
colors
=
[
'
#4287f5
'
,
'
#4287f5
'
,
'
orangered
'
'
orangered
'
]
]
binf
=
regions
.
Region
.
iloc
[
0
]
bsup
=
binf
+
chunk_size
chr_considered
=
regions
.
CHR
.
unique
()
length_chr
=
regions
.
groupby
(
"
CHR
"
).
MiddlePosition
.
max
()
/
10
**
6
length_chr
.
loc
[
0
]
=
0
label
=
"
Chr
"
+
length_chr
.
loc
[
chr_considered
].
index
.
astype
(
"
str
"
)
label
=
"
Chr
"
+
length_chr
.
loc
[
chr_considered
].
index
.
astype
(
"
str
"
)
lab_pos
=
length_chr
.
loc
[
chr_considered
]
/
2
lab_pos
=
length_chr
.
loc
[
chr_considered
]
/
2
...
@@ -63,7 +67,7 @@ def create_global_plot(work_file_path: str, global_plot_path: str):
...
@@ -63,7 +67,7 @@ def create_global_plot(work_file_path: str, global_plot_path: str):
pos_shift
.
index
=
pos_shift
.
index
+
1
pos_shift
.
index
=
pos_shift
.
index
+
1
pos_shift
.
loc
[
chr_considered
[
0
]]
=
0
pos_shift
.
loc
[
chr_considered
[
0
]]
=
0
lab_pos
=
lab_pos
+
[
pos_shift
.
loc
[
i
]
for
i
in
chr_considered
]
lab_pos
=
lab_pos
+
[
pos_shift
.
loc
[
i
]
for
i
in
chr_considered
]
bsup
=
binf
+
chunk_size
while
binf
<
N_reg
:
while
binf
<
N_reg
:
df
=
read_hdf
(
work_file_path
,
"
SumStatTab
"
,
columns
=
[
"
CHR
"
,
"
position
"
,
'
JASS_PVAL
'
,
"
Region
"
],
where
=
"
Region >= {0} and Region < {1}
"
.
format
(
binf
,
bsup
))
df
=
read_hdf
(
work_file_path
,
"
SumStatTab
"
,
columns
=
[
"
CHR
"
,
"
position
"
,
'
JASS_PVAL
'
,
"
Region
"
],
where
=
"
Region >= {0} and Region < {1}
"
.
format
(
binf
,
bsup
))
binf
+=
chunk_size
binf
+=
chunk_size
...
...
This diff is collapsed.
Click to expand it.
jass/test/expected_graphs/expected_global_plot.png
0 → 100644
+
0
−
0
View file @
56313c79
321 KiB
This diff is collapsed.
Click to expand it.
jass/test/test_plots.py
+
14
−
1
View file @
56313c79
...
@@ -3,8 +3,10 @@
...
@@ -3,8 +3,10 @@
from
__future__
import
absolute_import
from
__future__
import
absolute_import
import
os
,
shutil
,
tempfile
import
os
,
shutil
,
tempfile
from
pathlib
import
Path
from
pathlib
import
Path
import
matplotlib
as
plt
from
jass.models
import
plots
from
jass.models
import
plots
from
PIL
import
Image
import
numpy
as
np
from
.
import
JassTestCase
from
.
import
JassTestCase
...
@@ -12,10 +14,13 @@ from . import JassTestCase
...
@@ -12,10 +14,13 @@ from . import JassTestCase
class
TestPlots
(
JassTestCase
):
class
TestPlots
(
JassTestCase
):
test_folder
=
"
data_real
"
test_folder
=
"
data_real
"
expected_res_folder
=
"
expected_graphs
"
#expected_res_folder="baseline_images/test_plot"
def
setUp
(
self
):
def
setUp
(
self
):
# Create a temporary directory
# Create a temporary directory
self
.
test_dir
=
Path
(
tempfile
.
mkdtemp
())
self
.
test_dir
=
Path
(
tempfile
.
mkdtemp
())
self
.
ref_res_dir
=
Path
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
self
.
expected_res_folder
))
self
.
worktable_hdf_path
=
self
.
get_file_path_fn
(
"
worktable-withnans.hdf5
"
)
self
.
worktable_hdf_path
=
self
.
get_file_path_fn
(
"
worktable-withnans.hdf5
"
)
def
tearDown
(
self
):
def
tearDown
(
self
):
...
@@ -24,7 +29,15 @@ class TestPlots(JassTestCase):
...
@@ -24,7 +29,15 @@ class TestPlots(JassTestCase):
pass
pass
def
test_create_global_plot
(
self
):
def
test_create_global_plot
(
self
):
#import shutil
#print(plt.rcParams)
plots
.
create_global_plot
(
self
.
worktable_hdf_path
,
self
.
test_dir
/
"
global_plot.png
"
)
plots
.
create_global_plot
(
self
.
worktable_hdf_path
,
self
.
test_dir
/
"
global_plot.png
"
)
img_new
=
Image
.
open
(
self
.
test_dir
/
"
global_plot.png
"
)
img_ref
=
Image
.
open
(
self
.
ref_res_dir
/
"
expected_global_plot.png
"
)
sum_sq_diff
=
np
.
sum
((
np
.
asarray
(
img_new
).
astype
(
'
float
'
)
-
np
.
asarray
(
img_ref
).
astype
(
'
float
'
))
**
2
)
print
(
"
sum_sq_diff=
"
,
sum_sq_diff
)
assert
(
sum_sq_diff
==
0.0
)
def
test_create_qq_plot
(
self
):
def
test_create_qq_plot
(
self
):
plots
.
create_qq_plot
(
self
.
worktable_hdf_path
,
self
.
test_dir
/
"
qq_plot.png
"
)
plots
.
create_qq_plot
(
self
.
worktable_hdf_path
,
self
.
test_dir
/
"
qq_plot.png
"
)
...
...
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