Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
binfpy
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
opensource
binfpy
Commits
a30165e5
Commit
a30165e5
authored
Apr 25, 2020
by
Mikael Boden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug with assigning sequence content in parsimony
parent
8430dbc0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
41 deletions
+14
-41
phylo.py
phylo.py
+14
-41
No files found.
phylo.py
View file @
a30165e5
...
...
@@ -193,37 +193,18 @@ class PhyloNode:
for
i
in
range
(
len
(
stubs
)
-
1
):
stubstr
+=
stubs
[
i
]
+
','
return
stubstr
+
stubs
[
-
1
]
+
')'
+
label
+
dist
# there is no label
'''
if not self.left and self.right:
return ',' + right
elif self.left and not self.right:
return left + ','
elif self.left and self.right:
return '(' + left + ',' + right + ')' + dist
'''
# def __le__(self, other):
# """ Returns indication of less than other node. """
# return other and self.__hash__() <= other.__hash__()
#
# def __eq__(self, other):
# """ Returns indication of equivalence to other node. """
# return other and self.__hash__() == other.__hash__()
#
# def __hash__(self):
# """ Returns hash of object. """
# return hash((self.label, self.dist, self.sequence))
def
_printSequences
(
self
,
start
,
end
):
""" Returns string with node (incl descendants) in a Newick style. """
stubs
=
[
''
for
_
in
range
(
self
.
nChildren
())]
label
=
dist
=
''
for
i
in
range
(
self
.
nChildren
()):
stubs
[
i
]
=
self
.
_printSequences
(
self
.
children
[
i
],
start
,
end
)
stubs
[
i
]
=
self
.
children
[
i
]
.
_printSequences
(
start
,
end
)
if
self
.
dist
or
self
.
dist
==
0.0
:
dist
=
':'
+
str
(
self
.
dist
)
if
self
.
label
!=
None
:
if
self
.
sequence
!=
None
:
label
=
""
.
join
(
self
.
sequence
[
start
:
end
])
+
""
else
:
# there is no sequence, just use label
label
=
str
(
self
.
label
)
if
self
.
nChildren
()
==
0
:
return
label
+
dist
...
...
@@ -263,20 +244,6 @@ class PhyloNode:
self
.
sequence
=
seq
break
""" # Not sure if this is required (putting nodes into a canonical ordering)
def _canonise(self):
if self.left == None and self.right == None: # at leaf
return self.label
myleft = self.left._canonise()
myright = self.right._canonise();
if myleft > myright:
tmpnode = self.left
self.left = self.right
self.right = tmpnode
return myright
return myleft
"""
def
_forwardParsimony
(
self
,
aln
):
""" Internal function that operates recursively to first initialise each node (forward),
stopping only once a sequence has been assigned to the node,
...
...
@@ -343,10 +310,10 @@ class PhyloNode:
child_symb
=
[
None
for
_
in
range
(
self
.
nChildren
())]
for
i
in
range
(
self
.
nChildren
()):
child_symb
[
i
]
=
self
.
backptr
[
i
][
col
][
a_parent
]
childbuf
.
append
(
aln
.
alphabet
[
child_symb
[
i
]])
childbuf
[
i
]
.
append
(
aln
.
alphabet
[
child_symb
[
i
]])
col
+=
1
for
i
in
range
(
self
.
nChildren
()):
self
.
children
[
i
]
.
_backwardParsimony
(
aln
,
sequence
.
Sequence
(
childbuf
[
i
],
aln
.
alphabet
,
self
.
label
,
gappy
=
True
))
self
.
children
[
i
]
.
_backwardParsimony
(
aln
,
sequence
.
Sequence
(
childbuf
[
i
],
aln
.
alphabet
,
self
.
children
[
i
]
.
label
or
"Child of "
+
self
.
label
,
gappy
=
True
))
return
self
.
sequence
def
getSequence
(
self
):
...
...
@@ -623,6 +590,12 @@ def get_unique_tree(tree):
def
unpack_list
(
list
):
return
(
" "
.
join
([
"
%
s"
]
*
len
(
list
))
+
"!"
)
%
(
x
for
x
in
list
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__
1
'
:
tree
=
readNewick
(
'/Users/mikael/simhome/ASR/edge1.nwk'
)
print
(
tree
)
if
__name__
==
'__main__'
:
tree
=
readNewick
(
'/Users/mikael/simhome/ASR/parsitest.nwk'
)
tree
.
putAlignment
(
sequence
.
Alignment
(
sequence
.
readFastaFile
(
'/Users/mikael/simhome/ASR/parsitest.aln'
,
sequence
.
DNA_Alphabet
)))
tree
.
parsimony
()
print
(
tree
.
strSequences
())
\ No newline at end of file
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