Open, read and parse DS9 region file.

    Parameters
    ----------
    fname : str
        Filename

    Returns
    -------
    shapes : `ShapeList`
        List of `~pyregion.Shape`
770839
def open(fname):
    
    with _builtin_open(fname) as fh:
        region_string = fh.read()
    return parse(region_string)
570311
def shapes(self):
        """"""
        shp = self.__getFileObj(self.shp)
        shp.seek(100)
        shapes = []
        while shp.tell() < self.shpLength:
            shapes.append(self.__shape())
        return shapes
222251
def split_by_fname_file(self, fname:PathOrStr, path:PathOrStr=None)->'ItemLists':
        ""
        path = Path(ifnone(path, self.path))
        valid_names = loadtxt_str(path/fname)
        return self.split_by_files(valid_names)
1063975
def read_map(fname):
    
    lst = []
    with open(fname, "r") as f:
        for line in f:
            lst.append(line)
    return lst
58459
def _read_file(fname):
    
    with open(fname) as input_file:
        re_grammar = [x.strip('\n') for x in input_file.readlines()]
    return re_grammar
1115278
def Read(f):
  
  try:
    yaml_data = yaml.load(f)
  except yaml.YAMLError as e:
    raise ParseError('%s' % e)
  except IOError as e:
    raise YAMLLoadError('%s' % e)

  _CheckData(yaml_data)

  try:
    return Config(
        yaml_data.get('blacklist', ()),
        yaml_data.get('whitelist', ('*')))
  except UnicodeDecodeError as e:
    raise YAMLLoadError('%s' % e)
390907
def open(filename, frame='unspecified'):
        
        data = Image.load_data(filename)
        return SegmentationImage(data, frame)
769205
def _read_name_file(self, filename):
        
        file_path = os.path.join(self._DATA_DIR, filename)
        with open(file_path) as f:
            names = json.load(f)

        return names
790441
def read_source_groups(fname):
    
    smodel = nrml.read(fname).sourceModel
    src_groups = []
    if smodel[0].tag.endswith('sourceGroup'):  # NRML 0.5 format
        for sg_node in smodel:
            sg = SourceGroup(sg_node['tectonicRegion'])
            sg.sources = sg_node.nodes
            src_groups.append(sg)
    else:  # NRML 0.4 format: smodel is a list of source nodes
        src_groups.extend(SourceGroup.collect(smodel))
    return src_groups
1080655
def visitShapeOrRef(self, ctx: ShExDocParser.ShapeOrRefContext):
        
        if ctx.shapeDefinition():
            from pyshexc.parser_impl.shex_shape_definition_parser import ShexShapeDefinitionParser
            shdef_parser = ShexShapeDefinitionParser(self.context, self.label)
            shdef_parser.visitChildren(ctx)
            self.expr = shdef_parser.shape
        else:
            self.expr = self.context.shapeRef_to_iriref(ctx.shapeRef())
841771
def parse_file(self, name):
        
        with open(name, "rb") as fp:
            return self.parse(fp.read())
511246
def _read_v3_10x_h5(filename):
    
    with tables.open_file(str(filename), 'r') as f:
        try:
            dsets = {}
            for node in f.walk_nodes('/matrix', 'Array'):
                dsets[node.name] = node.read()
            from scipy.sparse import csr_matrix
            M, N = dsets['shape']
            data = dsets['data']
            if dsets['data'].dtype == np.dtype('int32'):
                data = dsets['data'].view('float32')
                data[:] = dsets['data']
            matrix = csr_matrix((data, dsets['indices'], dsets['indptr']),
                                shape=(N, M))
            adata = AnnData(matrix,
                            {'obs_names': dsets['barcodes'].astype(str)},
                            {'var_names': dsets['name'].astype(str),
                             'gene_ids': dsets['id'].astype(str),
                             'feature_types': dsets['feature_type'].astype(str),
                             'genome': dsets['genome'].astype(str)})
            logg.info(t=True)
            return adata
        except KeyError:
            raise Exception('File is missing one or more required datasets.')
574968
def __getFileObj(self, f):
        """"""
        if not f:
            raise ShapefileException("Shapefile Reader requires a shapefile or file-like object.")
        if self.shp and self.shpLength is None:
            self.load()
        if self.dbf and len(self.fields) == 0:
            self.load()
        return f
811597
def parse_file(fname):
        
        try:
            with fopen(fname) as f:
                fstr = f.read()
        except IOError:
            if fname != 'stdin':
                raise
            sys.stdout.write('\nReading from stdin:\n\n')
            fstr = sys.stdin.read()
        fstr = fstr.replace('\r\n', '\n').replace('\r', '\n')
        if not fstr.endswith('\n'):
            fstr += '\n'
        return ast.parse(fstr, filename=fname)
939691
def read(filename):
    
    import os
    here = os.path.dirname(os.path.abspath(__file__))
    with open(os.path.join(here, filename)) as fd:
        return fd.read()
951027
def overplot_ds9reg(filename, ax):
    

    # read ds9 region file
    with open(filename) as f:
        file_content = f.read().splitlines()

    # check first line
    first_line = file_content[0]
    if "# Region file format: DS9" not in first_line:
        raise ValueError("Unrecognized ds9 region file format")

    for line in file_content:
        if line[0:4] == "line":
            line_fields = line.split()
            x1 = float(line_fields[1])
            y1 = float(line_fields[2])
            x2 = float(line_fields[3])
            y2 = float(line_fields[4])
            if "color" in line:
                i = line.find("color=")
                color = line[i+6:i+13]
            else:
                color = "green"
            ax.plot([x1,x2], [y1,y2], '-', color=color)
        elif line[0:4] == "text":
            line_fields = line.split()
            x0 = float(line_fields[1])
            y0 = float(line_fields[2])
            text=line_fields[3][1:-1]
            if "color" in line:
                i = line.find("color=")
                color = line[i+6:i+13]
            else:
                color = "green"
            ax.text(x0, y0, text, fontsize=8,
                    bbox=dict(boxstyle="round,pad=0.1", fc="white", ec="grey", ),
                    color=color, fontweight='bold', backgroundcolor='white',
                    ha='center')
        else:
            # ignore
            pass
31741
def parse_file(self, filename, skip_unreadable=False):
        
        if not os.access(filename, os.R_OK):
            if skip_unreadable:
                return
            raise ConfigReadingError("Unable to open file %s." % filename)
        with open(filename, 'rt') as f:
            return self.parse(f, name_hint=filename)