Returns an iterator over the Phenotypes from the server
509062
def search_phenotype(
            self, phenotype_association_set_id=None, phenotype_id=None,
            description=None, type_=None, age_of_onset=None):
        
        request = protocol.SearchPhenotypesRequest()
        request.phenotype_association_set_id = phenotype_association_set_id
        if phenotype_id:
            request.id = phenotype_id
        if description:
            request.description = description
        if type_:
            request.type.mergeFrom(type_)
        if age_of_onset:
            request.age_of_onset = age_of_onset
        request.page_size = pb.int(self._page_size)
        return self._run_search_request(
            request, "phenotypes",
            protocol.SearchPhenotypesResponse)
100037
def zero_fill_missing_phenotypes(self):
        
        if self.is_uniform(verbose=False): return self.copy()
        output = self.copy()
        def _do_fill(d,names):
            old_names = list(d.keys())
            old_values = list(d.values())
            missing = set(names)-set(old_names)
            return dict(zip(old_names+list(missing),old_values+([0]*len(missing))))
        ## Need to make these uniform
        pnames = self.phenotypes
        output['phenotype_calls']= output.apply(lambda x:
            _do_fill(x['phenotype_calls'],pnames)
            ,1)
        return output
1031321
def featuresGenerator(self, request):
        
        compoundId = None
        parentId = None
        if request.feature_set_id != "":
            compoundId = datamodel.FeatureSetCompoundId.parse(
                request.feature_set_id)
        if request.parent_id != "":
            compoundParentId = datamodel.FeatureCompoundId.parse(
                request.parent_id)
            parentId = compoundParentId.featureId
            # A client can optionally specify JUST the (compound) parentID,
            # and the server needs to derive the dataset & featureSet
            # from this (compound) parentID.
            if compoundId is None:
                compoundId = compoundParentId
            else:
                # check that the dataset and featureSet of the parent
                # compound ID is the same as that of the featureSetId
                mismatchCheck = (
                    compoundParentId.dataset_id != compoundId.dataset_id or
                    compoundParentId.feature_set_id !=
                    compoundId.feature_set_id)
                if mismatchCheck:
                    raise exceptions.ParentIncompatibleWithFeatureSet()

        if compoundId is None:
            raise exceptions.FeatureSetNotSpecifiedException()

        dataset = self.getDataRepository().getDataset(
            compoundId.dataset_id)
        featureSet = dataset.getFeatureSet(compoundId.feature_set_id)
        iterator = paging.FeaturesIterator(
            request, featureSet, parentId)
        return iterator
347745
def iter_genotypes(self):
        
        # Parsing each column of the dataframe
        for variant in self.df.columns:
            genotypes = self.df.loc[:, variant].values
            info = self.map_info.loc[variant, :]

            yield Genotypes(
                Variant(info.name, info.chrom, info.pos, [info.a1, info.a2]),
                genotypes,
                reference=info.a2,
                coded=info.a1,
                multiallelic=False,
            )
704249
def iterchildren(self):
        """"""

        child_iter = self.model.iter_children(self.iter)
        return TreeModelRowIter(self.model, child_iter)
1066506
def iterator(self):
        """"""
        if self.combined:
            grouped_data = [[(0, datum)] for datum in self.data]
            skip_dims = {"chain"}
        else:
            grouped_data = [datum.groupby("chain") for datum in self.data]
            skip_dims = set()

        label_dict = OrderedDict()
        for name, grouped_datum in zip(self.model_names, grouped_data):
            for _, sub_data in grouped_datum:
                datum_iter = xarray_var_iter(
                    sub_data,
                    var_names=[self.var_name],
                    skip_dims=skip_dims,
                    reverse_selections=True,
                )
                for _, selection, values in datum_iter:
                    label = make_label(self.var_name, selection, position="beside")
                    if label not in label_dict:
                        label_dict[label] = OrderedDict()
                    if name not in label_dict[label]:
                        label_dict[label][name] = []
                    label_dict[label][name].append(values)

        y = self.y_start
        for label, model_data in label_dict.items():
            for model_name, value_list in model_data.items():
                if model_name:
                    row_label = "{}: {}".format(model_name, label)
                else:
                    row_label = label
                for values in value_list:
                    yield y, row_label, label, values, self.model_color[model_name]
                    y += self.chain_offset
                y += self.var_offset
            y += self.group_offset
482530
def iter_(obj):
    
    if six.PY2:
        file_types = file,  # noqa
    if six.PY3:
        file_types = io.IOBase,
        dict_items = {}.items().__class__
        dict_values = {}.values().__class__
        dict_keys = {}.keys().__class__
        dict_view = (dict_items, dict_values, dict_keys)

    if isinstance(obj, dict):
        return ordered_sequence_iterator(list(obj.keys()))
    if isinstance(obj, file_types):
        return file_iterator(obj)
    if six.PY2:
        if isinstance(obj, (list, tuple)):
            return ordered_sequence_iterator(obj)
        if isinstance(obj, xrange):  # noqa
            return range_iterator(obj)
        if NUMPY_AVAILABLE and isinstance(obj, numpy.ndarray):
            return ordered_sequence_iterator(obj)
    if six.PY3 and isinstance(obj, dict_view):
        return ordered_sequence_iterator(list(obj))
    return iter(obj)
281637
def iter_variants(self):
        """"""
        if not self.has_index:
            raise NotImplementedError("Not implemented when IMPUTE2 file is "
                                      "not indexed (see genipe)")

        for name, row in self._impute2_index.iterrows():
            # Seeking to the right place in the file
            f = self._impute2_file
            f.seek(int(row.seek))
            chrom, name, pos, a1, a2 = f.read(1024).split(" ")[:5]
            pos = int(pos)

            yield Variant(name, CHROM_STR_ENCODE.get(chrom, chrom), pos,
                          [a1, a2])
