def main():
    '''Function that will parse the given file and convert the tree to the
       format specified'''
    argParser = ArgumentParser(description='tree structured data converter')
    argParser.add_argument('--file',
                           type=FileType('r'),
                           action='store',
                           dest='file',
                           required=True,
                           help='file to parse')
    argParser.add_argument('--format',
                           type=str,
                           action='store',
                           default='string',
                           dest='format',
                           help='format to convert to, default = string')
    options = argParser.parse_args()
    tree_str = '\n'.join(options.file.readlines())
    options.file.close()
    node_parser = NewickParser()
    tree = node_parser.parse(tree_str)
    if options.format == 'xml':
        writer = XmlNewickWriter()
    elif options.format == 'relational':
        writer = RelationalNewickWriter()
    else:
        writer = IndentedStringNewickWriter()
    print(writer.write(tree))
예제 #2
0
def main():
    arg_parser = ArgumentParser(description="Determine leaf branch " "lengths for Newick tree.")
    arg_parser.add_argument(
        "--file", type=FileType("r"), action="store", dest="file", required=True, help="Newick file to parse"
    )
    options = arg_parser.parse_args()
    tree_str = "\n".join(options.file.readlines())
    options.file.close()
    node_parser = NewickParser()
    tree = node_parser.parse(tree_str)
    branch_lengths = compute_branch_lengths(tree)
    for taxa, length in list(branch_lengths.items()):
        print("{taxa}: {length}".format(taxa=taxa, length=length))
예제 #3
0
def main():
    arg_parser = ArgumentParser(description='Determine leaf branch '
                                'lengths for Newick tree.')
    arg_parser.add_argument('--file',
                            type=FileType('r'),
                            action='store',
                            dest='file',
                            required=True,
                            help='Newick file to parse')
    options = arg_parser.parse_args()
    tree_str = '\n'.join(options.file.readlines())
    options.file.close()
    node_parser = NewickParser()
    tree = node_parser.parse(tree_str)
    branch_lengths = compute_branch_lengths(tree)
    for taxa, length in list(branch_lengths.items()):
        print('{taxa}: {length}'.format(taxa=taxa, length=length))
def main():
    '''Function that will parse the given file and convert the tree to the
       format specified'''
    argParser = ArgumentParser(description='tree structured data converter')
    argParser.add_argument('--file', type=FileType('r'), action='store',
                           dest='file', required=True,
                           help='file to parse')
    argParser.add_argument('--format', type=str, action='store',
                           default='string', dest='format',
                           help='format to convert to, default = string')
    options = argParser.parse_args()
    tree_str = '\n'.join(options.file.readlines())
    options.file.close()
    node_parser = NewickParser()
    tree = node_parser.parse(tree_str)
    if options.format == 'xml':
        writer = XmlNewickWriter()
    elif options.format == 'relational':
        writer = RelationalNewickWriter()
    else:
        writer = IndentedStringNewickWriter()
    print(writer.write(tree))