Returns a list of assigned taxa from an RDP classification line
354230
def parse_rdp_assignment(line):
    
    toks = line.strip().split('\t')
    seq_id = toks.pop(0)
    direction = toks.pop(0)
    if ((len(toks) % 3) != 0):
        raise ValueError(
            "Expected assignments in a repeating series of (rank, name, "
            "confidence), received %s" % toks)
    assignments = []
    # Fancy way to create list of triples using consecutive items from
    # input.  See grouper function in documentation for itertools for
    # more general example.
    itoks = iter(toks)
    for taxon, rank, confidence_str in zip(itoks, itoks, itoks):
        if not taxon:
            continue
        assignments.append((taxon.strip('"'), rank, float(confidence_str)))
    return seq_id, direction, assignments
316041
def _slice(self, level):
        ''''''
        if level >= len(self.taxonomy):
            raise IndexError('Level greater than size of taxonomy')
        res = []
        for ident in sorted(list(self.keys())):
            res.append((self[ident]['taxref'], self[ident]['lineage'][level]))
        return res
579653
def filter_taxa(records, taxids, unclassified=False, discard=False):
    '''
     
    '''
    taxids = set(taxids)
    kept_records = []
    ncbi = ete3.NCBITaxa()
    unclassified_taxids = {0,1}
    for r in records:
        taxid, rank, sciname, lineage = r.description.strip().partition(' ')[2].split('|')
        taxid = int(taxid)
        lineage = set(ncbi.get_lineage(taxid) or [0])  # lineage defined twice?
        intersection = lineage & taxids
        if taxid in unclassified_taxids and unclassified:
            kept_records.append(r)
        elif intersection and not discard:
            kept_records.append(r)
        elif not intersection and discard and taxid not in unclassified_taxids:
            kept_records.append(r)

    return kept_records
365373
def get_specs(self,data):
        
    # sort the specimen names
    #
#        print "calling get_specs()"
        speclist=[]
        for rec in data:
          spec=rec["er_specimen_name"]
          if spec not in speclist:speclist.append(spec)
        speclist.sort()
        #print speclist
        return speclist
552942
def get_lines(data_nts, prtfmt=None, nt_fields=None, **kws):
    """"""
    lines = []
    # optional keyword args: prt_if sort_by
    if prtfmt is None:
        prtfmt = mk_fmtfld(data_nts[0], kws.get('joinchr', ' '), kws.get('eol', '\n'))
    # if nt_fields arg is None, use fields from prtfmt string.
    if nt_fields is not None:
        _chk_flds_fmt(nt_fields, prtfmt)
    if 'sort_by' in kws:
        data_nts = sorted(data_nts, key=kws['sort_by'])
    prt_if = kws.get('prt_if', None)
    for data_nt in data_nts:
        if prt_if is None or prt_if(data_nt):
            lines.append(prtfmt.format(**data_nt._asdict()))
    return lines
791680
def from_text_list(name, ttl, rdclass, rdtype, text_rdatas):
    

    if isinstance(name, (str, unicode)):
        name = dns.name.from_text(name, None)
    if isinstance(rdclass, (str, unicode)):
        rdclass = dns.rdataclass.from_text(rdclass)
    if isinstance(rdtype, (str, unicode)):
        rdtype = dns.rdatatype.from_text(rdtype)
    r = RRset(name, rdclass, rdtype)
    r.update_ttl(ttl)
    for t in text_rdatas:
        rd = dns.rdata.from_text(r.rdclass, r.rdtype, t)
        r.add(rd)
    return r
756374
def get_lines(self):
        
        with open(self.path, "r") as data:
            self.lines = data.readlines()  # store data in arrays

        return self.lines
80233
def get_species(species_id):
    '''  '''
    result = _get(species_id, settings.SPECIES)
    return Species(result.content)
907904
def extract_ast_species(ast):
    """"""

    species_id = "None"
    species_label = "None"
    species = [
        (species_id, species_label) for (species_id, species_label) in ast.species if species_id
    ]

    if len(species) == 1:
        (species_id, species_label) = species[0]

    if not species_id:
        species_id = "None"
        species_label = "None"

    log.debug(f"AST Species: {ast.species}  Species: {species}  SpeciesID: {species_id}")

    return (species_id, species_label)
