190 likes | 298 Views
This project involves creating a subclass for a Royal Vikings family tree, extending a generic tree class to represent historical figures like Gorm den Gamle and Svend Tveskæg, maintaining parent-sibling relationships and additional royal attributes. We will implement methods for string representation and data management of Viking lineage, as well as parse Newick tree files to calculate Hamming errors in sequences mapped to each tree node. The tree structure aims to enhance our understanding of Viking ancestry and lineage in a computational context.
E N D
Viking database! Family tree of Gorm den Gamle, Harald Blåtand, Svend Tveskæg .. Build new class for representing this tree..?
tree.py No! We already have a generic tree class: Phylogeny_node
general_tree.py • Create copy with more general name • Build Royal class as a subclass of this class: • Needs same attributes and methods, plus perhaps more
royal_vikings.py (part 1) Overrides __str__ method of Node class • A Royal viking in a family tree has a father/parent node, a name, and a string representing the reigning period (if viking was queen/king)
royal_vikings.py (part 2) Test program Not queen/king: no reign given
royal_vikings.py (part 3) [..] Name: Svend Estridsen Parent: Estrid Siblings: Sons: Harald Hen, Knud den Hellige, Oluf Hunger, Erik Ejegod, Niels (f)ather, (s)on, si(b)ling, (p)rint, (q)uit? f Name: Estrid Parent: Svend Tveskæg Siblings: Harald 2., Knud den Store Sons: Svend Estridsen (f)ather, (s)on, si(b)ling, (p)rint, (q)uit? b Number of sibling (0-1)? 1 Name: Knud den Store Parent: Svend Tveskæg Siblings: Harald 2., Estrid Sons: Knud 3. Hardeknud (f)ather, (s)on, si(b)ling, (p)rint, (q)uit? p Knud den Store (1014-1035) - Svend Tveskæg (987-1014) - Harald Blåtand (958-987) – Gorm den Gamle (?-958) Navigating the family tree, starting with Niels
Another kind of tree: Newick trees ((monkey:100.85,cat:47.14):20.59); 20.59 47.14 100.85 cat monkey
Project: Newick trees Load and parse newick tree file Need newick class Newick node has name, list of sons, distance to father, sequence Inherit from general_tree's Node class! Need parser Check that loaded tree corresponds to “current sequences” Create (ID, sequence) dictionary from current seqs (efficient!) After parsing tree file, traverse tree and look up sequence from each node ID, store in node Give error message if ID not found Calculate “Average Hamming error”
Project: Newick trees Load and parse newick tree file Need newick class Newick node has name, list of sons, distance to father, sequence Inherit from general_tree's Node class! Need parser Check that loaded tree corresponds to “current sequences” Create (ID, sequence) dictionary from current seqs (efficient!) After parsing tree file, traverse tree and look up sequence from each node ID, store in node Give error message if ID not found Calculate “Average Hamming error”
Average Hamming Error in tree Average number of mismatches per alignment position over all alignments in tree (2+1+1+1)/(5+6+5+4) = 5/20 = 0.25 errors per alignment position CATAT 1/4 1/5 CGATAT GTAT 1/6 2/5 CGTAT CGAGAT
hamming.py (part 1) Newick_node derives from Node Exercise: Newick_node method CATAT CGATAT GTAT CGTAT CGAGAT
hamming.py (part 1) CATAT mismatches = 0 alignmentlength = 0 CGATAT GTAT 0/0 2/5 CGTAT CGAGAT
hamming.py (part 1) CATAT mismatches = 2 alignmentlength = 5 CGATAT GTAT 0/0 0/0 2/5 1/6 CGTAT CGAGAT
hamming.py (part 1) CATAT mismatches = 3 alignmentlength = 11 CGATAT GTAT 0/0 1/6 CGTAT CGAGAT
hamming.py (part 1) CATAT 3/11 CGATAT GTAT CGTAT CGAGAT
hamming.py (part 1) CATAT 3/11 0/0 1/5 1/4 CGATAT GTAT CGTAT CGAGAT
hamming.py (part 1) 5/20 CATAT 3/11 0/0 1/5 1/4 CGATAT GTAT CGTAT CGAGAT
hamming.py (part 2) Average Hamming Error CATAT CGATAT GTAT CGTAT CGAGAT Average Hamming error: 0.250