Read VCF file into pandas DataFrame.

    Parameters:
    -----------
    fn : str
        Path to VCF file.

    Returns
    -------
    df : pandas.DataFrame
        The VCF file as a data frame. Note that all header information is thrown
        away.
322247
def vcf_as_df(fn):
    
    header_lines = 0
    with open(fn, 'r') as f:
        line = f.readline().strip()
        header_lines += 1
        while line[0] == '#':
            line = f.readline().strip()
            header_lines += 1
    
    header_lines -= 2
    df = pd.read_table(fn, skiprows=header_lines, header=0)
    df.columns = ['CHROM'] + list(df.columns[1:])
    return df
1306998
def to_frame(self, **kwargs):
        
        """
        df = export.write_dataframe(self._values, **kwargs)
        df.name = self.title
        return df
260679
def _read_columns_file(f):
    
    try:
        columns = json.loads(open(f, 'r').read(),
                             object_pairs_hook=collections.OrderedDict)
    except Exception as err:
        raise InvalidColumnsFileError(
            "There was an error while reading {0}: {1}".format(f, err))

    # Options are not supported yet:
    if '__options' in columns:
        del columns['__options']

    return columns
485439
def tsToDf(tso):
    
    dfs = {}
    try:
        dfs = ts_to_df(tso)
    except Exception as e:
        print("Error: Unable to create data frame")
        logger_start.warn("ts_to_df: tso malformed: {}".format(e))
    return dfs
1260648
def read_table(cls, filepath_or_buffer, *args, **vargs):
        
        # Look for .csv at the end of the path; use "," as a separator if found
        try:
            path = urllib.parse.urlparse(filepath_or_buffer).path
            if 'data8.berkeley.edu' in filepath_or_buffer:
                raise ValueError('data8.berkeley.edu requires authentication, '
                                 'which is not supported.')
        except AttributeError:
            path = filepath_or_buffer

        try:
            if 'sep' not in vargs and path.endswith('.csv'):
                vargs['sep'] = ','
        except AttributeError:
            pass
        df = pandas.read_table(filepath_or_buffer, *args, **vargs)
        return cls.from_df(df)
193472
def get_frame_src(f:Frame) -> str:
    ''' 
    '''
    path, line, src, fn = _get_frame(
        inspect.getframeinfo(f)
    )
    return '{}:{} -> {}\n{}'.format(
        path.split(os.sep)[-1],
        line,
        fn,
        repr(src[0][:-1]) # shave off \n
    )
848602
def ts_to_df(metadata):
    
    logger_dataframes.info("enter ts_to_df")
    dfs = {}

    # Plot the variable + values vs year, age, depth (whichever are available)
    dfs["paleoData"] = pd.DataFrame(_plot_ts_cols(metadata))

    # Plot the chronology variables + values in a data frame
    dfs["chronData"] = _get_key_data(metadata, "chronData_df")

    # Take out the chronData pandas data frame object if it exists in the metadata
    # Otherwise, the data frame renderer gets crazy and errors out.
    if "chronData_df" in metadata:
        del metadata["chronData_df"]
    s = collections.OrderedDict(sorted(metadata.items()))

    # Put key-vars in a data frame to make it easier to visualize
    dfs["metadata"] = pd.DataFrame(list(s.items()), columns=['Key', 'Value'])

    logger_dataframes.info("exit ts_to_df")
    return dfs
781606
def dataframe(self, dtype=False, parse_dates=True,  *args, **kwargs):
        """"""

        import pandas as pd

        rg = self.row_generator

        t = self.resolved_url.get_resource().get_target()

        if t.target_format == 'csv':
            return self.read_csv(dtype, parse_dates, *args, **kwargs)

        # Maybe generator has it's own Dataframe method()
        try:

            return rg.dataframe( *args, **kwargs)
        except AttributeError:
            pass

        # Just normal data, so use the iterator in this object.
        headers = next(islice(self, 0, 1))
        data = islice(self, 1, None)

        df = pd.DataFrame(list(data), columns=headers,  *args, **kwargs)

        self.errors = df.metatab_errors = rg.errors if hasattr(rg, 'errors') and rg.errors else {}

        return df
722288
def load_tbl_from_csv(fname):
	
	import csv

	rows_to_load = []

	with open(fname, 'r', encoding='cp1252', errors='ignore') as csvfile:
		csvreader = csv.reader(csvfile, delimiter = ',' )

		reader = csv.reader(csvfile)

		rows_to_load = list(reader)

	return rows_to_load
529323
def _read_dataframe(filename):
    
    import pandas

    # read in triples of user/artist/playcount from the input dataset
    # get a model based off the input params
    start = time.time()
    log.debug("reading data from %s", filename)
    data = pandas.read_csv(filename, delimiter='|', quotechar='\\')

    # map each artist and user to a unique numeric value
    data['uid'] = data['uid'].astype("category")
    data['mid'] = data['mid'].astype("category")

    # store as a CSR matrix
    log.debug("read data file in %s", time.time() - start)
    return data
815012
def make_het_matrix(fn):
    
    # TODO: parallelize?
    vcf_df = vcf_as_df(fn)
    variant_ids = vcf_df.apply(lambda x: df_variant_id(x), axis=1)
    vcf_reader = pyvcf.Reader(open(fn, 'r'))
    record = vcf_reader.next()
    hets = pd.DataFrame(0, index=variant_ids,
                        columns=[x.sample for x in record.samples])
    
    vcf_reader = pyvcf.Reader(open(fn, 'r'))
    for record in vcf_reader:
        h = record.get_hets()
        i = record_variant_id(record)
        hets.ix[i, [x.sample for x in h]] = 1
    
    return hets
1016009
def _convert_to_df(in_file, freq, raw_file):
    
    dat = defaultdict(Counter)
    if isinstance(in_file, (str, unicode)):
        with open(in_file) as in_handle:
            for line in in_handle:
                cols = line.strip().split("\t")
                counts = freq[cols[3]]
                dat = _expand(dat, counts, int(cols[1]), int(cols[2]))
    else:
        if raw_file:
            out_handle = open(raw_file, "w")
        for name in in_file:
            counts = freq[name]
            if raw_file:
                print("%s\t%s\t%s\t%s\t%s\t%s" % ("chr", in_file[name][0], in_file[name][1], name, sum(counts.values()), "+"), file=out_handle, end="")
            dat = _expand(dat, counts, in_file[name][0], in_file[name][1])

    for s in dat:
        for p in dat[s]:
            dat[s][p] = mlog2(dat[s][p] + 1)
    return dat
619030
def read_avro(file_path_or_buffer, schema=None, **kwargs):
    
    if isinstance(file_path_or_buffer, six.string_types):
        with open(file_path_or_buffer, 'rb') as f:
            return __file_to_dataframe(f, schema, **kwargs)
    else:
        return __file_to_dataframe(file_path_or_buffer, schema, **kwargs)
876901
def load_hdf(cls, filename, path='', ic=None):
        
        store = pd.HDFStore(filename)
        try:
            samples = store[path+'/df']
            attrs = store.get_storer(path+'/df').attrs
        except:
            store.close()
            raise
        df = store[path+'/df']
        new = cls.from_df(df)

        if ic is None:
            ic = get_ichrone('mist')

        new.define_models(ic, N=attrs.N, index=attrs.index)
        new.spectroscopy = attrs.spectroscopy
        new.parallax = attrs.parallax
        store.close()
        return new
449193
def __load(arff):
    
    attrs = arff['attributes']
    attrs_t = []
    for attr in attrs:
        if isinstance(attr[1], list):
            attrs_t.append("%s@{%s}" % (attr[0], ','.join(attr[1])))
        else:
            attrs_t.append("%s@%s" % (attr[0], attr[1]))

    df = pd.DataFrame(data=arff['data'], columns=attrs_t)
    return df
161672
def read_csv(self, dtype=False, parse_dates=True, *args, **kwargs):
        

        import pandas

        t = self.resolved_url.get_resource().get_target()

        kwargs = self._update_pandas_kwargs(dtype, parse_dates, kwargs)

        return pandas.read_csv(t.fspath, *args, **kwargs)
223943
def to_df(self):
        ''''''
        return pd.DataFrame({k: v for k, v in self.items() if k is not 'names'},
                            index=self['names'])