Given a taxid, this gets the expanded tree which can then be checked to
    see if the organism is a plant or not

    >>> isPlantOrigin(29760)
    True
762026
def isPlantOrigin(taxid):
    

    assert isinstance(taxid, int)

    t = TaxIDTree(taxid)
    try:
        return "Viridiplantae" in str(t)
    except AttributeError:
        raise ValueError("{0} is not a valid ID".format(taxid))
387002
def get_tree(cls, parent=None):
        
        cls = get_result_class(cls)

        if parent is None:
            # return the entire tree
            return cls.objects.all()
        if parent.is_leaf():
            return cls.objects.filter(pk=parent.pk)
        return cls.objects.filter(
            tree_id=parent.tree_id,
            lft__range=(parent.lft, parent.rgt - 1))
1069475
def import_gene_history(file_handle, tax_id, tax_id_col, id_col, symbol_col):
    

    # Make sure that tax_id is not "" or "  "
    if not tax_id or tax_id.isspace():
        raise Exception("Input tax_id is blank")

    # Make sure that tax_id exists in Organism table in the database.
    try:
        organism = Organism.objects.get(taxonomy_id=tax_id)
    except Organism.DoesNotExist:
        raise Exception('Input tax_id %s does NOT exist in Organism table. '
                        'Please add it into Organism table first.' % tax_id)

    if tax_id_col < 0 or id_col < 0 or symbol_col < 0:
        raise Exception(
            'tax_id_col, id_col and symbol_col must be positive integers')

    for line_index, line in enumerate(file_handle):
        if line.startswith('#'):  # Skip comment lines.
            continue

        fields = line.rstrip().split('\t')
        # Check input column numbers.
        chk_col_numbers(line_index + 1, len(fields), tax_id_col, id_col,
                        symbol_col)

        # Skip lines whose tax_id's do not match input tax_id.
        if tax_id != fields[tax_id_col]:
            continue

        entrez_id = fields[id_col]
        # If the gene already exists in database, set its "obsolete" attribute
        # to True; otherwise create a new obsolete Gene record in database.
        try:
            gene = Gene.objects.get(entrezid=entrez_id)
            if not gene.obsolete:
                gene.obsolete = True
                gene.save()
        except Gene.DoesNotExist:
            Gene.objects.create(entrezid=entrez_id, organism=organism,
                                systematic_name=fields[symbol_col],
                                obsolete=True)
88493
def _init_taxids(taxid, taxids):
        """"""
        ret = set()
        if taxids is not None:
            if taxids is True:
                return True
            if isinstance(taxids, int):
                ret.add(taxids)
            else:
                ret.update(taxids)
        if taxid is not None:
            ret.add(taxid)
        if not ret:
            ret.add(9606)
            # pylint: disable=superfluous-parens
            print('**NOTE: DEFAULT TAXID STORED FROM gene2go IS 9606 (human)\n')
        return ret
149836
public boolean isLeafNode()
  {
    boolean leaf = false;
    if ( (_leftChild  == null) &&
         (_rightChild == null) )
      leaf = true;
    return leaf;
  }
84906
def leaf(self, node, elem, module, path):
        """"""
        if node.i_default is None:
            nel, newm, path = self.sample_element(node, elem, module, path)
            if path is None:
                return
            if self.annots:
                nel.append(etree.Comment(
                    " type: %s " % node.search_one("type").arg))
        elif self.defaults:
            nel, newm, path = self.sample_element(node, elem, module, path)
            if path is None:
                return
            nel.text = str(node.i_default_str)
250953
def desc_taxa(taxid, ncbi, outFH, just_taxids=False):
    
    # Main feature of the script is to get all taxa within a given group.	
    descendent_taxa = ncbi.get_descendant_taxa(taxid)
    descendent_taxa_names = ncbi.translate_to_names(descendent_taxa)

    if just_taxids:
        for taxid in descendent_taxa:
            outFH.write(str(taxid) + '\n')
    else:
        for dtn, dt in zip(descendent_taxa_names, descendent_taxa):
            x = [str(x) for x in [taxid, dt, dtn]]
            outFH.write('\t'.join(x) + '\n')
724324
public function isExtensionTaxonomy()
	{
		if ( is_null( $this->isExtensionTaxonomy ) )
		{
			$this->isExtensionTaxonomy = $this->getIsExtensionTaxonomy();
		}
		return $this->isExtensionTaxonomy;
	}
275132
def extendsTree( self ):
        
        delegate = self.itemDelegate()
        if ( isinstance(delegate, XTreeWidgetDelegate) ):
            return delegate.extendsTree()
        return False
544705
function () {
				var oBinding = this.byId("tree").getBinding("items");
				if (this._sFilter) {
					oBinding.filter(new Filter({
						path: "name",
						operator: FilterOperator.Contains,
						value1: this._sFilter
					}));
					return true;
				} else {
					oBinding.filter();
					return false;
				}
			}
