Commit bf0494eb authored by Martin Larralde's avatar Martin Larralde
Browse files

Implement `__str__` for `plan7.Alignment` using `p7_nontranslated_alidisplay_Print`

parent 27bc3570
......@@ -12,6 +12,13 @@ ELIF HMMER_IMPL == "SSE":
from libhmmer.impl_sse.p7_oprofile cimport P7_OPROFILE
cdef extern from "hmmer.h" nogil:
cdef struct p7_pipeline:
pass
ctypedef p7_pipeline P7_PIPELINE
cdef extern from "hmmer.h" nogil:
cdef struct p7_alidisplay_s:
......@@ -56,11 +63,14 @@ cdef extern from "hmmer.h" nogil:
float p7_alidisplay_DecodePostProb(char pc);
char p7_alidisplay_EncodeAliPostProb(float p, float hi, float med, float lo);
# int p7_alidisplay_Print(FILE *fp, P7_ALIDISPLAY *ad, int min_aliwidth, int linewidth, P7_PIPELINE *pli);
# int p7_translated_alidisplay_Print(FILE *fp, P7_ALIDISPLAY *ad, int min_aliwidth, int linewidth, P7_PIPELINE *pli);
int p7_nontranslated_alidisplay_Print(FILE *fp, P7_ALIDISPLAY *ad, int min_aliwidth, int linewidth, int show_accessions);
int p7_alidisplay_Backconvert(const P7_ALIDISPLAY *ad, const ESL_ALPHABET *abc, ESL_SQ **ret_sq, P7_TRACE **ret_tr);
int p7_alidisplay_Sample(ESL_RANDOMNESS *rng, int N, P7_ALIDISPLAY **ret_ad);
int p7_alidisplay_Dump(FILE *fp, const P7_ALIDISPLAY *ad);
int p7_alidisplay_Compare(const P7_ALIDISPLAY *ad1, const P7_ALIDISPLAY *ad2);
# The GIL may be held there in case the FILE* is a Python file object
cdef extern from "hmmer.h":
int p7_alidisplay_Print(FILE *fp, P7_ALIDISPLAY *ad, int min_aliwidth, int linewidth, P7_PIPELINE *pli);
int p7_translated_alidisplay_Print(FILE *fp, P7_ALIDISPLAY *ad, int min_aliwidth, int linewidth, P7_PIPELINE *pli);
int p7_nontranslated_alidisplay_Print(FILE *fp, P7_ALIDISPLAY *ad, int min_aliwidth, int linewidth, int show_accessions);
......@@ -206,6 +206,31 @@ cdef class Alignment:
def __len__(self):
return self.hmm_to - self.hmm_from
def __str__(self):
assert self._ad != NULL
cdef int status
cdef object buffer = io.BytesIO()
cdef FILE* fp = fopen_obj(buffer, "w")
try:
status = libhmmer.p7_alidisplay.p7_nontranslated_alidisplay_Print(
fp,
self._ad,
0,
-1,
False,
)
if status == libeasel.eslEWRITE:
raise OSError("Failed to write alignment")
elif status != libeasel.eslOK:
raise UnexpectedError(status, "p7_alidisplay_Print")
finally:
fclose(fp)
return buffer.getvalue().decode("ascii")
# --- Properties ---------------------------------------------------------
@property
......@@ -993,7 +1018,7 @@ cdef class Cutoffs:
c._owner = self._owner
return c
def __str__(self):
def __repr__(self):
ty = type(self).__name__
return "<Pfam score cutoffs of {!r}>".format(
self._owner,
......@@ -1403,7 +1428,7 @@ cdef class EvalueParameters:
ev._evparams = self._evparams
return ev
def __str__(self):
def __repr__(self):
ty = type(self).__name__
return "<e-value parameters of {!r}>".format(
self._owner,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment