<jupyter_start><jupyter_text>Phylogenetics Tutorial **Run a [phylogenetics](https://github.com/harmslab/phylogenetics "https://github.com/harmslab/phylogenetics") project, all in one place!***This tutorial will cover:*1. Project initialization and data input/output2. BLASTing and aligning sequences3. Building a phylogenetic tree4. Reconstructing ancestral proteins (ASR)5. Quality control and evaluation for each of the steps above<jupyter_code># import packages

import phylogenetics as phy
import phylogenetics.tools as tools
import phylopandas as ph
import pandas as pd
from phylovega import TreeChart<jupyter_output><empty_output><jupyter_text>1. Inititialize a phylogenetics project This creates a folder in your current working directory (here called 'project1') where your project data will be automatically saved.This also initializes the `project` object (you can name it whatever you want).The `project` object is a [phylopandas dataframe](https://github.com/Zsailer/phylopandas "https://github.com/Zsailer/phylopandas") that you can view within the notebook at any point. As you proceed, it will house all of your sequence, alignment, tree, and ancestor data.<jupyter_code># intitialize project object and create project folder

project = phy.PhylogeneticsProject(project_dir='tutorial', overwrite=True)<jupyter_output><empty_output><jupyter_text>2. Read in your starting sequence(s)You'll need at least one sequence to start with. In this example, we're reading in a single sequence - a human protein called MD2.<jupyter_code># read in seed sequence(s) to project object

project.read_data("md2_seed_sequence.txt", schema="fasta")<jupyter_output><empty_output><jupyter_text>3. Use [BLAST](https://blast.ncbi.nlm.nih.gov/Blast.cgi "https://blast.ncbi.nlm.nih.gov/Blast.cgi") to search for orthologs similar to your seed sequence(s)The default search returns 100 hits with an e-value cutoff of 0.01 and default BLAST gap penalties.  These parameters can be modified as you wish (to view options, run `project.compute_blast?` cell below or check out [Biopython's NCBI BLAST](https://biopython.org/DIST/docs/api/Bio.Blast.NCBIWWW-module.html "https://biopython.org/DIST/docs/api/Bio.Blast.NCBIWWW-module.html") module)<jupyter_code># run BLAST search with default settings, returning 100 hits

project.compute_blast(hitlist_size=100)<jupyter_output>Running blast...
Done.<jupyter_text>4. Build a phylogenetic tree using [PhyML](http://www.atgc-montpellier.fr/phyml/ "http://www.atgc-montpellier.fr/phyml/")  5. Reconstruct ancestral proteins using [PAML](http://abacus.gene.ucl.ac.uk/software/paml.html "http://abacus.gene.ucl.ac.uk/software/paml.html") \ start working here \- add docs to alignment, clustering, tree building, ASR, gblocks, df_editor, etc.\- rd 1 tutorial - blast, align, tree, ancestors\- rd 2 - add in QC:1) look at alignment (outsource to aliview)\- remove bad seqs (df_editor)3) look at tree (outsource to figtree? use viewer?)\- remove long branches (df_editor)4) ancestors - look at PP, compare before and after QC<jupyter_code>project.compute_clusters()
project.compute_alignment()
project.compute_gblocks()
project.compute_tree()
project.compute_reconstruction()
# Visualize tree and ancestors using phylovega

from phylovega import TreeChart

# Construct Vega Specification
chart = TreeChart.from_phylopandas(
    project.data,
    height_scale=300,

    # Node attributes
    node_size=300,
    node_color="#ccc",

    # Leaf attributes
    leaf_labels="id",

    # Edge attributes
    edge_width=2,
    edge_color="#000",
)

chart<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09974993053626008, 'fraction_numerical': 0.011114198388441235, 'mean_word_length': 5.509945750452079, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '507369', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1074, 'n_words': 344, 'path': 'examples/detailed_tutorial.ipynb', 'repo_name': 'Zsailer/phylo_tools_2', 'size': '3599'}