Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
VEBER Philippe
codepi
Commits
c356bed6
Commit
c356bed6
authored
Nov 08, 2020
by
Philippe Veber
Browse files
scripts: don't check if tree is rooted when not necessary
parent
a0c6b95c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
45 deletions
+53
-45
lib/scripts/parse_input_tree_bpp_sim_part.py
lib/scripts/parse_input_tree_bpp_sim_part.py
+1
-0
lib/scripts/parse_input_tree_common_part.py
lib/scripts/parse_input_tree_common_part.py
+47
-45
lib/scripts/parse_input_tree_diffsel_part.py
lib/scripts/parse_input_tree_diffsel_part.py
+2
-0
lib/scripts/parse_input_tree_pcoc_part.py
lib/scripts/parse_input_tree_pcoc_part.py
+2
-0
lib/scripts/parse_input_tree_topological_part.py
lib/scripts/parse_input_tree_topological_part.py
+1
-0
No files found.
lib/scripts/parse_input_tree_bpp_sim_part.py
View file @
c356bed6
...
...
@@ -3,6 +3,7 @@
#===================================================================================================
######### output trees for simulation
t
,
nodeId
=
read_input_tree
()
### tree.only_node_ids.nhx: a tree with numbered nodes
t
.
write
(
format
=
1
,
features
=
[
"ND"
],
outfile
=
"%s/tree.only_node_ids.nhx"
%
(
OutDirName
),
format_root_node
=
True
)
...
...
lib/scripts/parse_input_tree_common_part.py
View file @
c356bed6
...
...
@@ -92,52 +92,54 @@ elif OutDirName: # if OutDirName is not a empty string we create the directory
#===================================================================================================
# Read input tree
#===================================================================================================
try
:
t
=
Tree
(
TreeFile
.
name
)
except
Exception
as
exc
:
logger
.
error
(
str
(
exc
))
sys
.
exit
(
1
)
if
t
:
features
=
[]
for
n
in
t
.
traverse
(
"postorder"
):
# get all features:
features
.
extend
(
list
(
set
(
dir
(
n
))
-
set
(
dir
(
Tree
()))))
features
=
list
(
set
(
features
))
# list(set(*)) = remove duplicates
logger
.
info
(
"No detected tag"
if
not
features
else
"Detected tags: "
+
", "
.
join
([
f
for
f
in
features
]))
#check rooted tree
nb_root_children
=
len
(
t
.
get_children
())
if
nb_root_children
>
2
:
logger
.
error
(
"Unrooted tree"
)
def
read_input_tree
(
ensure_tree_is_rooted
=
True
):
try
:
t
=
Tree
(
TreeFile
.
name
)
except
Exception
as
exc
:
logger
.
error
(
str
(
exc
))
sys
.
exit
(
1
)
if
"ND"
in
features
:
logger
.
warning
(
"
\"
ND
\"
is in the detected tags but it will be removed by the programm"
)
features
.
remove
(
"ND"
)
if
not
"Condition"
in
features
:
logger
.
error
(
"
\"
Condition
\"
must be in the detected tags.
\"
Condition:1
\"
must identify nodes under the convergent model under Ha"
)
if
t
:
features
=
[]
for
n
in
t
.
traverse
(
"postorder"
):
# get all features:
features
.
extend
(
list
(
set
(
dir
(
n
))
-
set
(
dir
(
Tree
()))))
features
=
list
(
set
(
features
))
# list(set(*)) = remove duplicates
logger
.
info
(
"No detected tag"
if
not
features
else
"Detected tags: "
+
", "
.
join
([
f
for
f
in
features
]))
#check rooted tree
nb_root_children
=
len
(
t
.
get_children
())
if
ensure_tree_is_rooted
and
nb_root_children
>
2
:
logger
.
error
(
"Unrooted tree"
)
sys
.
exit
(
1
)
if
"ND"
in
features
:
logger
.
warning
(
"
\"
ND
\"
is in the detected tags but it will be removed by the programm"
)
features
.
remove
(
"ND"
)
if
not
"Condition"
in
features
:
logger
.
error
(
"
\"
Condition
\"
must be in the detected tags.
\"
Condition:1
\"
must identify nodes under the convergent model under Ha"
)
sys
.
exit
(
1
)
if
not
"Transition"
in
features
:
logger
.
error
(
"
\"
Transition
\"
must be in the detected tags.
\"
Transition:1
\"
must identify nodes where there are transitions"
)
sys
.
exit
(
1
)
if
"Transition"
in
features
:
logger
.
info
(
"
\"
Transition
\"
is in the detected tags.
\"
Transition:1
\"
will be use to indicate OneChange model on this node"
)
# Check existing bl
branch_lengths
=
[]
nodeId
=
0
for
node
in
t
.
traverse
(
"postorder"
):
node
.
add_features
(
ND
=
nodeId
)
branch_lengths
.
append
(
node
.
dist
)
nodeId
=
nodeId
+
1
logger
.
debug
(
"Branch length %s"
,
branch_lengths
)
if
set
(
branch_lengths
)
==
set
([
1.0
]):
logger
.
warning
(
"No branch length in %s, all branch length will be put to 1"
,
tree_filename
)
if
not
(
t
and
branch_lengths
):
sys
.
exit
(
1
)
if
not
"Transition"
in
features
:
logger
.
error
(
"
\"
Transition
\"
must be in the detected tags.
\"
Transition:1
\"
must identify nodes where there are transitions"
)
sys
.
exit
(
1
)
if
"Transition"
in
features
:
logger
.
info
(
"
\"
Transition
\"
is in the detected tags.
\"
Transition:1
\"
will be use to indicate OneChange model on this node"
)
# Check existing bl
branch_lengths
=
[]
nodeId
=
0
for
node
in
t
.
traverse
(
"postorder"
):
node
.
add_features
(
ND
=
nodeId
)
branch_lengths
.
append
(
node
.
dist
)
nodeId
=
nodeId
+
1
logger
.
debug
(
"Branch length %s"
,
branch_lengths
)
if
set
(
branch_lengths
)
==
set
([
1.0
]):
logger
.
warning
(
"No branch length in %s, all branch length will be put to 1"
,
tree_filename
)
if
not
(
t
and
branch_lengths
):
sys
.
exit
(
1
)
logger
.
info
(
"Tree (%s) ok after checking"
,
TreeFile
.
name
)
logger
.
info
(
"Tree (%s) ok after checking"
,
TreeFile
.
name
)
return
(
t
,
nodeId
)
lib/scripts/parse_input_tree_diffsel_part.py
View file @
c356bed6
...
...
@@ -2,6 +2,8 @@
# Create output files
#===================================================================================================
t
,
nodeId
=
read_input_tree
(
ensure_tree_is_rooted
=
False
)
######### output trees for detection
all_node_ids
=
range
(
nodeId
-
1
)
conv_node_ids
=
[
n
.
ND
for
n
in
t
.
search_nodes
(
Condition
=
"1"
)]
...
...
lib/scripts/parse_input_tree_pcoc_part.py
View file @
c356bed6
######### output trees for detection
t
,
_
=
read_input_tree
()
### tree.only_convergent_tags.nhx: a tree with only Condition and Transition tags
t
.
write
(
format
=
1
,
features
=
[
"Condition"
,
"Transition"
],
outfile
=
"%s/tree.only_convergent_tags.nhx"
%
(
OutDirName
))
lib/scripts/parse_input_tree_topological_part.py
View file @
c356bed6
...
...
@@ -67,5 +67,6 @@ def build_conv_topo(t):
return
tconv
t
,
_
=
read_input_tree
()
tconv
=
build_conv_topo
(
t
)
tconv
.
write
(
format
=
1
,
outfile
=
"%s/tree.topological"
%
(
OutDirName
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment