Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libhts
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Blaise LI
libhts
Commits
ede0ff41
Commit
ede0ff41
authored
7 years ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
Moved stuff to libhts.
parent
460fe53f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libhts/__init__.py
+1
-1
1 addition, 1 deletion
libhts/__init__.py
libhts/libhts.py
+28
-0
28 additions, 0 deletions
libhts/libhts.py
with
29 additions
and
1 deletion
libhts/__init__.py
+
1
−
1
View file @
ede0ff41
from
.libhts
import
do_deseq2
from
.libhts
import
do_deseq2
,
median_ratio_to_pseudo_ref_size_factors
,
set_de_status
This diff is collapsed.
Click to expand it.
libhts/libhts.py
+
28
−
0
View file @
ede0ff41
import
pandas
as
pd
# To compute geometric mean
from
scipy.stats.mstats
import
gmean
from
rpy2.robjects
import
r
,
pandas2ri
,
Formula
,
StrVector
as_df
=
r
(
"
as.data.frame
"
)
from
rpy2.robjects.packages
import
importr
...
...
@@ -38,3 +40,29 @@ def do_deseq2(cond_names, conditions, counts_data,
res
.
index
=
counts_data
.
index
return
res
def
median_ratio_to_pseudo_ref_size_factors
(
counts_data
):
"""
Adapted from DESeq paper (doi:10.1186/gb-2010-11-10-r106)
"""
# Add pseudo-count to compute the geometric mean, then remove it
#pseudo_ref = (counts_data + 1).apply(gmean, axis=1) - 1
# Ignore lines with zeroes instead:
pseudo_ref
=
(
counts_data
[
counts_data
.
prod
(
axis
=
1
)
>
0
]).
apply
(
gmean
,
axis
=
1
)
def
median_ratio_to_pseudo_ref
(
col
):
return
(
col
/
pseudo_ref
).
median
()
#size_factors = counts_data.apply(median_ratio_to_pseudo_ref, axis=0)
return
counts_data
[
counts_data
.
prod
(
axis
=
1
)
>
0
].
apply
(
median_ratio_to_pseudo_ref
,
axis
=
0
)
def
set_de_status
(
row
):
"""
Determines the up- or down-regulation status corresponding to a given
row of a deseq2 results table.
"""
if
row
[
"
padj
"
]
<
0.05
:
#if row["log2FoldChange"] > 0:
if
row
[
"
lfcMLE
"
]
>
0
:
return
"
up
"
else
:
return
"
down
"
else
:
return
"
NS
"
This diff is collapsed.
Click to expand it.
Preview
0%
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