Skip to content
Snippets Groups Projects
Commit 0b72a7a9 authored by Ariane Delrocq's avatar Ariane Delrocq
Browse files

create python function for clustalo

parent b709672e
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,42 @@ import Bio.Entrez
from Bio.SeqRecord import SeqRecord
from Bio.SubsMat.MatrixInfo import blosum62
#==============================================================================
import importlib
import os
import sys
import io
spec, m = None, None
def bali_score(ref_fasta_path, test_fasta_path):
"""Portable wrapper for the bali_score.py script.
Calculate BALI scores from a test and a reference multiple sequence alignment in FASTA format.
Reproduces the results of the bali_score C program.
"""
path = os.path.join("balibase", "bali_score.py")
global spec, m
if spec is None:
spec = importlib.util.spec_from_file_location("baliscore", path)
m = importlib.util.module_from_spec(spec)
tmp_argv = sys.argv
tmp_stdout = sys.stdout
buf = sys.stdout = io.StringIO()
sys.argv = [path, ref_fasta_path, test_fasta_path]
try:
spec.loader.exec_module(m)
finally:
sys.argv = tmp_argv
sys.stdout = tmp_stdout
buf.seek(0)
score = {}
for line in buf:
name, var = line.partition("=")[::2]
score[name.strip()] = float(var)
return score
#==============================================================================
class BalibaseTestCase(unittest.TestCase):
"""Base class to inherit by all test cases that need access to the balibase.
"""
......@@ -179,30 +215,22 @@ class AlignmentSeqTestCase(BalibaseTestCase):
print(ex_r2)
raise
# =============================================================================
# def test_multiple_align(self):
# """Tests the multiple_align function (using blosum and gap extension)."""
# #from alignementseq import multiple_align
# from Bio.Align.Applications import ClustalwCommandline
# from Bio import AlignIO
# import pip
#
# if not os.path.isfile("clustalo.py"):
# print("Fetching clustalo.py from Github...")
# urllib.request.urlretrieve(
# "https://raw.githubusercontent.com/ebi-wp/webservice-clients/master/python/clustalo.py",
# "clustalo.py")
# pip.main(["install --upgrade", "xmltramp2"])
# #pip("install --upgrade xmltramp2")
# print("Done")
# import clustalo
# # How to use: python clustalo.py --email <your@email.com> --sequence sp:wap_rat,sp:wap_mouse,sp:wap_pig
#
# for records, filename in self.get_dataset_records():
# clustalo("ariane.delrocq@polytechnique.edu", *list(records))
#
# print("Fine", filename)
# =============================================================================
def test_benchmark_multiple_align(self):
"""Tests the multiple_align function (using blosum and gap extension)."""
#from alignementseq import multiple_align
from Bio.Align.Applications import ClustalwCommandline
from Bio import AlignIO
import pip
print("Test-benchmark multiple_align")
import clustalo as cl
for records, filename in list(self.get_dataset_records())[:3]:
cl.runClustalO("ariane-la-fusee@laposte.net", "sp:wap_rat,sp:wap_mouse,sp:wap_pig", fmt='fasta')
# TODO: use real seq instead of rat, pig...
print("Fine", filename)
def save_alignments(self, NameFile):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment