Пример #1
0
    def list_features(self):
        """Print ASCII table with all features.

        Examples
        --------
        >>> from Bio.Seq import Seq
        >>> from pydna.seqrecord import SeqRecord
        >>> a=SeqRecord(Seq("atgtaa"))
        >>> a.add_feature(2,4)
        >>> print(a.list_features())
        +-----+---------------+-----+-----+-----+-----+------+------+
        | Ft# | Label or Note | Dir | Sta | End | Len | type | orf? |
        +-----+---------------+-----+-----+-----+-----+------+------+
        |   0 | L:ft2         | --> | 2   | 4   |   2 | misc |  no  |
        +-----+---------------+-----+-----+-----+-----+------+------+
        """
        x = _PrettyTable([
            "Ft#", "Label or Note", "Dir", "Sta", "End", "Len", "type", "orf?"
        ])
        x.align["Ft#"] = "r"  # Left align
        x.align["Label or Note"] = "l"  # Left align
        x.align["Len"] = "r"
        x.align["Sta"] = "l"
        x.align["End"] = "l"
        x.align["type"] = "l"
        x.padding_width = 1  # One space between column edges and contents
        for i, sf in enumerate(self.features):
            try:
                lbl = sf.qualifiers["label"]
            except KeyError:
                try:
                    lbl = sf.qualifiers["note"]
                except KeyError:
                    lbl = "nd"
                else:
                    lbl = "N:{}".format(" ".join(lbl).strip())
            else:
                lbl = "L:{}".format(" ".join(lbl).strip())
            x.add_row([
                i,
                lbl[:16],
                {
                    1: "-->",
                    -1: "<--",
                    0: "---",
                    None: "---"
                }[sf.strand],
                sf.location.start,
                sf.location.end,
                len(sf),
                sf.type,
                {
                    True: "yes",
                    False: "no"
                }[self.extract_feature(i).isorf()
                  or self.extract_feature(i).reverse_complement().isorf()],
            ])
        return _pretty_str(x)
 def _format(self, title, key_values):
     if len(key_values) == 0:
         return ""
     tbl = _PrettyTable(header=False)
     for k, v in key_values.iteritems():
             tbl.add_row([k, v])
     tbl.align['Field 1'] = 'l'
     tbl.align['Field 2'] = 'l'
     s = title + ":\n"
     s += tbl.__str__() + '\n'
     return s
Пример #3
0
 def _format(self, title, key_values):
     if len(key_values) == 0:
         return ""
     tbl = _PrettyTable(header=False)
     for k, v in key_values.iteritems():
             tbl.add_row([k, v])
     tbl.align['Field 1'] = 'l'
     tbl.align['Field 2'] = 'l'
     s = title + ":\n"
     s += tbl.__str__() + '\n'
     return s
Пример #4
0
 def _format(self, title, key_values):
     if len(key_values) == 0:
         return ""
     tbl = _PrettyTable(header=False)
     for k, v in six.iteritems(key_values):
         tbl.add_row([k, v])
     tbl.align["Field 1"] = "l"
     tbl.align["Field 2"] = "l"
     s = title + ":\n"
     s += tbl.__str__() + "\n"
     return s
Пример #5
0
    def __str__(self):
        """
        Print the tree summary table.
        """
        summary = _PrettyTable([
            "id", "start_level", "end_level", "start_mass", "end_mass", "size",
            "parent", "children"
        ])
        for node_id, v in self.nodes.items():
            summary.add_row([
                node_id, v.start_level, v.end_level, v.start_mass, v.end_mass,
                len(v.members), v.parent, v.children
            ])

        for col in ["start_level", "end_level", "start_mass", "end_mass"]:
            summary.float_format[col] = "5.3"

        return summary.get_string()
Пример #6
0
    def __str__(self):
        """
        Print the tree summary table.
        """
        summary = _PrettyTable(["id", "start_level", "end_level", "start_mass",
                                "end_mass", "size", "parent", "children"])
        for node_id, v in self.nodes.items():
            summary.add_row([node_id,
                             v.start_level,
                             v.end_level,
                             v.start_mass,
                             v.end_mass,
                             len(v.members),
                             v.parent,
                             v.children])

        for col in ["start_level", "end_level", "start_mass", "end_mass"]:
            summary.float_format[col] = "5.3"

        return summary.get_string()
 def _describe_fields(cls):
     """
     Return a pretty table for the class fields description.
     """
     dispatch_table = {
         'ShortestPathModel': 'sssp_model_fields',
         'GraphColoringModel': 'graph_coloring_model_fields',
         'PagerankModel': 'pagerank_model_fields',
         'ConnectedComponentsModel': 'connected_components_model_fields',
         'TriangleCountingModel': 'triangle_counting_model_fields',
         'KcoreModel': 'kcore_model_fields'
     }
     try:
         fields_description = _main.run(dispatch_table[cls.__name__], {})
         tbl = _PrettyTable(['Field', 'Description'])
         for k, v in fields_description.iteritems():
             tbl.add_row([k, v])
         tbl.align['Field'] = 'l'
         tbl.align['Description'] = 'l'
         return tbl
     except:
         raise RuntimeError('Model %s does not have fields description' % cls.__name__)
Пример #8
0
 def _describe_fields(cls):
     """
     Return a pretty table for the class fields description.
     """
     dispatch_table = {
         'ShortestPathModel': 'sssp_model_fields',
         'GraphColoringModel': 'graph_coloring_model_fields',
         'PagerankModel': 'pagerank_model_fields',
         'ConnectedComponentsModel': 'connected_components_model_fields',
         'TriangleCountingModel': 'triangle_counting_model_fields',
         'KcoreModel': 'kcore_model_fields'
     }
     try:
         fields_description = _main.run(dispatch_table[cls.__name__], {})
         tbl = _PrettyTable(['Field', 'Description'])
         for k, v in fields_description.iteritems():
             tbl.add_row([k, v])
         tbl.align['Field'] = 'l'
         tbl.align['Description'] = 'l'
         return tbl
     except:
         raise RuntimeError('Model %s does not have fields description' % cls.__name__)