Beispiel #1
0
    def pos(self, *val):

        # turn int-tuple into slice
        newval = []
        for v in val:
            if isinstance(v, tuple) and len(v) == 2 and isinstance(v[0], int) and isinstance(v[1], int):
                newval.append(slice(v[0], v[1]))
            else:
                newval.append(v)

        val = tuple(newval)

        if len(val) == 1:
            val = val[0]

        if isinstance(val, str):
            df = get_string(self, val)
        elif isinstance(val, tuple):
            df = get_tuple(self, val)
        elif isinstance(val, slice):
            df = get_slice(self, val)
        else:
            raise Exception("Invalid type for indexer. Must be str, slice, or 2/3-tuple.")

        return return_copy_if_view(df, self.df)
Beispiel #2
0
def _getitem(self, val):

    if isinstance(val, list):
        dfs = _keep(self, keep=val).dfs
    elif isinstance(val, str):
        dfs = get_string(self, val)
    elif isinstance(val, tuple):
        dfs = get_tuple(self, val)
    elif isinstance(val, slice):
        dfs = get_slice(self, val)
    elif isinstance(val, dict):
        dfs = get_booldict(self, val)
    elif (isinstance(val, (pd.Series, np.ndarray))) and val.dtype == "bool":
        assert len(val) == len(
            self), "Boolean indexer must be same length as pyrange!"
        _length = 0
        if isinstance(val, pd.Series):
            val = val.values

        dfs = {}
        for k, df in self:
            length = len(df)
            _bool = val[_length:(length + _length)]
            dfs[k] = df[_bool]
            _length += length
    else:
        raise Exception("Not valid subsetter: {}".format(str(val)))

    gr = PyRanges(dfs)
    return gr
Beispiel #3
0
def _getitem(self, val):
    if isinstance(val, str):
        df = get_string(self, val)
    elif isinstance(val, tuple):
        df = get_tuple(self, val)
    elif isinstance(val, slice):
        df = get_slice(self, val)
    else:
        raise Exception("Not valid subsetter: {}".format(str(val)))

    if not df is None:
        return PyRanges(df)
    else:
        return PyRanges({})
Beispiel #4
0
def _getitem(self, val):

    if isinstance(val, list):
        dfs = _keep(self, keep=val).dfs
    elif isinstance(val, str):
        dfs = get_string(self, val)
    elif isinstance(val, tuple):
        dfs = get_tuple(self, val)
    elif isinstance(val, slice):
        dfs = get_slice(self, val)
    elif isinstance(val, dict):
        dfs = get_booldict(self, val)
    else:
        raise Exception("Not valid subsetter: {}".format(str(val)))

    gr = PyRanges(dfs)
    return gr