minorg.blast module

class minorg.blast.BlastHSP(hsp, query, subject)[source]

Bases: object

Class that binds HSP object with QueryResult and Hit as query and subject respectively.

__init__(hsp, query, subject)[source]
property btop[source]
expand_btop_str(include_unaligned=False)[source]
Expands btop to a string of characters of length equal to alignment, where:

‘.’ is a match, ‘m’ is a mismatch, ‘i’ is an insertion in the query, ‘d’ is a deletion in the query.

Parameters

include_unaligned (bool) – add space character for each unaligned position at 3’ and 5’ ends

Returns

Expanded btop pattern

Return type

str

expand_btop_tuple(rvs_index=False, include_unaligned=False)[source]

Calls str_expand_btop and groups expanded btop to a tuple of characters of length equal to aligned query, where:

‘.’ is a match, ‘m’ is a mismatch, ‘i’ is an insertion in the query, ‘d’ is a deletion in the query (deletion between N and N+1 will be grouped with position N+1 if rvs_index=False else N).

Parameters

rvs_index (bool) – default=False. A deletion between positions N and N+1 will be grouped with: position N+1 if rvs_index=False; position N, if rvs_index=True.

Returns

Expanded btop pattern

Return type

tuple of str

num_deletion(start=None, end=None, rvs_index=False)[source]

Returns number of deletions relative to subject (that is, one or more bases that is/are present in the query but not in the subject).

Parameters
  • start (int) – optional, start position (default=0)

  • end (int) – optional, end position (non-inclusive) (default=<query length (self.qlen))

  • rvs_index (bool) – used when fmt=tuple; deletion between N and N+1 will be grouped with position N+1 if rvs_index=False else N

Returns

Number of deletions within range

Return type

int

num_gap(start=None, end=None, rvs_index=False)[source]

Returns number of gaps.

Parameters
  • start (int) – optional, start position (default=0)

  • end (int) – optional, end position (non-inclusive) (default=<query length (self.qlen))

  • rvs_index (bool) – used when fmt=tuple; deletion between N and N+1 will be grouped with position N+1 if rvs_index=False else N

Returns

Number of gaps within range

Return type

int

num_insertion(start=None, end=None)[source]

Returns number of insertions relative to subject (that is, one or more bases that is/are present in the subject but not in the query).

Parameters
  • start (int) – optional, start position (default=0)

  • end (int) – optional, end position (non-inclusive) (default=<query length (self.qlen))

Returns

Number of insertions within range

Return type

int

num_mismatch(start=None, end=None)[source]

Returns number of mismatches.

Parameters
  • start (int) – optional, start position (default=0)

  • end (int) – optional, end position (non-inclusive) (default=<query length (self.qlen))

Returns

Number of mismatches within range

Return type

int

parse_btop()[source]
splice_expanded_btop(start=None, end=None, fmt=<class 'tuple'>, rvs_index=False, include_unaligned=True)[source]

Returns expanded btop spliced to specified range and in specified format

Parameters
  • start (int) – optional, start position (default=0)

  • end (int) – optional, end position (non-inclusive) (default=<query length (self.qlen))

  • fmt (type) – str or tuple; return expanded btop type

  • rvs_index (bool) – used when fmt=tuple; deletion between N and N+1 will be grouped with position N+1 if rvs_index=False else N

  • unaligned (include) – add space character for each unaligned position at 3’ and 5’ ends

Returns

Expanded btop spliced to specified range

Return type

str or tuple

class minorg.blast.BlastNR(query, blastf, header, fout, directory=None, keep_tmp=False, **kwargs)[source]

Bases: object

__init__(query, blastf, header, fout, directory=None, keep_tmp=False, **kwargs)[source]
blast()[source]
collapse_query(fout_fasta=None, fout_map=None)[source]
expand(write=True)[source]
class minorg.blast.BlastResult(filename, fmt, **kwargs)[source]

Bases: object

Generator that reads blast-tab format and yields BlastHSP, which stores a HSP object with its associated QueryResult and Hit objects as attributes query and subject respectively.

__init__(filename, fmt, **kwargs)[source]

Create a BlastResult object.

Parameters
  • filename (str) – path to file

  • fmt (str) – file format (e.g. ‘blast-tab’, ‘blast-xml’)

  • **kwargs – additional arguments for SearchIO (notably, fields)

minorg.blast.blast(blastf, header, fout, append=False, dir=None, outfmt=6, **kwargs)[source]
minorg.blast.blast6(blastf, header, fout, **kwargs)[source]
minorg.blast.blast6multi(blastf, header, fout, subjects, threshold=None, n=None, metric=None, dir=None, **kwargs)[source]
minorg.blast.blast6threshold(blastf, header, fout, threshold=0, metric='bitscore', **kwargs)[source]
minorg.blast.blast6topn(blastf, header, fout, n=1, metric='bitscore', **kwargs)[source]
minorg.blast.filter_blast6_threshold(fname, fout, threshold=0, metric='bitscore')[source]
minorg.blast.filter_blast6_topn(fname, fout, n=1, metric='bitscore')[source]
minorg.blast.filter_rpsblast_for_domain(fname, *pssmids, fout=None)[source]