921195
def main(argv):
    
    import argparse
    description = 'Uses Open Tree of Life web services to try to find a taxon ID for each name supplied. ' \
                  'Using a --context-name=NAME to provide a limited taxonomic context and using the ' \
                  ' --prohibit-fuzzy-matching option can make the matching faster. If there is only' \
                  'one match finds, then it also calls the equivalent of the ot-taxon-info.py and ot-taxon-subtree.py scripts.'
    parser = argparse.ArgumentParser(prog='ot-tnrs-match-names', description=description)
    parser.add_argument('names', nargs='+', help='name(s) for which we will try to find OTT IDs')
    parser.add_argument('--context-name', default=None, type=str, required=False)
    parser.add_argument('--include-dubious',
                        action='store_true',
                        default=False,
                        required=False,
                        help='return matches to taxa that are not included the synthetic tree because their taxonomic status is doubtful')
    parser.add_argument('--subtree',
                        action='store_true',
                        default=False,
                        required=False,
                        help='print the newick representation of the taxonomic subtree if there is only one matching OTT ID')
    parser.add_argument('--include-deprecated', action='store_true', default=False, required=False)
    parser.add_argument('--prohibit-fuzzy-matching', action='store_true', default=False, required=False)
    args = parser.parse_args(argv)
    # The service takes do_approximate_matching
    # We use the opposite to make the command-line just include positive directives
    #   (as opposed to requiring --do-approximate-matching=False) so we use "not"
    do_approximate_matching = not args.prohibit_fuzzy_matching
    name_list = args.names
    if len(name_list) == 0:
        name_list = ["Homo sapiens", "Gorilla gorilla"]
        sys.stderr.write('Running a demonstration query with {}\n'.format(name_list))
    else:
        for name in name_list:
            if name.startswith('-'):
                parser.print_help()
    match_and_print(name_list,
                    context_name=args.context_name,
                    do_approximate_matching=do_approximate_matching,
                    include_dubious=args.include_dubious,
                    include_deprecated=args.include_deprecated,
                    include_subtree=args.subtree,
                    output=sys.stdout)
724537
def checkGeneTreeMatchesSpeciesTree(speciesTree, geneTree, processID):
    
    def fn(tree, l):
        if tree.internal:
            fn(tree.left, l)
            fn(tree.right, l)
        else:
            l.append(processID(tree.iD))
    l = []
    fn(speciesTree, l)
    l2 = []
    fn(geneTree, l2)
    for i in l2:
        #print "node", i, l
        assert i in l
496052
def p_identifier(self, tree):
        '''  '''
        tree.value = tree.attr
        tree.svalue = tree.attr
1116520
function isLooped(node, parent) {
    switch (parent.type) {
        case "ForStatement":
            return (
                node === parent.test ||
                node === parent.update ||
                node === parent.body
            );

        case "ForOfStatement":
        case "ForInStatement":
            return node === parent.body;

        case "WhileStatement":
        case "DoWhileStatement":
            return node === parent.test || node === parent.body;

        default:
            return false;
    }
}
1324839
def v_reference_leaf_leafref(ctx, stmt):
    """"""

    if (hasattr(stmt, 'i_leafref') and
        stmt.i_leafref is not None and
        stmt.i_leafref_expanded is False):
        path_type_spec = stmt.i_leafref
        not_req_inst = not(path_type_spec.require_instance)
        x = validate_leafref_path(ctx, stmt,
                                  path_type_spec.path_spec,
                                  path_type_spec.path_,
                                  accept_non_config_target=not_req_inst
        )
        if x is None:
            return
        ptr, expanded_path, path_list = x
        path_type_spec.i_target_node = ptr
        path_type_spec.i_expanded_path = expanded_path
        path_type_spec.i_path_list = path_list
        stmt.i_leafref_expanded = True
        if ptr is not None:
            chk_status(ctx, stmt, ptr)
            stmt.i_leafref_ptr = (ptr, path_type_spec.pos)
728045
def _get_vectors(self, tree, precomputed_info):
        
        little_m = []
        big_m = []

        leaf_nodes = sorted(tree.leaf_nodes(), key=lambda x: x.taxon.label)
        # inner nodes, sorted order
        for leaf_a, leaf_b in combinations(leaf_nodes, 2):
            mrca = tree.mrca(taxa=[leaf_a.taxon, leaf_b.taxon])
            little_m.append(precomputed_info[mrca].edges_from_root)
            big_m.append(precomputed_info[mrca].dist_from_root)
        
        # leaf nodes, sorted order
        for leaf in leaf_nodes:
            little_m.append(1)
            big_m.append(leaf.edge_length)

        return np.array(little_m), np.array(big_m)
383570
def _process_organisms(self, limit):
        

        if self.test_mode:
            graph = self.testgraph
        else:
            graph = self.graph
        model = Model(graph)
        raw = '/'.join((self.rawdir, 'organism'))
        LOG.info("processing organisms")

        line_counter = 0
        with open(raw, 'r') as f:
            filereader = csv.reader(f, delimiter='\t', quotechar='\"')
            f.readline()  # read the header row; skip
            for line in filereader:
                (organism_id, abbreviation, genus, species, common_name,
                 comment) = line
                # 1	Dmel	Drosophila	melanogaster	fruit fly
                # 2	Comp	Computational	result

                line_counter += 1

                tax_internal_id = self._makeInternalIdentifier('organism', organism_id)
                tax_label = ' '.join((genus, species))
                tax_id = tax_internal_id

                self.idhash['organism'][organism_id] = tax_id
                self.label_hash[tax_id] = tax_label

                # we won't actually add the organism to the graph,
                # unless we actually use it therefore it is added outside of
                # this function

                if self.test_mode and int(organism_id) not in self.test_keys['organism']:
                    continue

                if not self.test_mode and limit is not None and line_counter > limit:
                    pass
                else:
                    model.addClassToGraph(tax_id)
                    for s in [common_name, abbreviation]:
                        if s is not None and s.strip() != '':
                            model.addSynonym(tax_id, s)
                            model.addComment(tax_id, tax_internal_id)

        return