This script takes in a multi-tree newick file and splits it into individual newick files based on an iqtree 2.3.6 log file. Although, it should work with most versions. Specifically, this script is useful for when you have used the -S flag to generate your locus/gene trees, and is intended as an intermediate step before running a sortadate sortadate analysis. It may have utility in concordance vector analyses as well, but I haven't explored that yet. Notably, the script assumes the analysis partition file came from one generated by AMAS concatenate function, where the locus trees are appended with a p*_{locus_name}. A python v3.10 conda environment with bioconda::phyx installed is required for the full utility of the script. You can alternatively use the available requirements.yaml file to get these appropriate dependencies: conda env create -f requirements.yml.
This script will split the locus trees into a new directory and reroot them using phyx. The command pxrr uses a ranked order outgroup flag, which can accept multiple outgroups as a list. Here it is denoted as a comma seperated input (e.g., --reroot out1,out2,out4). It has the utility to check that a fasta file exists by calling that dirrectory with the --fasta_directory flag. This exists as somewhat of a sanity check to ensure you have called your files correctly. The --keep_only_outgroup flag will only reroot trees that include an outgroup. However, the --keep_only_outgroup flag only works with one out group. A list named no_outgroups.list will be printed in the output directory. Lastly, as a final check, the number of files it splits and rerooted is printed to the standard output.
In development, I removed the full file names in my partition file (p4_core1000_trimalauto) thinking I would be slick, but I had to re-add the _trimalauto suffix to the file name for consistency, so that is why the --suffix flag exists. I.E., my original files were named p4_core1000_trimalauto.fasta but I altered my partition file to say p4_core1000 (removing the suffix). Thus, unless you have altered your partition names in a similar way, you should not need the --suffix flag!
python iqtree_sortadate_helper.py \
--logfile locustrees.iqtree \
--input_locus_trees locustrees.treefile \
--output locus_trees \
--fasta_directory loci_keep/ \
--reroot GCA_048127345.1 \
--keep_only_outgroup
If used in publication, please be sure to refer to this github and approrpiately attribute AMAS, SortaDate, phyx, and IQTree.