818637
def add_types(graph, phenotypes):  # TODO missing expression phenotypes! also basket type somehow :(
    

    collect = defaultdict(set)
    def recurse(id_, start, level=0):
        #print(level)
        for t in graph.g.triples((None, None, id_)):
            if level == 0:
                if t[1] != rdflib.term.URIRef('http://www.w3.org/2002/07/owl#someValuesFrom'):
                    continue
            if type_check(t, (rdflib.term.URIRef, rdflib.term.URIRef, rdflib.term.BNode)):
                #print(start, t[0])
                collect[start].add(t[0])
                return  #  we're done here, otherwise we hit instantiated subclasses
            if level > 1:
                if t[1] == rdflib.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#first') or \
                   t[1] == rdflib.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#rest'):
                    continue

            recurse(t[0], start, level + 1)


    for phenotype in phenotypes:
        recurse(phenotype, phenotype)

    return collect
1296861
def iter_genotypes(self):
        
        for v in self.get_vcf():
            alleles = {v.REF} | set(v.ALT)

            if self.quality_field:
                variant = ImputedVariant(v.ID, v.CHROM, v.POS, alleles,
                                         getattr(v, self.quality_field))
            else:
                variant = Variant(v.ID, v.CHROM, v.POS, alleles)

            for coded_allele, g in self._make_genotypes(v.ALT, v.genotypes):
                yield Genotypes(variant, g, v.REF, coded_allele,
                                multiallelic=len(v.ALT) > 1)
1020735
def iteritems(cls):
        
        for key in dir(cls):
            val = getattr(cls, key)
            if isinstance(cls, val):
                yield (key, val)
2484
def fill_phenotype_label(self,inplace=False):
        
        def _get_phenotype(d):
            vals = [k for k,v in d.items() if v ==  1]
            return np.nan if len(vals) == 0 else vals[0]
        if inplace:
            if self.shape[0] == 0: return self
            self['phenotype_label'] = self.apply(lambda x: _get_phenotype(x['phenotype_calls']),1)
            return
        fixed = self.copy()
        if fixed.shape[0] == 0: return fixed
        fixed['phenotype_label'] = fixed.apply(lambda x: _get_phenotype(x['phenotype_calls']),1)
        return fixed
914016
def results_iterator(self, scan_id, pop_res):
        
        if pop_res:
            result_aux = self.scans_table[scan_id]['results']
            self.scans_table[scan_id]['results'] = list()
            return iter(result_aux)

        return iter(self.scans_table[scan_id]['results'])
48604
private FilterResult<G, C> filter(
		final Seq<Phenotype<G, C>> population,
		final long generation
	) {
		int killCount = 0;
		int invalidCount = 0;

		final MSeq<Phenotype<G, C>> pop = MSeq.of(population);
		for (int i = 0, n = pop.size(); i < n; ++i) {
			final Phenotype<G, C> individual = pop.get(i);

			if (!_validator.test(individual)) {
				pop.set(i, newPhenotype(generation));
				++invalidCount;
			} else if (individual.getAge(generation) > _maximalPhenotypeAge) {
				pop.set(i, newPhenotype(generation));
				++killCount;
			}
		}

		return new FilterResult<>(pop.toISeq(), killCount, invalidCount);
	}
364065
def iter_variants(self):
        
        for variant in self.repository.iter_variants(self.resource):
            yield Variant(variant, context=self.context, parent=self)
616569
def _process_phenotypicseries(self, limit):
        
        if self.test_mode:
            graph = self.testgraph
        else:
            graph = self.graph
        LOG.info("getting phenotypic series titles")
        model = Model(graph)
        line_counter = 0
        src_key = 'phenotypicSeries'
        col = self.files[src_key]['columns']
        raw = '/'.join((self.rawdir, self.files[src_key]['file']))
        with open(raw) as reader:
            line = reader.readline()  # title
            line = reader.readline()  # date downloaded
            line = reader.readline()  # copyright
            line = reader.readline()  # <blank>

            line = reader.readline().strip()  # column headers
            line_counter = 5
            row = line.split('\t')
            if row != col:  # assert
                LOG.error('Expected  %s to have columns: %s', raw, col)
                LOG.error('But Found %s to have columns: %s', raw, row)
                raise AssertionError('Incomming data headers have changed.')

            for line in reader:
                line_counter += 1
                row = line.strip().split('\t')
                if row and len(row) != len(col):
                    LOG.warning(
                        'Unexpected input on line: %i  got: %s', line_counter, row)
                    continue
                ps_label = row[col.index('Phenotypic Series Title')].strip()
                ps_num = row[col.index('Phenotypic Series number')].strip()
                omimps_curie = 'OMIMPS:' + ps_num
                model.addClassToGraph(omimps_curie, ps_label)

                if not self.test_mode and limit is not None and line_counter > limit:
                    break
628041
def fill_phenotype_calls(self,phenotypes=None,inplace=False):
        
        if phenotypes is None: phenotypes = list(self['phenotype_label'].unique())
        def _get_calls(label,phenos):
            d =  dict([(x,0) for x in phenos])
            if label!=label: return d # np.nan case
            d[label] = 1
            return d
        if inplace:
            self['phenotype_calls'] = self.apply(lambda x: _get_calls(x['phenotype_label'],phenotypes),1)
            return
        fixed = self.copy()
        fixed['phenotype_calls'] = fixed.apply(lambda x: _get_calls(x['phenotype_label'],phenotypes),1)
        return fixed