-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmuscle.py
48 lines (41 loc) · 1.44 KB
/
muscle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#Importación de módulos de Python necesarios para el script
import os
import pandas as pd
import sys
from Bio import Phylo
from Bio.Align.Applications import MuscleCommandline
#Función que alinea secuencias con MUSCLE (previo a alineamiento)
def muscle_align(input, output):
try:
in_file = r'{0}'.format(input)
out_file = r'{0}'.format(output)
muscle_cline = MuscleCommandline(input=in_file, out=out_file)
stdout, stderr = muscle_cline()
except:
print('Imposible alinear el archivo '+query+':'
'¿Ha comprobado sus valores de coverage e identity?')
pass
def muscle_maketree(alignd_sec, map):
#Como se puede ver, muy a mi pesar he usado os en vez de biopython, como acostumbro
#Esto es así porque el paquete MuscleCommandLine está fatal documentado,
#y el maketree no sale por ningún lado
try:
z=('muscle -maketree -in {0} -out {1} -cluster '
'neighborjoining >/dev/null 2>&1 '.format(alignd_sec, map))
os.system(z)
except:
print('Ignorando el archivo '+query+': Posible fallo de muscle')
pass
#Función que representa un árbol usando el módulo Phylo de biopython
def Phylo_maketree(map, output_name):
try:
sys.stdout = open(output_name, 'w')
tree = Phylo.read(map, 'newick')
arbol = Phylo.draw_ascii(tree)
sys.stdout.close()
sys.stdout = open('/dev/stdout', 'w')
except:
print('Ignorando el archivo '+query+': Posible fallo de muscle')
pass