def _insert_genome_into_species_tree(meth, genome, neighbor_count, out_tree):
    """ Insert a Genome into a global genome tree composed of 49 conserved COGs [20]

    :param genome: a Genome to insert into the tree [20.1]
    :type genome: kbtypes.KBaseGenomes.Genome
    :ui_name genome: Genome ID
    :param neighbor_count: number of closest public genomes the tree will contain. (optional, default value is 100) [20.2]
    :type neighbor_count: kbtypes.Unicode
    :ui_name neighbor_count: Neighbor public genome count
    :param out_tree: Output species tree ID. If empty, an ID will be chosen randomly. [20.3]
    :type out_tree: kbtypes.KBaseTrees.Tree
    :ui_name out_tree: Output species tree ID
    :return: Species Tree Result
    :rtype: kbtypes.Unicode
    :output_widget: kbaseTree
    """
    meth.stages = 2
    meth.advance("Instantiating tree construction job...")
    token, workspace = meth.token, meth.workspace_id
    if not out_tree:
        out_tree = "sptree_" + ''.join([chr(random.randrange(0, 26) + ord('A')) for _ in xrange(8)])
    treeClient = KBaseTrees(url = service.URLS.trees, token = token)
    construct_species_tree_params = {
        'new_genomes': [workspace + '/' + genome], 
        'use_ribosomal_s9_only': 0, 
        'out_workspace': workspace, 
        'out_tree_id': out_tree, 
    }
    if neighbor_count:
        construct_species_tree_params['nearest_genome_count'] = int(neighbor_count)
    job_id = treeClient.construct_species_tree(construct_species_tree_params)
    return json.dumps({'treeID': out_tree, 'workspaceID': workspace, 'height':'500px', 'jobID': job_id})
def _insert_genome_set_into_species_tree(meth, genome_set, neighbor_count, out_tree):
    """ Insert a Genome Set into a global genome tree composed of 50 conserved COGs [23]

    :param genome_set: a Genome Set to insert into the tree [23.1]
    :type genome_set: kbtypes.KBaseSearch.GenomeSet
    :ui_name genome_set: Genome Set ID
    :param neighbor_count: number of closest public genomes the tree will contain. (optional, default value is 100) [23.2]
    :type neighbor_count: kbtypes.Unicode
    :ui_name neighbor_count: Neighbor public genome count
    :param out_tree: Output species tree ID. If empty, an ID will be chosen randomly. [23.3]
    :type out_tree: kbtypes.KBaseTrees.Tree
    :ui_name out_tree: Output species tree ID
    :return: Species Tree Result
    :rtype: kbtypes.Unicode
    :output_widget: kbaseTree
    """
    meth.stages = 2
    meth.advance("Instantiating tree construction job...")
    token, workspace = meth.token, meth.workspace_id
    if not out_tree:
        out_tree = "sptree_" + ''.join([chr(random.randrange(0, 26) + ord('A')) for _ in xrange(8)])
    
    ws = workspaceService(service.URLS.workspace, token=token)
    data = ws.get_objects([{'ref': workspace+'/'+genome_set}])[0]
    genome_set_elements = data['data']['elements']
    genome_refs = []
    for key in genome_set_elements:
        genome_refs.append(genome_set_elements[key]['ref'])
    treeClient = KBaseTrees(url = service.URLS.trees, token = token)
    construct_species_tree_params = {
        'new_genomes': genome_refs, 
        'use_ribosomal_s9_only': 0, 
        'out_workspace': workspace, 
        'out_tree_id': out_tree, 
    }
    if neighbor_count:
        construct_species_tree_params['nearest_genome_count'] = int(neighbor_count)
    job_id = treeClient.construct_species_tree(construct_species_tree_params)
    return json.dumps({'treeID': out_tree, 'workspaceID': workspace, 'height':'500px', 'jobID': job_id})