Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
j2s
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
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
j2s
Commits
c76aa8f6
Commit
c76aa8f6
authored
5 years ago
by
Vincent LAVILLE
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
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
j2s.py
+60
-0
60 additions, 0 deletions
j2s.py
with
60 additions
and
0 deletions
j2s.py
0 → 100644
+
60
−
0
View file @
c76aa8f6
#!/usr/bin/env python3
import
math
import
numpy
as
np
import
pandas
as
pd
from
scipy.stats
import
chi2
import
sys
import
time
stt
=
time
.
time
()
# Checking number of arguments (4 expected)
if
len
(
sys
.
argv
)
!=
4
:
print
(
"
Incorrect call: wrong number of arguments
\n
"
)
sys
.
exit
(
1
)
infile
=
sys
.
argv
[
1
]
samplesize
=
int
(
sys
.
argv
[
2
])
Nexpo
=
int
(
sys
.
argv
[
3
])
outfile
=
sys
.
argv
[
4
]
print
(
"
Arguments passed:
"
)
print
(
"
\t
Sample size =
"
+
str
(
samplesize
))
print
(
"
\t
N exposed =
"
+
str
(
Nexpo
))
print
(
"
Output file =
"
+
outfile
+
"
\n
"
)
print
(
"
\n
"
)
meanE
=
Nexpo
/
samplesize
sdE
=
math
.
sqrt
(
meanE
*
(
1
-
meanE
))
df
=
pd
.
read_csv
(
infile
,
header
=
0
,
sep
=
"
\t
"
)
if
'
TotalSampleSize
'
in
list
(
df
)
:
df
=
df
.
rename
(
columns
=
{
'
TotalSampleSize
'
:
'
N
'
})
# Filtering out SNPs with low sample size compared to the sample size distribution
n_min
=
np
.
percentile
(
df
[
'
N
'
],
90
)
/
1.5
df
=
df
.
loc
[
df
[
'
N
'
]
>
n_min
,:]
df
[
'
propSample
'
]
=
df
[
'
N
'
]
/
samplesize
# Computation of summary statistics in the exposed, unexposed and total sample
df
[
'
Unexp_eff
'
]
=
df
[
'
Effect
'
]
df
[
'
Unexp_eff_sd
'
]
=
df
[
'
StdErr
'
]
df
[
'
Unexp_p
'
]
=
chi2
.
sf
((
df
[
'
Unexp_eff
'
]
/
df
[
'
Unexp_eff_sd
'
])
**
2
,
1
)
df
[
'
Unexp_N
'
]
=
np
.
floor
(
df
[
'
propSample
'
]
*
(
samplesize
-
Nexpo
))
df
[
'
Exp_eff
'
]
=
df
[
'
Effect
'
]
+
df
[
'
IntEffect
'
]
df
[
'
Exp_eff_sd
'
]
=
(
df
[
'
StdErr
'
]
**
2
+
df
[
'
IntStdErr
'
]
**
2
+
2
*
df
[
'
IntCov
'
])
**
0.5
df
[
'
Exp_p
'
]
=
chi2
.
sf
((
df
[
'
Exp_eff
'
]
/
df
[
'
Exp_eff_sd
'
])
**
2
,
1
)
df
[
'
Exp_N
'
]
=
np
.
floor
(
df
[
'
propSample
'
]
*
Nexpo
)
df
[
'
Marg_eff
'
]
=
df
[
'
Effect
'
]
+
df
[
'
IntEffect
'
]
*
meanE
df
[
'
Marg_eff_sd
'
]
=
(
df
[
'
StdErr
'
]
**
2
+
(
meanE
*
df
[
'
IntStdErr
'
])
**
2
+
2
*
meanE
*
df
[
'
IntCov
'
])
**
0.5
df
[
'
Marg_p
'
]
=
chi2
.
sf
((
df
[
'
Marg_eff
'
]
/
df
[
'
Marg_eff_sd
'
])
**
2
,
1
)
df
[
'
Marg_N
'
]
=
df
[
'
N
'
]
# Writing output file
df
.
loc
[:,[
'
rsID
'
,
'
Chr
'
,
'
BP
'
,
'
MarkerName
'
,
'
Allele1
'
,
'
Allele2
'
,
'
Freq1
'
,
'
Exp_eff
'
,
'
Exp_eff_sd
'
,
'
Exp_p
'
,
'
Exp_N
'
,
'
Unexp_eff
'
,
'
Unexp_eff_sd
'
,
'
Unexp_p
'
,
'
Unexp_N
'
,
'
Marg_eff
'
,
'
Marg_eff_sd
'
,
'
Marg_p
'
,
'
Marg_N
'
]].
to_csv
(
outfile
,
sep
=
'
\t
'
,
index
=
False
,
header
=
True
,
compression
=
'
gzip
'
)
print
(
"
Analysis finished
"
)
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