Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
linked reads molecule ordering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Yoann DUFRESNE
linked reads molecule ordering
Commits
566d08b3
Commit
566d08b3
authored
6 years ago
by
Yoann Dufresne
Browse files
Options
Downloads
Patches
Plain Diff
starting an avaluation/debug script
parent
ae5147d9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
evaluate.py
+94
-0
94 additions, 0 deletions
evaluate.py
requirements.txt
+2
-1
2 additions, 1 deletion
requirements.txt
with
96 additions
and
1 deletion
evaluate.py
0 → 100755
+
94
−
0
View file @
566d08b3
#!/usr/bin/env python3
import
sys
import
argparse
from
termcolor
import
colored
import
networkx
as
nx
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'
Process some integers.
'
)
parser
.
add_argument
(
'
filename
'
,
type
=
str
,
help
=
'
The output file to evalute
'
)
args
=
parser
.
parse_args
()
return
args
def
load_graph
(
filename
):
if
filename
.
endswith
(
'
.graphml
'
):
return
nx
.
read_graphml
(
filename
)
elif
filename
.
endswith
(
'
.gexf
'
):
return
nx
.
read_gexf
(
filename
)
else
:
print
(
"
Wrong file format. Require graphml or gefx format
"
,
file
=
sys
.
stderr
)
exit
()
"""
Compute appearance frequencies from node names.
All the node names must be under the format :
{idx}:{mol1_id}_{mol2_id}_...{molx_id}.other_things_here
@param graph The networkx graph representinf the deconvolved graph
@param only_wong If True, don
'
t print correct nodes
@param file_pointer Where to print the output. If set to stdout, then pretty print. If set to None, don
'
t print anything.
@return A tuple containing two dictionaries. The first one with theoritical frequences of each node, the second one with observed frequencies.
"""
def
parse_graph_frequencies
(
graph
,
only_wrong
=
False
,
file_pointer
=
sys
.
stdout
):
# Compute origin nodes formated as `{idx}:{mol1_id}_{mol2_id}_...`
observed_frequences
=
{}
origin_node_names
=
[]
for
node
in
graph
.
nodes
():
first_dot
=
node
.
find
(
"
.
"
)
origin_name
=
node
[:
first_dot
]
# Count frequency
if
not
origin_name
in
observed_frequences
:
observed_frequences
[
origin_name
]
=
0
origin_node_names
.
append
(
origin_name
)
observed_frequences
[
origin_name
]
+=
1
# Compute wanted frequencies
theoritical_frequencies
=
{}
for
node_name
in
origin_node_names
:
_
,
composition
=
node_name
.
split
(
'
:
'
)
mol_ids
=
composition
.
split
(
'
_
'
)
# The node should be splited into the number of molecules inside itself
theoritical_frequencies
[
node_name
]
=
len
(
mol_ids
)
# Print results
if
file_pointer
!=
None
:
print
(
"
--- Frequency analysis ---
"
,
file
=
file_pointer
)
for
key
in
theoritical_frequencies
:
obs
,
the
=
observed_frequences
[
key
],
theoritical_frequencies
[
key
]
result
=
f
"
{
key
}
:
{
obs
}
/
{
the
}
"
if
file_pointer
==
sys
.
stdout
:
result
=
colored
(
result
,
'
green
'
if
obs
==
the
else
'
red
'
)
if
only_wrong
and
obs
==
the
:
continue
print
(
result
,
file
=
file_pointer
)
return
theoritical_frequencies
,
observed_frequences
def
print_summary
(
frequencies
,
file_pointer
=
sys
.
stdout
):
print
(
"
--- Global summary ---
"
,
file
=
file_pointer
)
def
main
():
args
=
parse_args
()
graph
=
load_graph
(
args
.
filename
)
frequencies
=
parse_graph_frequencies
(
graph
)
print_summary
(
frequencies
)
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
requirements.txt
+
2
−
1
View file @
566d08b3
networkx
>=2.2
\ No newline at end of file
networkx
>=2.2
termcolor
>=1.1
\ 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