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_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__(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__(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__(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 = [] # 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 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__(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 program and version line lines.append('Program: %s (%s)' % (self.program, self.version)) # set query id line qid_line = ' Query: %s' % self.id if hasattr(self, 'seq_len'): qid_line += ' (%i)' % self.seq_len if self.description: qid_line += trim_str('\n %s' % self.description, 80, '...') lines.append(qid_line) # set target line lines.append(' Target: %s' % self.target) # set hit lines if not self.hits: lines.append(' Hits: 0') else: lines.append(' Hits: %s %s %s' % ('-'*4, '-'*5, '-'*58)) pattern = '%13s %5s %56s' lines.append(pattern % ('#', '# HSP', 'ID + description'.ljust(58))) lines.append(pattern % ('-'*4, '-'*5, '-'*58)) for idx, hit in enumerate(self.hits): if idx < 30: hid_line = '%s %s' % (hit.id, hit.description) if len(hid_line) > 58: hid_line = hid_line[:55] + '...' lines.append(pattern % (idx, str(len(hit)), hid_line.ljust(58))) elif idx > len(self.hits) - 4: hid_line = '%s %s' % (hit.id, hit.description) if len(hid_line) > 58: hid_line = hid_line[:55] + '...' lines.append(pattern % (idx, str(len(hit)), hid_line.ljust(58))) elif idx == 30: lines.append('%14s' % '~~~') return '\n'.join(lines)
def __str__(self): lines = [] # set program and version line lines.append('Program: %s (%s)' % (self.program, self.version)) # set query id line qid_line = ' Query: %s' % self.id if hasattr(self, 'seq_len'): qid_line += ' (%i)' % self.seq_len if self.description: qid_line += trim_str('\n %s' % self.description, 80, '...') lines.append(qid_line) # set target line lines.append(' Target: %s' % self.target) # set hit lines if not self.hits: lines.append(' Hits: 0') else: lines.append(' Hits: %s %s %s' % ('-' * 4, '-' * 5, '-' * 58)) pattern = '%13s %5s %56s' lines.append(pattern % ('#', '# HSP', 'ID + description'.ljust(58))) lines.append(pattern % ('-' * 4, '-' * 5, '-' * 58)) for idx, hit in enumerate(self.hits): if idx < 30: hid_line = '%s %s' % (hit.id, hit.description) if len(hid_line) > 58: hid_line = hid_line[:55] + '...' lines.append(pattern % (idx, str(len(hit)), hid_line.ljust(58))) elif idx > len(self.hits) - 4: hid_line = '%s %s' % (hit.id, hit.description) if len(hid_line) > 58: hid_line = hid_line[:55] + '...' lines.append(pattern % (idx, str(len(hit)), hid_line.ljust(58))) elif idx == 30: lines.append('%14s' % '~~~') return '\n'.join(lines)
def __str__(self): """Return a human readable summary of the QueryResult object.""" lines = [] # set program and version line lines.append("Program: %s (%s)" % (self.program, self.version)) # set query id line qid_line = " Query: %s" % self.id if hasattr(self, "seq_len"): qid_line += " (%i)" % self.seq_len if self.description: qid_line += trim_str("\n %s" % self.description, 80, "...") lines.append(qid_line) # set target line lines.append(" Target: %s" % self.target) # set hit lines if not self.hits: lines.append(" Hits: 0") else: lines.append(" Hits: %s %s %s" % ("-" * 4, "-" * 5, "-" * 58)) pattern = "%13s %5s %s" lines.append(pattern % ("#", "# HSP", "ID + description")) lines.append(pattern % ("-" * 4, "-" * 5, "-" * 58)) for idx, hit in enumerate(self.hits): if idx < 30: hid_line = "%s %s" % (hit.id, hit.description) if len(hid_line) > 58: hid_line = hid_line[:55] + "..." lines.append(pattern % (idx, str(len(hit)), hid_line)) elif idx > len(self.hits) - 4: hid_line = "%s %s" % (hit.id, hit.description) if len(hid_line) > 58: hid_line = hid_line[:55] + "..." lines.append(pattern % (idx, str(len(hit)), hid_line)) elif idx == 30: lines.append("%14s" % "~~~") return "\n".join(lines)
def pair_as_kwarg_string(key, val): if isinstance(val, basestring): return "%s='%s'" % (key, _utils.trim_str(unicode(val), 60, u'...')) return "%s=%s" % (key, val)
def __str__(self): if self.name: return _utils.trim_str(self.name, 40, '...') return self.__class__.__name__
def pair_as_kwarg_string(key, val): if isinstance(val, basestring): return "%s='%s'" % (key, _utils.trim_str(as_string(val), 60, "...")) return "%s=%s" % (key, val)
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 name of the class instance.""" if self.name: return _utils.trim_str(self.name, 40, '...') return self.__class__.__name__
def __str__(self): """Return name of the class instance.""" if self.name: return _utils.trim_str(self.name, 40, "...") return self.__class__.__name__