mirror of
https://codeberg.org/JasterV/sarscov-hierarchy.git
synced 2026-04-27 02:15:45 +00:00
ete3 added
This commit is contained in:
parent
16a15d7e7f
commit
34287dc372
4 changed files with 18 additions and 16 deletions
|
|
@ -15,6 +15,11 @@ pip install -r requeriments.txt 📝
|
|||
|
||||
### ✨ Execute
|
||||
|
||||
From the [NCBI official database](https://www.ncbi.nlm.nih.gov/labs/virus/vssi/#/virus?VirusLineage_ss=Severe%20acute%20respiratory%20syndrome%20coronavirus%202%20(SARS-CoV-2),%20taxid:2697049&SeqType_s=Nucleotide) download the sequences.fasta and sequences.csv files and you are ready to try this project!
|
||||
|
||||
We provide you a .zip file with 2 other fasta and csv files to try out without downloading anything so, have fun!
|
||||
|
||||
|
||||
```
|
||||
cd src/python
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import os
|
|||
import signal
|
||||
from os.path import join
|
||||
from sys import argv
|
||||
from zipfile import ZipFile
|
||||
|
||||
from utils.csv_table import CsvTable
|
||||
from utils.fasta_map import FastaMap
|
||||
|
|
@ -27,7 +26,6 @@ def main():
|
|||
distances_table = fasta_map.compare_all_samples()
|
||||
tree = HierarchyTree(distances_table, labels)
|
||||
tree.build_tree()
|
||||
tree.show()
|
||||
print("Done!")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class FastaMap:
|
|||
sequences = filter(None, fasta.read().split('>'))
|
||||
for seq in sequences:
|
||||
rna_id, rna = self._get_rna(seq)
|
||||
data[rna_id] = rna
|
||||
data[rna_id] = rna if len(rna) < 1000 else rna[:1000]
|
||||
return data
|
||||
|
||||
def _compare_all_samples(self):
|
||||
|
|
|
|||
|
|
@ -1,30 +1,29 @@
|
|||
from graphviz import Graph
|
||||
from ete3 import Tree, TreeStyle
|
||||
|
||||
|
||||
class HierarchyTree:
|
||||
def __init__(self, table, labels=None):
|
||||
self.__dot = Graph("Hierarchy Sars-Cov-2",
|
||||
node_attr={'shape': 'plaintext'})
|
||||
self.__table = table
|
||||
self.__labels = labels
|
||||
|
||||
def build_tree(self):
|
||||
hierarchy_table = self.__table
|
||||
closest_pair = tuple()
|
||||
while len(hierarchy_table) > 1:
|
||||
closest_pair = self.find_closest_pair(hierarchy_table)
|
||||
self._add_relation(closest_pair)
|
||||
new_relation = self.build_relation(closest_pair, hierarchy_table)
|
||||
hierarchy_table = self.refactor_table(
|
||||
closest_pair, new_relation, hierarchy_table)
|
||||
self._show_tree(str(closest_pair))
|
||||
|
||||
def show(self):
|
||||
self.__dot.render("../../output/hierarchy")
|
||||
|
||||
def _add_relation(self, pair):
|
||||
node1, node2 = tuple(map(self.__transform, pair))
|
||||
new_node = f"{node1},{node2}"
|
||||
self.__dot.edge(new_node, node1)
|
||||
self.__dot.edge(new_node, node2)
|
||||
def _show_tree(self, tuple_repr):
|
||||
t = Tree(tuple_repr + ";")
|
||||
ts = TreeStyle()
|
||||
ts.show_leaf_name = True
|
||||
ts.mode = "c"
|
||||
ts.arc_start = -180 # 0 degrees = 3 o'clock
|
||||
ts.arc_span = 180
|
||||
t.render("hierarchy.png", tree_style=ts)
|
||||
|
||||
def __transform(self, value):
|
||||
value = str(value).translate(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue