Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
treebuilder
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Huang Di
treebuilder
Commits
ed27460a
Commit
ed27460a
authored
Jul 07, 2023
by
Huang Di
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gene flow proportion block list, display threshold
parent
f47a1c00
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
4 deletions
+23
-4
main.py
+8
-3
treebuilder.py
+15
-1
No files found.
main.py
View file @
ed27460a
...
...
@@ -17,17 +17,22 @@ args = {
'threshold2'
:
0
,
# gene flow display threshold
'threshold3'
:
3
,
# gene flow merge threshold
'bidirectional'
:
True
,
# calculate the reversed gene flow
'calculate_pd'
:
Fals
e
,
# calculate the gene flow confidence
'calculate_pd'
:
Tru
e
,
# calculate the gene flow confidence
'data_path'
:
'data/test.log'
,
'save_path'
:
'pictures/tree
2
.png'
,
'save_path'
:
'pictures/tree.png'
,
'draw_gene_flow'
:
True
,
'gene_flow_display_confidence'
:
0.7
,
'target_block_list'
:
[
'Tianyuan'
],
's1_block_list'
:
[
'Boshan'
],
# 'target_block_list': [],
# 's1_block_list': [],
}
populations
=
[
'Kostenki14'
,
'Tianyuan'
,
'AR19K'
,
'AR14K'
,
'Zongri5
.
1k'
,
'Zongri5
_
1k'
,
'Boshan'
,
'Qihe3'
,
'Donghulin'
,
...
...
treebuilder.py
View file @
ed27460a
from
itertools
import
combinations
from
data_structures
import
UnionFindSet
,
Graph
from
anytree
import
Node
,
PreOrderIter
from
anytree
import
Node
,
PreOrderIter
,
RenderTree
from
anytree.exporter
import
DotExporter
from
collections
import
defaultdict
# from sklearn.linear_model import LinearRegression
...
...
@@ -405,6 +405,8 @@ class TreeBuilder(object):
bidirectional
=
kwargs
.
get
(
'bidirectional'
,
True
)
calculate_pd
=
kwargs
.
get
(
'calculate_pd'
,
False
)
tar_block_list
=
kwargs
.
get
(
'target_block_list'
,
[])
s1_block_list
=
kwargs
.
get
(
's1_block_list'
,
[])
# calculate_m1('Dushan', 'Baojianshan')
# calculate_m1('Baojianshan', 'Dushan')
# calculate_m1('Boshan', 'Dushan')
...
...
@@ -413,10 +415,12 @@ class TreeBuilder(object):
print
(
'Calculating gene flows...'
)
gf_cnt
=
0
for
s2
,
tar
in
gene_flow
:
if
tar
in
tar_block_list
:
continue
propotion
[(
s2
,
tar
)]
=
[]
if
(
s2
,
tar
)
not
in
self
.
s1_record
:
continue
for
s1
in
self
.
s1_record
[(
s2
,
tar
)]:
if
s1
in
s1_block_list
:
continue
if
DEBUG
:
print
(
'-----------------------------------------------'
)
# pd = False to make it fast
...
...
@@ -442,10 +446,12 @@ class TreeBuilder(object):
if
bidirectional
:
print
(
'Calculating reversed gene flows...'
)
for
tar
,
s2
in
gene_flow
:
if
tar
in
tar_block_list
:
continue
propotion
[(
s2
,
tar
)]
=
[]
if
(
s2
,
tar
)
not
in
self
.
s1_record
:
continue
for
s1
in
self
.
s1_record
[(
s2
,
tar
)]:
if
s1
in
s1_block_list
:
continue
mix_bc
,
m_pd_bc
=
calculate_m1
(
s1
,
tar
,
s2
)
# mix_a1b, mix_pd_a1b = calculate_m1(s2, tar, s1)
# print('mix_bc, mix_a1b', mix_bc, mix_a1b)
...
...
@@ -468,6 +474,8 @@ class TreeBuilder(object):
print
(
mat
.
format
(
's2'
,
'tar'
,
's1'
,
'mix'
,
'm_pd'
))
mat
=
"{:10}
\t
{:10}
\t
{:10}
\t
{:.3f}
\t
{:.3f}"
m_pd_display_threshold
=
kwargs
.
get
(
'gene_flow_display_confidence'
,
0.0
)
gene_flows_checked_by_propotion
=
[]
for
gene_flow
,
m1s
in
propotion
.
items
():
s2
,
tar
=
gene_flow
...
...
@@ -476,7 +484,10 @@ class TreeBuilder(object):
# print(s2, tar, s1, mix, m_pd)
print
(
mat
.
format
(
s2
,
tar
,
s1
,
mix
,
m_pd
))
if
(
s2
,
tar
)
not
in
gene_flows_checked_by_propotion
:
if
not
(
calculate_pd
and
m_pd
<
m_pd_display_threshold
):
gene_flows_checked_by_propotion
.
append
((
s2
,
tar
))
print
(
',,,'
,
gene_flows_checked_by_propotion
)
print
(
m_pd_display_threshold
)
return
gene_flows_checked_by_propotion
def
calculate_propotion_bak2
(
self
,
gene_flow
,
order
,
visited_leaves
,
bidirectional
=
True
):
...
...
@@ -693,6 +704,9 @@ class TreeBuilder(object):
if
print_gene_flow
:
for
l1
,
l2
in
self
.
gene_flow
:
options
.
append
(
"
%
s ->
%
s [color=red]"
%
(
l1
,
l2
))
print
(
self
.
populations
)
print
(
self
.
relations
)
print
(
RenderTree
(
self
.
root
))
return
DotExporter
(
self
.
root
,
options
=
options
)
def
export_dot
(
self
,
filename
,
print_gene_flow
=
True
):
...
...
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