376983
def __get_overall_data(self, x):
        
        if isinstance(x, dict):
            if "sensorGenus" in x:
                if x["sensorGenus"] and x["sensorGenus"] not in self.lsts_tmp["genus"]:
                    self.lsts_tmp["genus"].append(x["sensorGenus"])
            if "sensorSpecies" in x:
                if x["sensorSpecies"] and x["sensorSpecies"] not in self.lsts_tmp["species"]:
                    self.lsts_tmp["species"].append(x["sensorSpecies"])
            if "archiveType" in x:
                if x["archiveType"] and x["archiveType"] not in self.lsts_tmp["archive"]:
                    self.lsts_tmp["archive"].append(x["archiveType"])
            if "QCnotes" in x:
                if x["QCnotes"] and x["QCnotes"] not in self.lsts_tmp["qc"]:
                    self.lsts_tmp["qc"].append(x["QCnotes"])

            for k, v in x.items():
                if isinstance(v, dict):
                    self.__get_overall_data(v)
                elif isinstance(v, list):
                    self.__get_overall_data(v)
        elif isinstance(x, list):
            for i in x:
                self.__get_overall_data(i)

        return x
889363
def collect_by_type(self, typ):
        '''
        '''
        nodes = []
        if isinstance(self, typ):
            nodes.append(self)
        for c in self:
            nodes.extend(c.collect_by_type(typ))
        return nodes
1128619
def list_data_type(type_list):
    """"""
    data_type = []
    for item in type_list:
        match = re.match(r"(\d+)(.+)", item)
        if not match:
            reps = 1
            if item[0] in "FfEegG":
                data_type.append("REAL")
            elif item[0] in "Ii":
                data_type.append("INTEGER")
        else:
            reps = match.group(1)
            fmt = match.group(2)
            if "(" in fmt and "," in fmt:
                fmt = fmt[1:-1].split(",")
            elif "(" in fmt:
                fmt = [fmt[1:-1]]
            else:
                fmt = [fmt]
            for i in range(int(reps)):
                for ft in fmt:
                    if ft[0] in "FfEegG":
                        data_type.append("REAL")
                    elif ft[0] in "Ii":
                        data_type.append("INTEGER")
    return data_type
359947
def get_collections(self):
        """"""
        if not self.quiet:
            print
            print "Finding " + self.current_collection_type + "s..."

        self.compute_collections()

        if not self.quiet:
            print self.current_similarity_measure, self.current_collection_type, "information:"
            table_contents = [("Collection","Indices","Size")]
            for (i, j, k) in zip(self.collection_indices,self.collection_sizes,self.collection_list):
                table_contents.append(([unit.text for unit in k], i, j))
            print_table(table_contents)
1244550
def search(self,
               id_list: Iterable,
               negated_ids: Iterable,
               limit: Optional[int],
               taxon_filter: Optional,
               category_filter: Optional,
               method: Optional)-> SimResult:
        
        pass
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')
329600
def get_children(engine, parent_ids, rank='species', schema=None):
    

    if not parent_ids:
        return []

    nodes = schema + '.nodes' if schema else 'nodes'
    names = schema + '.names' if schema else 'names'

    cmd = ('select tax_id, tax_name, rank '
           'from {} join {} using (tax_id) '
           'where parent_id = :tax_id and is_primary').format(nodes, names)

    species = []
    for parent_id in parent_ids:
        result = engine.execute(sqlalchemy.sql.text(cmd), tax_id=parent_id)
        keys = list(result.keys())
        rows = [dict(list(zip(keys, row))) for row in result.fetchall()]
        for r in rows:
            if r['rank'] == rank and 'sp.' not in r['tax_name']:
                species.append(r)
        others = [r for r in rows if r['rank'] not in (rank, 'no_rank')]
        if others:
            _, s = get_children(engine, [r['tax_id'] for r in others])
            species.extend(s)

    return keys, species
492729
def _get_taxon(taxon):
        """"""
        if not taxon:
            return None
        ## assert taxon[:6] == 'taxon:', 'UNRECOGNIZED Taxon({Taxon})'.format(Taxon=taxon)
        ## taxid = taxon[6:]
        ## assert taxon[:10] == 'NCBITaxon:', 'UNRECOGNIZED Taxon({Taxon})'.format(Taxon=taxon)
        ## taxid = taxon[10:]
        # Get tzxon number: taxon:9606 NCBITaxon:9606
        sep = taxon.find(':')
        taxid = taxon[sep + 1:]
        assert taxid.isdigit(), "UNEXPECTED TAXON({T})".format(T=taxid)
        return int(taxid)