I calculate the pangenome for a set of bacterial genomes I am working with.
I have a classical pangenome matrix that looks like this:

               speciesA    speciesB ... speciesZ 
    gene1   1            2                 0 
    gene2    0            1                 0 
    gene3    1             1                1 
    gene4    1             1                2

Now I would like to map the gen gain and loss in a phylogenetic tree.
Something like this:

![enter image description here][1]

I guess I could just record all families of genes shared among the different species in each branch of the tree, but I believe there is a more elegant way of doing that.


Any suggestion?
  [1]: http://www.nature.com/nature/journal/v510/n7503/images/nature13400-f3.jpg
I guess you are looking for a software like Count, [that performs ancestral reconstruction of gene family sizes over a given tree][1]. But as [abascalfederico][2] mentioned, you should be very careful with the possibility of HGT.


  [1]: http://bioinformatics.oxfordjournals.org/content/26/15/1910.full "doi: 10.1093/bioinformatics/btq315"
  [2]: https://www.biostars.org/p/180593/#180615