It doesn't print anything because there's nothing to print.
All scorer
is is an instance of a default class at this point. You haven't passed any arguments (a tree or matrix) to the ParsimonyScorer
for it to have anything to calculate on.
Also, you define constructor
twice, which is probably confusing things.
Are you following the documentation online?
http://biopython.org/DIST/docs/api/Bio.Phylo.TreeConstruction.ParsimonyTreeConstructor-class.html
and
https://biopython.org/wiki/Phylo
The result of the suggestion above (for my test tree) is scorer.get_score(pars_tree, aln)
= 167
, but I have no idea if that's meaningful (see that you have to pass it a tree and alignment in order for there to be data to calculate on though).
==============
All the tutorial code works for me, see below:
>>> from Bio import Phylo
>>> from Bio import AlignIO
>>> from Bio.Phylo.TreeConstruction import *
>>> aln = AlignIO.read('PVC1_homologs.phy', 'phylip')
>>> print aln
SingleLetterAlphabet() alignment with 16 rows and 149 columns
MSTTPEQIAVEYPIPTYRFVVSLGDEQIPFNSVSGLDISHDVIE...QAA PAU_02775
....<abridged>
MSTTVDQIAVQYPIPTYRFVVTVGDEQMSFQSVSGLDISYDTIE...EFH PLT_02568
>>> calculator = DistanceCalculator('identity')
>>> dm = calculator.get_distance(aln)
>>> dm
DistanceMatrix(names=['PAU_02775', 'PLT_01696', ...<abridged>..., 0.03355704697986572, 0]])
>>> print(dm)
PAU_02775 0
PLT_01696 0.0134228187919 0
PAK_02606 0.0134228187919 0.0134228187919 0
...<abridged>...
PAU_02775 PLT_01696 PAK_02606 ....
>>> constructor = DistanceTreeConstructor(calculator, 'nj')
>>> tree = constructor.build_tree(aln)
>>> scorer = ParsimonyScorer()
>>> searcher = NNITreeSearcher(scorer)
>>> constructor = ParsimonyTreeConstructor(searcher, tree)
>>> pars_tree = constructor.build_tree(aln)
>>> print pars_tree
Tree(rooted=True)
Clade(branch_length=0)
...<abridged>...
Clade(branch_length=0.000559284116331, name='PAK_02014')
Clade(branch_length=0.00615212527964, name='PAU_02206')
>>> scorer
<Bio.Phylo.TreeConstruction.ParsimonyScorer object at 0x7f1a308cbbd0> # See? Nothing to be done with these instances
>>> print scorer
<Bio.Phylo.TreeConstruction.ParsimonyScorer object at 0x7f1a308cbbd0>
>>> searcher
<Bio.Phylo.TreeConstruction.NNITreeSearcher object at 0x7f1a308cbb10>
>>> searcher.
searcher.__class__( searcher.__doc__ searcher.__hash__( searcher.__new__( searcher.__repr__( searcher.__str__( searcher._get_neighbors( searcher.search(
searcher.__delattr__( searcher.__format__( searcher.__init__( searcher.__reduce__( searcher.__setattr__( searcher.__subclasshook__( searcher._nni(
searcher.__dict__ searcher.__getattribute__( searcher.__module__ searcher.__reduce_ex__( searcher.__sizeof__( searcher.__weakref__ searcher.scorer
>>> searcher.scorer
<Bio.Phylo.TreeConstruction.ParsimonyScorer object at 0x7f1a308cbbd0>
>>> scorer.get_score()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: get_score() takes exactly 3 arguments (1 given) # Needs some data to work on...
>>> scorer.get_score(pars_tree, aln)
167
When you refer to
scorer
are you referring to the object you created here in this line:scorer = ParsimonyScorer()
Also what does "it doesn't work" refer to. It produces an error? It returns nothing? It gives a different score/value/returns something unexpected?
It looks like there's a method function called
get_score
that you can access. I think usage would be:scorer.get_score()
. Not sure if it's applicable though.