diff --git a/README.md b/README.md index 92cdcbf..5a158e2 100644 --- a/README.md +++ b/README.md @@ -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 \ \ \ \ +```bash +rootstrap.py -\                     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. + 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. -\ All the bootstrap trees in Newick format.
-                                      For example: .ufboot file from IQ-TREE (tree.ufboot) + All the bootstrap trees in Newick format. + For example: .ufboot file from IQ-TREE (tree.ufboot) -\                  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) + 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 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) + 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 \ +```bash +rBED_rSED.py -\                     The tree file (rooted tree only in Newick format) where you want to calculate rBED and rSED values. + 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`. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..12f2720 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +ete3==3.1.* +dendropy==4.4.* +biopython==1.78 +six==1.15.* diff --git a/rootstrap.py b/rootstrap.py index 1b4efad..796ac2b 100644 --- a/rootstrap.py +++ b/rootstrap.py @@ -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) @@ -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() @@ -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]) @@ -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()