DessimozLab / pyham

MIT License
9 stars 5 forks source link

Empty Ham object? #16

Closed gmartinezredondo closed 2 years ago

gmartinezredondo commented 2 years ago

Hi!

I am trying to use the TreeProfile tool in pyHam to visualize gene evolution. I am first testing the tool with a dummy dataset and obtained my orthoXML file using ETE3. However, when I try to execute the functions from the tutorial, an error raises. I have explored a little bit and it seems that the output of pyham.Ham(tree_str, orthoxml_path, use_internal_name=False) is empty, while it is not when I use the example orthoXML. For example, the list of extant genes I get is empty, but it should not be.

#My orthoxml
ham_analysis.get_list_extant_genes()
[]
#Example orthoxml
ham_analysis_ex.get_list_extant_genes()
[Gene(41), Gene(12), Gene(13), Gene(2), Gene(33), Gene(5), Gene(34), Gene(14), Gene(43), Gene(31), Gene(51), Gene(32), Gene(23), Gene(22), Gene(53), Gene(11), Gene(1), Gene(3), Gene(21)]

I attach the orthoXML file I am using.

Does the orthoXML file have to have additional information that I am not including?

This is the code I have used, in case I did something wrong:

import pyham

nwk_path="./test_sptree.nwk"
tree_str=pyham.utils.get_newick_string(nwk_path,type="nwk")
orthoxml_path =  "./test.orthoxml"
ham_analysis=pyham.Ham(tree_str,orthoxml_path,use_internal_name=False) treeprofile=ham_analysis.create_tree_profile(outfile="output/tp.html")

And the error it raises (which I think is caused by the empty Ham object):

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/metazomics/miniconda3/envs/ete3/lib/python3.5/site-packages/pyham/ham.py", line 394, in create_tree_profile
    tp = TreeProfile(self, hog=hog)
  File "/home/metazomics/miniconda3/envs/ete3/lib/python3.5/site-packages/pyham/TreeProfile.py", line 34, in __init__
    self.treemap = self.compute_tree_profile_full()
  File "/home/metazomics/miniconda3/envs/ete3/lib/python3.5/site-packages/pyham/TreeProfile.py", line 169, in compute_tree_profile_full
    node_genome = self.ham.get_ancestral_genome_by_name(node.name)
  File "/home/metazomics/miniconda3/envs/ete3/lib/python3.5/site-packages/pyham/ham.py", line 628, in get_ancestral_genome_by_name
    raise KeyError('No ancestral genomes match the query name: {}'.format(name))
KeyError: 'No ancestral genomes match the query name: Hsa/Ptr/Mmu/Mms/Cfa/Dme'
alpae commented 2 years ago

Hi @gmartinezredondo

The problem with your test orthoxml is that the orthoxml namespace is not defined. you need to include in <orthoXML> tag the xmlns attribute with http://orthoXML.org/2011/. Then it seems to work:

  <orthoXML xmlns="http://orthoXML.org/2011/">
      <species name="Dme">
      ...
  </orthoXML>
gmartinezredondo commented 2 years ago

That works!

Thank you very much, Adrian!