Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cami
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chow Castro, Marcos
cami
Commits
277c98ff
Commit
277c98ff
authored
2 years ago
by
bay9355
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of
https://gitlab.rrz.uni-hamburg.de/bay2046/cami
parents
dca69284
18ad0877
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cami_src/cami_suite.py
+41
-40
41 additions, 40 deletions
cami_src/cami_suite.py
with
41 additions
and
40 deletions
cami_src/cami_suite.py
+
41
−
40
View file @
277c98ff
...
@@ -181,9 +181,9 @@ class cami():
...
@@ -181,9 +181,9 @@ class cami():
:rtype: set()
:rtype: set()
"""
"""
tool
.
create_tmp_output_dir
(
self
.
tmp_dir
)
# creates the temporary input directory
tool
.
create_tmp_output_dir
(
self
.
tmp_dir
)
# creates the temporary input directory
print
(
f
"
preparing
{
tool
.
name
}
input...
"
)
if
self
.
debug
:
print
(
f
"
preparing
{
tool
.
name
}
input...
"
)
inputparams
=
tool
.
prepare_input
()
inputparams
=
tool
.
prepare_input
()
print
(
f
'
running
{
tool
.
name
}
...
'
)
if
self
.
debug
:
print
(
f
'
running
{
tool
.
name
}
...
'
)
preds
=
set
(
tool
.
run_algorithm
(
inputparams
))
preds
=
set
(
tool
.
run_algorithm
(
inputparams
))
if
self
.
debug
:
if
self
.
debug
:
print
(
f
'
{
tool
.
name
}
predicted
{
len
(
preds
)
}
active vertices (seeds not excluded):
'
)
print
(
f
'
{
tool
.
name
}
predicted
{
len
(
preds
)
}
active vertices (seeds not excluded):
'
)
...
@@ -225,6 +225,7 @@ class cami():
...
@@ -225,6 +225,7 @@ class cami():
to the corresponding tool
to the corresponding tool
:rtype: dict(AlgorithmWrapper():set(Graph.vertex()))
:rtype: dict(AlgorithmWrapper():set(Graph.vertex()))
"""
"""
if
self
.
debug
:
print
(
f
'
Creating result sets of all
{
self
.
nof_tools
}
tools...
'
)
print
(
f
'
Creating result sets of all
{
self
.
nof_tools
}
tools...
'
)
pred_sets
=
{
tool
:
None
for
tool
in
self
.
tool_wrappers
}
pred_sets
=
{
tool
:
None
for
tool
in
self
.
tool_wrappers
}
...
@@ -338,10 +339,16 @@ class cami():
...
@@ -338,10 +339,16 @@ class cami():
}},
}},
}
}
# transform all vertex indices to their corresponding gene names in a result set
for
tool
in
result_sets
:
self
.
result_gene_sets
[
tool
.
name
]
=
set
([
gene_name_map
[
vertex
]
for
vertex
in
result_sets
[
tool
]])
# create integer codes for cami_versions (needed for predicted_by vertex property)
# create integer codes for cami_versions (needed for predicted_by vertex property)
recursion_limit
=
sys
.
getrecursionlimit
()
recursion_limit
=
sys
.
getrecursionlimit
()
for
cami_method_name
,
cami_params
in
camis
.
items
():
for
cami_method_name
,
cami_params
in
camis
.
items
():
if
self
.
debug
:
print
(
"
Running
"
+
cami_method_name
)
print
(
"
Running
"
+
cami_method_name
)
# create integer codes for cami_versions (needed for predicted_by vertex property)
tool_code
=
max
(
list
(
tool_name_map
.
keys
()))
+
1
tool_code
=
max
(
list
(
tool_name_map
.
keys
()))
+
1
tool_name_map
[
tool_code
]
=
cami_method_name
tool_name_map
[
tool_code
]
=
cami_method_name
...
@@ -349,7 +356,6 @@ class cami():
...
@@ -349,7 +356,6 @@ class cami():
predicted_by
,
cami_scores
,
predicted_by
,
cami_scores
,
tool_name_map
,
tool_code
,
tool_name_map
,
tool_code
,
cami_params
[
'
params
'
])
cami_params
[
'
params
'
])
# sort the resulting vertices according to their cami_score
# sort the resulting vertices according to their cami_score
cami_vlist
=
sorted
(
cami_vertices
,
key
=
lambda
v
:
cami_scores
[
v
],
reverse
=
True
)
cami_vlist
=
sorted
(
cami_vertices
,
key
=
lambda
v
:
cami_scores
[
v
],
reverse
=
True
)
...
@@ -363,30 +369,30 @@ class cami():
...
@@ -363,30 +369,30 @@ class cami():
for
vertex
in
cami_vlist
:
for
vertex
in
cami_vlist
:
print
(
f
'
{
gene_name_map
[
vertex
]
}
\t
{
cami_scores
[
vertex
]
}
\t
{
codes2tools
[
vertex
]
}
'
)
print
(
f
'
{
gene_name_map
[
vertex
]
}
\t
{
cami_scores
[
vertex
]
}
\t
{
codes2tools
[
vertex
]
}
'
)
else
:
else
:
print
(
f
'
With the
{
len
(
seed_genes
)
}
seed genes CAMI (
{
cami_method_name
}
) proposes
{
len
(
cami_vlist
)
}
to add to the Active Module
'
)
print
(
f
'
With the
{
len
(
seed_genes
)
}
seed genes CAMI (
{
cami_method_name
}
) proposes
{
len
(
cami_vlist
)
}
genes
to add to the Active Module
'
)
# for visualization with nvenn
# for visualization with nvenn
self
.
result_gene_sets
[
cami_method_name
]
=
cami_genes
self
.
result_gene_sets
[
cami_method_name
]
=
set
(
cami_genes
)
# transform all vertex indices to their corresponding gene names in a result set
# transform all vertex indices to their corresponding gene names in a result set
for
tool
in
result_sets
:
for
tool
in
result_sets
:
self
.
result_gene_sets
[
tool
.
name
]
=
set
([
gene_name_map
[
vertex
]
for
vertex
in
result_sets
[
tool
]])
self
.
result_gene_sets
[
tool
.
name
]
=
set
([
gene_name_map
[
vertex
]
for
vertex
in
result_sets
[
tool
]])
# add seeds to result sets for drugstone and digest
# add seeds to result sets for drugstone and digest
for
tool
in
result_sets
:
for
toolname
in
self
.
result_gene_sets
:
self
.
result_module_sets
[
tool
.
name
]
=
set
(
gene_name_map
[
vertex
]
for
vertex
in
set
(
result_sets
[
tool
]).
union
(
self
.
seed_lst
))
self
.
result_module_sets
[
toolname
]
=
self
.
result_gene_sets
[
toolname
].
union
(
set
([
gene_name_map
[
svertex
]
for
svertex
in
self
.
seed_lst
]))
print
(
f
'
With the
{
len
(
seed_genes
)
}
seed genes CAMI (
{
cami_method_name
}
) proposes
{
len
(
cami_vlist
)
}
to add to the Active Module
'
)
assert
(
self
.
code2toolname
==
tool_name_map
)
sys
.
setrecursionlimit
(
recursion_limit
)
sys
.
setrecursionlimit
(
recursion_limit
)
# save the results in outputfiles
# save the results in outputfiles
self
.
generate_output
(
cami_method_name
,
seed_genes
,
cami_vlist
,
cami_vertices
,
putative_vertices
,
cami_genes
,
self
.
generate_output
(
cami_method_name
,
seed_genes
,
cami_vlist
,
cami_vertices
,
putative_vertices
,
cami_genes
,
gene_name_map
,
codes2tools
,
cami_scores
)
gene_name_map
,
codes2tools
,
cami_scores
)
def
generate_output
(
self
,
cami_method
,
seed_genes
,
cami_vlist
,
cami_vertices
,
putative_vertices
,
cami_genes
,
def
generate_output
(
self
,
cami_method
,
seed_genes
,
cami_vlist
,
cami_vertices
,
putative_vertices
,
cami_genes
,
gene_name_map
,
codes2tools
,
cami_scores
):
gene_name_map
,
codes2tools
,
cami_scores
):
# save all predictions by all tools
# save all predictions by all tools
if
self
.
debug
:
print
(
'
Saving the results...
'
)
print
(
'
Saving the results...
'
)
with
open
(
f
'
{
self
.
output_dir
}
/all_predictions_
{
self
.
uid
}
.tsv
'
,
'
w
'
)
as
outputfile
:
with
open
(
f
'
{
self
.
output_dir
}
/all_predictions_
{
self
.
uid
}
.tsv
'
,
'
w
'
)
as
outputfile
:
outputfile
.
write
(
f
'
CAMI predictions with
{
len
(
self
.
seed_lst
)
}
of initially
{
len
(
self
.
initial_seed_lst
)
}
seeds:
{
seed_genes
}
,
\n
'
+
outputfile
.
write
(
f
'
CAMI predictions with
{
len
(
self
.
seed_lst
)
}
of initially
{
len
(
self
.
initial_seed_lst
)
}
seeds:
{
seed_genes
}
,
\n
'
+
...
@@ -401,7 +407,7 @@ class cami():
...
@@ -401,7 +407,7 @@ class cami():
ncbi_url
=
(
'
\t
ncbi_url
'
if
self
.
ncbi
else
''
)
ncbi_url
=
(
'
\t
ncbi_url
'
if
self
.
ncbi
else
''
)
ncbi_summary
=
(
'
\t
ncbi_summary
'
if
self
.
ncbi
else
''
)
ncbi_summary
=
(
'
\t
ncbi_summary
'
if
self
.
ncbi
else
''
)
with
open
(
f
'
{
self
.
output_dir
}
/
CAMI
_output_
{
self
.
uid
}
.tsv
'
,
'
w
'
)
as
outputfile
:
with
open
(
f
'
{
self
.
output_dir
}
/
{
cami_method
}
_output_
{
self
.
uid
}
.tsv
'
,
'
w
'
)
as
outputfile
:
outputfile
.
write
(
f
'
gene
\t
index_in_graph
\t
cami_score
\t
degree_in_graph
{
ncbi_url
}{
ncbi_summary
}
\n
'
)
outputfile
.
write
(
f
'
gene
\t
index_in_graph
\t
cami_score
\t
degree_in_graph
{
ncbi_url
}{
ncbi_summary
}
\n
'
)
for
vertex
in
cami_vlist
:
for
vertex
in
cami_vlist
:
if
self
.
ncbi
:
if
self
.
ncbi
:
...
@@ -415,33 +421,29 @@ class cami():
...
@@ -415,33 +421,29 @@ class cami():
url
,
summary
=
''
,
''
url
,
summary
=
''
,
''
outputfile
.
write
(
f
'
{
gene_name_map
[
vertex
]
}
\t
{
str
(
vertex
)
}
\t
{
cami_scores
[
vertex
]
}
\t
{
vertex
.
out_degree
()
}{
url
}{
summary
}
\n
'
)
outputfile
.
write
(
f
'
{
gene_name_map
[
vertex
]
}
\t
{
str
(
vertex
)
}
\t
{
cami_scores
[
vertex
]
}
\t
{
vertex
.
out_degree
()
}{
url
}{
summary
}
\n
'
)
# save the whole module
#
#
save the whole module
whole_module
=
[]
#
whole_module = []
with
open
(
f
'
{
self
.
output_dir
}
/
CAMI_module_
{
cami_method
}
_
{
self
.
uid
}
.txt
'
,
'
w
'
)
as
modfile
:
#
with open(f'{self.output_dir}/{cami_method}_
module_
{self.uid}.txt', 'w') as modfile:
for
vertex
in
seed_genes
:
#
for vertex in seed_genes:
modfile
.
write
(
f
'
{
vertex
}
\n
'
)
#
modfile.write(f'{vertex}\n')
whole_module
.
append
(
vertex
)
#
whole_module.append(vertex)
for
vertex
in
cami_genes
:
#
for vertex in cami_genes:
modfile
.
write
(
f
'
{
vertex
}
\n
'
)
#
modfile.write(f'{vertex}\n')
whole_module
.
append
(
vertex
)
#
whole_module.append(vertex)
print
(
f
'
saved cami output in:
{
self
.
output_dir
}
/CAMI
_output_
{
self
.
uid
}
.tsv
'
)
#
print(f'saved
{
cami
_method}
output in: {
cami_method}
_output_{self.uid}.tsv')
print
(
f
'
saved the Consensus Active Module by CAMI in:
{
self
.
output_dir
}
/
CAMI_nodes_
{
cami_method
}
_
{
self
.
uid
}
.txt
'
)
#
print(f'saved the Consensus Active Module by CAMI in: {self.output_dir}/{cami_method}_
module_
{self.uid}.txt')
# save predict
ion
s by
the
other tools
# save predict
ed module
s by
all
other tools
for
tool
in
self
.
result_
gen
e_sets
:
for
tool
in
self
.
result_
modul
e_sets
:
with
open
(
f
'
{
self
.
output_dir
}
/
{
tool
}
_output_
{
self
.
uid
}
.tsv
'
,
'
w
'
)
as
outputfile
:
with
open
(
f
'
{
self
.
output_dir
}
/
{
tool
}
_output_
{
self
.
uid
}
.tsv
'
,
'
w
'
)
as
outputfile
:
outputfile
.
write
(
'
gene
\n
'
)
outputfile
.
write
(
'
gene
\n
'
)
for
gene
in
self
.
result_gene_sets
[
tool
]:
for
gene
in
self
.
result_gene_sets
[
tool
]:
outputfile
.
write
(
f
'
{
gene
}
\n
'
)
outputfile
.
write
(
f
'
{
gene
}
\n
'
)
if
self
.
debug
:
print
(
f
'
saved
{
tool
}
output in:
{
self
.
output_dir
}
/
{
tool
}
_output_
{
self
.
uid
}
.tsv
'
)
print
(
f
'
saved
{
tool
}
output in:
{
self
.
output_dir
}
/
{
tool
}
_output_
{
self
.
uid
}
.tsv
'
)
# return values
consensus
=
{}
consensus
[
'
module
'
]
=
whole_module
consensus
[
'
seeds
'
]
=
self
.
seed_lst
def
use_nvenn
(
self
):
def
use_nvenn
(
self
):
"""
Create Venn Diagrams via a external tool named degradome.
"""
Create Venn Diagrams via a external tool named degradome.
...
@@ -489,7 +491,6 @@ class cami():
...
@@ -489,7 +491,6 @@ class cami():
#print(list(set(cami_symbol_edges)))
#print(list(set(cami_symbol_edges)))
url
=
drugstone
.
send_request
(
cami_symbols
,
cami_symbol_edges
)
url
=
drugstone
.
send_request
(
cami_symbols
,
cami_symbol_edges
)
print
(
f
'
You can find a network visualization of the CAMI module via:
{
url
}
'
)
print
(
f
'
You can find a network visualization of the CAMI module via:
{
url
}
'
)
print
(
'
The link was also saved in the outputfolder for later.
'
)
with
open
(
f
'
{
self
.
output_dir
}
/drugstone_link_
{
self
.
uid
}
.txt
'
,
'
w
'
)
as
f
:
with
open
(
f
'
{
self
.
output_dir
}
/drugstone_link_
{
self
.
uid
}
.txt
'
,
'
w
'
)
as
f
:
f
.
write
(
url
)
f
.
write
(
url
)
return
url
return
url
...
...
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