Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 49 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,64 @@
rootstrap.py: A script to calculate the rootstrap support values for all the branches
`rootstrap.py`: A script to calculate the rootstrap support values for all the branches

Syntax:

rootstrap.py \<tree file> \<bootstrap trees file> \<is rooted> \<outgroup file>
```bash
rootstrap.py <tree file> <bootstrap trees file> <is rooted> <outgroup file>

\<treefile> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The tree file where you want to calculate the rootstrap support values in Newick format (e.g. tree.treefile).<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; The tree can be rooted or unrooted.
<treefile> The tree file where you want to calculate the rootstrap support values in Newick format (e.g. tree.treefile).
The tree can be rooted or unrooted.

\<bootstrap trees file> All the bootstrap trees in Newick format.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; For example: .ufboot file from IQ-TREE (tree.ufboot)
<bootstrap trees file> All the bootstrap trees in Newick format.
For example: .ufboot file from IQ-TREE (tree.ufboot)

\<is rooted> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; Are the ML tree and the boostrap trees rooted or not.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; True - The trees assumed to be rooted and no outgroup taxa infromation is required <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; False - The trees assumed to be unrooted and outgroup taxa infromation is required <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; (default: True)
<is rooted> Are the ML tree and the boostrap trees rooted or not.
True - The trees assumed to be rooted and no outgroup taxa infromation is required
False - The trees assumed to be unrooted and outgroup taxa infromation is required
(default: True)

\<outgroup file> ;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; outgroup taxa in Nexus format. <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; The outgroup block can be part of the alignment (e.g. OG_File1.nex) file or in a separate file (e.g. OG_File2.nex)
<outgroup file> outgroup taxa in Nexus format.
The outgroup block can be part of the alignment (e.g. OG_File1.nex) file or in a separate file (e.g. OG_File2.nex)
```

-------------------------------------------------------------------------------------
rBED_rSED.py: A script to calculate the root Branchlength Error Distance (rBED) and the root Split Error Distance (rSED)
`rBED_rSED.py`: A script to calculate the root Branchlength Error Distance (rBED) and the root Split Error Distance (rSED)

Syntax:

rBED_rSED.py \<tree file>
```bash
rBED_rSED.py <tree file>

\<treefile> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The tree file (rooted tree only in Newick format) where you want to calculate rBED and rSED values.
<treefile> The tree file (rooted tree only in Newick format) where you want to calculate rBED and rSED values.
```

Note: In order to calculate rBED and rSED values, the true root should be known (or assumed to be known) in advance.

## Installation

For running the scripts in this repository you will need Python 3, and the dependencies
listed in `requirements.txt`.

It is recommended to use a virtual environment to avoid complications with system
dependencies and Python.

For users that prefer `pip`, the following should work assuming you have Python 3
`python` and `pip` in your command line `$PATH` (if using an older OS, you may still
have `python3` and `pip3`, so just use those commands instead).

```bash
$ python -m venv venv # create a virtual environment called venv with pip
$ source venv/bin/activate # load the virtual environment, note the change in some shells displaying the venv name
(venv) $ pip install -r requirements.txt
# ... it should take a few minutes to download dependencies from PYPI.org and install in your venv (not in your OS Python modules)
(venv) $ python rootstrap.py
Error: Please provide the ML tree file and the bootstrap trees file
(venv) $ python rBED_rSED.py
Error: Please provide the rooted ML tree file
```

If you had a similar output to the commands above, your installation worked successfully.
Have a read at the command syntax instructions to use the scripts.

For Conda users, follow their instructions for [managing environments](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html)
and just run `pip`. Alternativelly, you can consult [Conda Forge](https://conda-forge.org/)
searching for equivalent packages and installing them via `conda install $package-name`.
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ete3==3.1.*
dendropy==4.4.*
biopython==1.78
six==1.15.*
9 changes: 4 additions & 5 deletions rootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def all_possible_roots(treefile):
raise SystemExit('Error: you have unrooted trees. please deactivate the is_rooted flag and provide outgroup taxa file in Nexus format')
return roots, sameTree

def caluclate_rootstrap(treeFile, bootFile, is_rooted, out_group):
def calculate_rootstrap(treeFile, bootFile, is_rooted, out_group):
'''
input:
treeFile: rooted tree in newick format (.treefile in IQ-TREE)
Expand All @@ -64,7 +64,7 @@ def caluclate_rootstrap(treeFile, bootFile, is_rooted, out_group):
trees = []
polyphyly = 0
if not is_rooted:
if out_group == None:
if out_group is None:
raise SystemExit('Error: Please provide outgroup taxa in Nexus format')
ML_tree = Tree(treeFile)
nex = Nexus.Nexus()
Expand Down Expand Up @@ -104,14 +104,13 @@ def caluclate_rootstrap(treeFile, bootFile, is_rooted, out_group):
ML_tree.write(outfile=rootedMLtree) #write the rooted tree with ingroup taxa only to a file

else:
ML_tree = Tree(treeFile)
with open(bootFile, 'r') as f:
for tree in f:
t = Tree(tree)
boottrees.append(t.write(format=9))

N_boottrees = len(boottrees)
booted = [(g[0], len(list(g[1]))) for g in ite.groupby(boottrees)] #a list of all unique bootstrap trees with thier number of occurrence
booted = [(g[0], len(list(g[1]))) for g in ite.groupby(boottrees)] #a list of all unique bootstrap trees with their number of occurrence
boottrees = []
for b in booted:
t2 = Tree(b[0])
Expand Down Expand Up @@ -192,7 +191,7 @@ def rootstrap():
out_group = sys.argv[4]
elif len(sys.argv) > 5:
raise SystemExit('Error: too many arguments')
print('Note: ingroup taxa are not monophyletic in {} bootstrap trees\n'.format(caluclate_rootstrap(sys.argv[1], sys.argv[2], is_rooted, out_group)))
print('Note: ingroup taxa are not monophyletic in {} bootstrap trees\n'.format(calculate_rootstrap(sys.argv[1], sys.argv[2], is_rooted, out_group)))

if __name__ == '__main__':
rootstrap()