def _str_hsp_header(self): """Print the alignment header info (PRIVATE).""" lines = [] # set query id line qid_line = trim_str(' Query: %s %s' % (self.query_id, self.query_description), 80, '...') # set hit id line hid_line = trim_str(' Hit: %s %s' % (self.hit_id, self.hit_description), 80, '...') lines.append(qid_line) lines.append(hid_line) # coordinates query_start = getattr_str(self, 'query_start') query_end = getattr_str(self, 'query_end') hit_start = getattr_str(self, 'hit_start') hit_end = getattr_str(self, 'hit_end') # strands try: qstrand = self.query_strand hstrand = self.hit_strand except ValueError: qstrand = self.query_strand_all[0] hstrand = self.hit_strand_all[0] lines.append('Query range: [%s:%s] (%r)' % (query_start, query_end, qstrand)) lines.append(' Hit range: [%s:%s] (%r)' % (hit_start, hit_end, hstrand)) return '\n'.join(lines)
def _str_hsp_header(self): """Prints the alignment header info.""" lines = [] # set query id line qid_line = trim_str(" Query: %s %s" % (self.query_id, self.query_description), 80, "...") # set hit id line hid_line = trim_str(" Hit: %s %s" % (self.hit_id, self.hit_description), 80, "...") lines.append(qid_line) lines.append(hid_line) # coordinates query_start = getattr_str(self, "query_start") query_end = getattr_str(self, "query_end") hit_start = getattr_str(self, "hit_start") hit_end = getattr_str(self, "hit_end") # strands try: qstrand = self.query_strand hstrand = self.hit_strand except ValueError: qstrand = self.query_strand_all[0] hstrand = self.hit_strand_all[0] lines.append("Query range: [%s:%s] (%r)" % (query_start, query_end, qstrand)) lines.append(" Hit range: [%s:%s] (%r)" % (hit_start, hit_end, hstrand)) return "\n".join(lines)
def __str__(self): lines = [] # set query id line qid_line = 'Query: %s' % self.query_id if self.query_description: qid_line += trim_str('\n %s' % self.query_description, 80, '...') lines.append(qid_line) # set hit id line hid_line = ' Hit: %s' % self.id if hasattr(self, 'seq_len'): hid_line += ' (%i)' % self.seq_len if self.description: hid_line += trim_str('\n %s' % self.description, 80, '...') lines.append(hid_line) # set hsp line and table if not self.hsps: lines.append(' HSPs: ?') else: lines.append(' HSPs: %s %s %s %s %s %s' % ('-'*4, '-'*8, '-'*9, '-'*6, '-'*15, '-'*21)) pattern = '%11s %8s %9s %6s %15s %21s' lines.append(pattern % ('#', 'E-value', 'Bit score', 'Span', 'Query range', 'Hit range')) lines.append(pattern % ('-'*4, '-'*8, '-'*9, '-'*6, '-'*15, '-'*21)) for idx, hsp in enumerate(self.hsps): # evalue evalue = getattr_str(hsp, 'evalue', fmt='%.2g') # bitscore bitscore = getattr_str(hsp, 'bitscore', fmt='%.2f') # alignment length aln_span = getattr_str(hsp, 'aln_span') # query region query_start = getattr_str(hsp, 'query_start') query_end = getattr_str(hsp, 'query_end') query_range = '[%s:%s]' % (query_start, query_end) # max column length is 18 query_range = trim_str(query_range, 15, '~]') # hit region hit_start = getattr_str(hsp, 'hit_start') hit_end = getattr_str(hsp, 'hit_end') hit_range = '[%s:%s]' % (hit_start, hit_end) hit_range = trim_str(hit_range, 21, '~]') # append the hsp row lines.append(pattern % (str(idx), evalue, bitscore, aln_span, query_range, hit_range)) return '\n'.join(lines)
def _str_aln(self): lines = [] # alignment length aln_span = getattr_str(self, 'aln_span') lines.append(' Fragments: 1 (%s columns)' % aln_span) # sequences if self.query is not None and self.hit is not None: try: qseq = str(self.query.seq) except AttributeError: # query is None qseq = '?' try: hseq = str(self.hit.seq) except AttributeError: # hit is None hseq = '?' # similarity line simil = '' if 'similarity' in self.aln_annotation and \ isinstance(self.aln_annotation.get('similarity'), basestring): simil = self.aln_annotation['similarity'] if self.aln_span <= 67: lines.append("%10s - %s" % ('Query', qseq)) if simil: lines.append(" %s" % simil) lines.append("%10s - %s" % ('Hit', hseq)) else: # adjust continuation character length, so we don't display # the same residues twice if self.aln_span - 66 > 3: cont = '~' * 3 else: cont = '~' * (self.aln_span - 66) lines.append("%10s - %s%s%s" % ('Query', qseq[:59], cont, qseq[-5:])) if simil: lines.append(" %s%s%s" % (simil[:59], cont, simil[-5:])) lines.append("%10s - %s%s%s" % ('Hit', hseq[:59], cont, hseq[-5:])) return '\n'.join(lines)
def __str__(self): """Return a human readable summary of the HSP object.""" lines = [] # set hsp info line statline = [] # evalue evalue = getattr_str(self, "evalue", fmt="%.2g") statline.append("evalue " + evalue) # bitscore bitscore = getattr_str(self, "bitscore", fmt="%.2f") statline.append("bitscore " + bitscore) lines.append("Quick stats: " + "; ".join(statline)) if len(self.fragments) == 1: return "\n".join([ self._str_hsp_header(), "\n".join(lines), self.fragments[0]._str_aln() ]) else: lines.append(" Fragments: %s %s %s %s" % ("-" * 3, "-" * 14, "-" * 22, "-" * 22)) pattern = "%16s %14s %22s %22s" lines.append(pattern % ("#", "Span", "Query range", "Hit range")) lines.append(pattern % ("-" * 3, "-" * 14, "-" * 22, "-" * 22)) for idx, block in enumerate(self.fragments): # set hsp line and table # alignment span aln_span = getattr_str(block, "aln_span") # query region query_start = getattr_str(block, "query_start") query_end = getattr_str(block, "query_end") query_range = "[%s:%s]" % (query_start, query_end) # max column length is 20 query_range = trim_str(query_range, 22, "~]") # hit region hit_start = getattr_str(block, "hit_start") hit_end = getattr_str(block, "hit_end") hit_range = "[%s:%s]" % (hit_start, hit_end) hit_range = trim_str(hit_range, 22, "~]") # append the hsp row lines.append(pattern % (str(idx), aln_span, query_range, hit_range)) return self._str_hsp_header() + "\n" + "\n".join(lines)
def __str__(self): lines = [] # set hsp info line statline = [] # evalue evalue = getattr_str(self, 'evalue', fmt='%.2g') statline.append('evalue ' + evalue) # bitscore bitscore = getattr_str(self, 'bitscore', fmt='%.2f') statline.append('bitscore ' + bitscore) lines.append('Quick stats: ' + '; '.join(statline)) if len(self.fragments) == 1: return '\n'.join([ self._str_hsp_header(), '\n'.join(lines), self.fragments[0]._str_aln() ]) else: lines.append(' Fragments: %s %s %s %s' % ('-' * 3, '-' * 14, '-' * 22, '-' * 22)) pattern = '%16s %14s %22s %22s' lines.append(pattern % ('#', 'Span', 'Query range', 'Hit range')) lines.append(pattern % ('-' * 3, '-' * 14, '-' * 22, '-' * 22)) for idx, block in enumerate(self.fragments): # set hsp line and table # alignment span aln_span = getattr_str(block, 'aln_span') # query region query_start = getattr_str(block, 'query_start') query_end = getattr_str(block, 'query_end') query_range = '[%s:%s]' % (query_start, query_end) # max column length is 20 query_range = trim_str(query_range, 22, '~]') # hit region hit_start = getattr_str(block, 'hit_start') hit_end = getattr_str(block, 'hit_end') hit_range = '[%s:%s]' % (hit_start, hit_end) hit_range = trim_str(hit_range, 22, '~]') # append the hsp row lines.append(pattern % (str(idx), aln_span, query_range, hit_range)) return self._str_hsp_header() + '\n' + '\n'.join(lines)
def _str_aln(self): lines = [] # alignment length aln_span = getattr_str(self, "aln_span") lines.append(" Fragments: 1 (%s columns)" % aln_span) # sequences if self.query is not None and self.hit is not None: try: qseq = str(self.query.seq) except AttributeError: # query is None qseq = "?" try: hseq = str(self.hit.seq) except AttributeError: # hit is None hseq = "?" # similarity line simil = "" if "similarity" in self.aln_annotation and isinstance( self.aln_annotation.get("similarity"), str ): simil = self.aln_annotation["similarity"] if self.aln_span <= 67: lines.append("%10s - %s" % ("Query", qseq)) if simil: lines.append(" %s" % simil) lines.append("%10s - %s" % ("Hit", hseq)) else: # adjust continuation character length, so we don't display # the same residues twice if self.aln_span - 66 > 3: cont = "~" * 3 else: cont = "~" * (self.aln_span - 66) lines.append("%10s - %s%s%s" % ("Query", qseq[:59], cont, qseq[-5:])) if simil: lines.append(" %s%s%s" % (simil[:59], cont, simil[-5:])) lines.append("%10s - %s%s%s" % ("Hit", hseq[:59], cont, hseq[-5:])) return "\n".join(lines)
def _str_aln(self): lines = [] # alignment length aln_span = getattr_str(self, "aln_span") lines.append(" Fragments: 1 (%s columns)" % aln_span) # sequences if self.query is not None and self.hit is not None: try: qseq = str(self.query.seq) except AttributeError: # query is None qseq = "?" try: hseq = str(self.hit.seq) except AttributeError: # hit is None hseq = "?" # homology line homol = "" if "homology" in self.aln_annotation: homol = self.aln_annotation["homology"] if self.aln_span <= 67: lines.append("%10s - %s" % ("Query", qseq)) if homol: lines.append(" %s" % homol) lines.append("%10s - %s" % ("Hit", hseq)) else: # adjust continuation character length, so we don't display # the same residues twice if self.aln_span - 66 > 3: cont = "~" * 3 else: cont = "~" * (self.aln_span - 66) lines.append("%10s - %s%s%s" % ("Query", qseq[:59], cont, qseq[-5:])) if homol: lines.append(" %s%s%s" % (homol[:59], cont, homol[-5:])) lines.append("%10s - %s%s%s" % ("Hit", hseq[:59], cont, hseq[-5:])) return "\n".join(lines)
def __str__(self): lines = [] # set hsp info line statline = [] # evalue evalue = getattr_str(self, 'evalue', fmt='%.2g') statline.append('evalue ' + evalue) # bitscore bitscore = getattr_str(self, 'bitscore', fmt='%.2f') statline.append('bitscore ' + bitscore) lines.append('Quick stats: ' + '; '.join(statline)) if len(self.fragments) == 1: return '\n'.join([self._str_hsp_header(), '\n'.join(lines), self.fragments[0]._str_aln()]) else: lines.append(' Fragments: %s %s %s %s' % ('-'*3, '-'*14, '-'*22, '-'*22)) pattern = '%16s %14s %22s %22s' lines.append(pattern % ('#', 'Span', 'Query range', 'Hit range')) lines.append(pattern % ('-'*3, '-'*14, '-'*22, '-'*22)) for idx, block in enumerate(self.fragments): # set hsp line and table # alignment span aln_span = getattr_str(block, 'aln_span') # query region query_start = getattr_str(block, 'query_start') query_end = getattr_str(block, 'query_end') query_range = '[%s:%s]' % (query_start, query_end) # max column length is 20 query_range = trim_str(query_range, 22, '~]') # hit region hit_start = getattr_str(block, 'hit_start') hit_end = getattr_str(block, 'hit_end') hit_range = '[%s:%s]' % (hit_start, hit_end) hit_range = trim_str(hit_range, 22, '~]') # append the hsp row lines.append(pattern % (str(idx), aln_span, query_range, hit_range)) return self._str_hsp_header() + '\n' + '\n'.join(lines)
def __str__(self): lines = [] # set hsp info line statline = [] # evalue evalue = getattr_str(self, "evalue", fmt="%.2g") statline.append("evalue " + evalue) # bitscore bitscore = getattr_str(self, "bitscore", fmt="%.2f") statline.append("bitscore " + bitscore) lines.append("Quick stats: " + "; ".join(statline)) if len(self.fragments) == 1: return "\n".join([self._str_hsp_header(), "\n".join(lines), self.fragments[0]._str_aln()]) else: lines.append(" Fragments: %s %s %s %s" % ("-" * 3, "-" * 14, "-" * 22, "-" * 22)) pattern = "%16s %14s %22s %22s" lines.append(pattern % ("#", "Span", "Query range", "Hit range")) lines.append(pattern % ("-" * 3, "-" * 14, "-" * 22, "-" * 22)) for idx, block in enumerate(self.fragments): # set hsp line and table # alignment span aln_span = getattr_str(block, "aln_span") # query region query_start = getattr_str(block, "query_start") query_end = getattr_str(block, "query_end") query_range = "[%s:%s]" % (query_start, query_end) # max column length is 20 query_range = trim_str(query_range, 22, "~]") # hit region hit_start = getattr_str(block, "hit_start") hit_end = getattr_str(block, "hit_end") hit_range = "[%s:%s]" % (hit_start, hit_end) hit_range = trim_str(hit_range, 22, "~]") # append the hsp row lines.append(pattern % (str(idx), aln_span, query_range, hit_range)) return self._str_hsp_header() + "\n" + "\n".join(lines)
def __str__(self): """Return a human readable summary of the Hit object.""" lines = [] # set query id line qid_line = "Query: %s" % self.query_id if self.query_description: qid_line += trim_str("\n %s" % self.query_description, 80, "...") lines.append(qid_line) # set hit id line hid_line = " Hit: %s" % self.id if hasattr(self, "seq_len"): hid_line += " (%i)" % self.seq_len if self.description: hid_line += trim_str("\n %s" % self.description, 80, "...") lines.append(hid_line) # set attributes lines for key, value in sorted(self.attributes.items()): lines.append(" %s: %s" % (key, value)) # set dbxrefs line if self.dbxrefs: lines.append("Database cross-references: " + ", ".join(self.dbxrefs)) # set hsp line and table if not self.hsps: lines.append(" HSPs: ?") else: lines.append( " HSPs: %s %s %s %s %s %s" % ("-" * 4, "-" * 8, "-" * 9, "-" * 6, "-" * 15, "-" * 21)) pattern = "%11s %8s %9s %6s %15s %21s" lines.append(pattern % ("#", "E-value", "Bit score", "Span", "Query range", "Hit range")) lines.append( pattern % ("-" * 4, "-" * 8, "-" * 9, "-" * 6, "-" * 15, "-" * 21)) for idx, hsp in enumerate(self.hsps): # evalue evalue = getattr_str(hsp, "evalue", fmt="%.2g") # bitscore bitscore = getattr_str(hsp, "bitscore", fmt="%.2f") # alignment length aln_span = getattr_str(hsp, "aln_span") # query region query_start = getattr_str(hsp, "query_start") query_end = getattr_str(hsp, "query_end") query_range = "[%s:%s]" % (query_start, query_end) # max column length is 18 query_range = trim_str(query_range, 15, "~]") # hit region hit_start = getattr_str(hsp, "hit_start") hit_end = getattr_str(hsp, "hit_end") hit_range = "[%s:%s]" % (hit_start, hit_end) hit_range = trim_str(hit_range, 21, "~]") # append the hsp row lines.append(pattern % (str(idx), evalue, bitscore, aln_span, query_range, hit_range)) return "\n".join(lines)
def __str__(self): """Return a human readable summary of the Hit object.""" lines = [] # set query id line qid_line = 'Query: %s' % self.query_id if self.query_description: qid_line += trim_str('\n %s' % self.query_description, 80, '...') lines.append(qid_line) # set hit id line hid_line = ' Hit: %s' % self.id if hasattr(self, 'seq_len'): hid_line += ' (%i)' % self.seq_len if self.description: hid_line += trim_str('\n %s' % self.description, 80, '...') lines.append(hid_line) # set attributes lines for key, value in sorted(self.attributes.items()): lines.append(' %s: %s' % (key, value)) # set dbxrefs line if self.dbxrefs: lines.append("Database cross-references: " + ", ".join(self.dbxrefs)) # set hsp line and table if not self.hsps: lines.append(' HSPs: ?') else: lines.append( ' HSPs: %s %s %s %s %s %s' % ('-' * 4, '-' * 8, '-' * 9, '-' * 6, '-' * 15, '-' * 21)) pattern = '%11s %8s %9s %6s %15s %21s' lines.append(pattern % ('#', 'E-value', 'Bit score', 'Span', 'Query range', 'Hit range')) lines.append( pattern % ('-' * 4, '-' * 8, '-' * 9, '-' * 6, '-' * 15, '-' * 21)) for idx, hsp in enumerate(self.hsps): # evalue evalue = getattr_str(hsp, 'evalue', fmt='%.2g') # bitscore bitscore = getattr_str(hsp, 'bitscore', fmt='%.2f') # alignment length aln_span = getattr_str(hsp, 'aln_span') # query region query_start = getattr_str(hsp, 'query_start') query_end = getattr_str(hsp, 'query_end') query_range = '[%s:%s]' % (query_start, query_end) # max column length is 18 query_range = trim_str(query_range, 15, '~]') # hit region hit_start = getattr_str(hsp, 'hit_start') hit_end = getattr_str(hsp, 'hit_end') hit_range = '[%s:%s]' % (hit_start, hit_end) hit_range = trim_str(hit_range, 21, '~]') # append the hsp row lines.append(pattern % (str(idx), evalue, bitscore, aln_span, query_range, hit_range)) return '\n'.join(lines)
def __str__(self): lines =[] qid_line = 'Query: %s' % self.query_id qlength_line = 'Length: %i' % self.query_length lines.append(qid_line) lines.append(qlength_line) if not self.hsps: lines.append(' HSPs: ?') else: lines.append(' HSPs: %s %s %s %s %s %s %s %s %s %s' % ('-'*4, '-'*8, '-'*9, '-'*6, '-'*6, '-'*15, '-'*21, '-'*58, '-'*15, '-'*7)) pattern = '%11s %8s %9s %6s %6s %15s %21s %58s %15s %7s' lines.append(pattern % ('#', 'E-value', 'Bit score', 'ID (%)','Span', 'Query range', 'Hit range', 'Contig', 'Contig Length', 'Strand')) lines.append(pattern % ('-'*4, '-'*8, '-'*9, '-'*6, '-'*6, '-'*15, '-'*21, '-'*58, '-'*15, '-'*7)) for idx, hsp in enumerate(self.hsps): # evalue evalue = getattr_str(hsp, 'evalue', fmt='%.2g') # bitscore bitscore = getattr_str(hsp, 'bitscore', fmt='%.2f') # identities identity = getattr_str(hsp, 'identity', fmt='%4.2f') # alignment length aln_span = getattr_str(hsp, 'aln_span') # query region query_start = getattr_str(hsp, 'query_start') query_end = getattr_str(hsp, 'query_end') query_range = '[%s:%s]' % (query_start, query_end) # max column length is 18 query_range = trim_str(query_range, 15, '~]') # hit region hit_start = getattr_str(hsp, 'hit_start') hit_end = getattr_str(hsp, 'hit_end') hit_range = '[%s:%s]' % (hit_start, hit_end) hit_range = trim_str(hit_range, 21, '~]') # contig id contig_id = getattr_str(hsp, 'hit_id') # contig length contig_length = getattr_str(hsp, 'hit_length') # strand strand = getattr_str(hsp, 'strand') # append the hsp row lines.append(pattern % (str(idx), evalue, bitscore, identity, aln_span, query_range, hit_range, contig_id, contig_length, strand)) return '\n'.join(lines)
def __str__(self): lines = [] qid_line = 'Query: %s' % self.query_id qlength_line = 'Length: %i' % self.query_length lines.append(qid_line) lines.append(qlength_line) if not self.hsps: lines.append(' HSPs: ?') else: lines.append(' HSPs: %s %s %s %s %s %s %s %s %s %s' % ('-' * 4, '-' * 8, '-' * 9, '-' * 6, '-' * 6, '-' * 15, '-' * 21, '-' * 58, '-' * 15, '-' * 7)) pattern = '%11s %8s %9s %6s %6s %15s %21s %58s %15s %7s' lines.append( pattern % ('#', 'E-value', 'Bit score', 'ID (%)', 'Span', 'Query range', 'Hit range', 'Contig', 'Contig Length', 'Strand')) lines.append(pattern % ('-' * 4, '-' * 8, '-' * 9, '-' * 6, '-' * 6, '-' * 15, '-' * 21, '-' * 58, '-' * 15, '-' * 7)) for idx, hsp in enumerate(self.hsps): # evalue evalue = getattr_str(hsp, 'evalue', fmt='%.2g') # bitscore bitscore = getattr_str(hsp, 'bitscore', fmt='%.2f') # identities identity = getattr_str(hsp, 'identity', fmt='%4.2f') # alignment length aln_span = getattr_str(hsp, 'aln_span') # query region query_start = getattr_str(hsp, 'query_start') query_end = getattr_str(hsp, 'query_end') query_range = '[%s:%s]' % (query_start, query_end) # max column length is 18 query_range = trim_str(query_range, 15, '~]') # hit region hit_start = getattr_str(hsp, 'hit_start') hit_end = getattr_str(hsp, 'hit_end') hit_range = '[%s:%s]' % (hit_start, hit_end) hit_range = trim_str(hit_range, 21, '~]') # contig id contig_id = getattr_str(hsp, 'hit_id') # contig length contig_length = getattr_str(hsp, 'hit_length') # strand strand = getattr_str(hsp, 'strand') # append the hsp row lines.append( pattern % (str(idx), evalue, bitscore, identity, aln_span, query_range, hit_range, contig_id, contig_length, strand)) return '\n'.join(lines)