returns column names from CTD download file

        :param str file_path: path to CTD download file
427423
def get_column_names_from_file(file_path):
        
        if file_path.endswith('.gz'):
            file_handler = io.TextIOWrapper(io.BufferedReader(gzip.open(file_path)))
        else:
            file_handler = open(file_path, 'r')

        fields_line = False
        with file_handler as file:
            for line in file:
                line = line.strip()
                if not fields_line and re.search('#\s*Fields\s*:$', line):
                    fields_line = True
                elif fields_line and not (line == '' or line == '#'):
                    return [column.strip() for column in line[1:].split("\t")]
503157
def read_existing_paths(bt_table):
    """"""
    rows = bt_table.read_rows(
        filter_=row_filters.ColumnRangeFilter(
            METADATA, SGF_FILENAME, SGF_FILENAME))
    names = (row.cell_value(METADATA, SGF_FILENAME).decode() for row in rows)
    processed = [os.path.splitext(os.path.basename(r))[0] for r in names]
    return processed
1125439
def _generate_examples(self, file_path):
    

    with tf.io.gfile.GFile(file_path) as f:
      raw_data = csv.DictReader(f)
      for row in raw_data:
        survive_val = row.pop("survived")
        yield {
            "survived": convert_to_label(survive_val, _SURVIVED_DICT),
            "features": {
                name: FEATURE_DICT[name][1](value)
                for name, value in row.items()
            }
        }
1079831
def load(cls, file_path):
        

        # convert back to numpy
        data = helper.read_json(file_path)
        return Concise.from_dict(data)
379447
def inspect_file(path):
    
    with open(path, 'rb') as f:
        labels, count = inspect(tx.decode(line) for line in f)
    return labels, count
894653
def getfullfilename(file_path):
        ''' 
        '''
        warnings.warn("getfullfilename() is deprecated and will be removed in near future. Use chirptext.io.write_file() instead", DeprecationWarning)
        if file_path:
            return os.path.basename(file_path)
        else:
            return ''
1365145
def read_tabular(filepath):
    
    _, fn, ext = splitext2(filepath)
    if ext == '.h5':
        return _read_tabular_h5(filepath)
    elif ext == '.pkl':
        return _read_tabular_pickle(filepath)
    else:
        raise NotImplementedError
576392
def get_tp_from_file(file_path):
    
    match = TP_FROM_FILE_REGEX.match(file_path)
    if not match:
        print("File path is not valid: " + file_path)
        sys.exit(1)
    return match.group(1)
921041
def read_tb(path):
    
    import pandas
    import numpy as np
    from glob import glob
    from collections import defaultdict
    import tensorflow as tf
    if osp.isdir(path):
        fnames = glob(osp.join(path, "events.*"))
    elif osp.basename(path).startswith("events."):
        fnames = [path]
    else:
        raise NotImplementedError("Expected tensorboard file or directory containing them. Got %s"%path)
    tag2pairs = defaultdict(list)
    maxstep = 0
    for fname in fnames:
        for summary in tf.train.summary_iterator(fname):
            if summary.step > 0:
                for v in summary.summary.value:
                    pair = (summary.step, v.simple_value)
                    tag2pairs[v.tag].append(pair)
                maxstep = max(summary.step, maxstep)
    data = np.empty((maxstep, len(tag2pairs)))
    data[:] = np.nan
    tags = sorted(tag2pairs.keys())
    for (colidx,tag) in enumerate(tags):
        pairs = tag2pairs[tag]
        for (step, value) in pairs:
            data[step-1, colidx] = value
    return pandas.DataFrame(data, columns=tags)
424994
def getDownload(self, params):
        
        df = self.getData(params)
        buffer = io.StringIO()
        df.to_csv(buffer, index=False, encoding='utf-8')
        filepath = buffer
        return filepath
250762
def get_index_and_columns_order(cls, columns_in_file_expected, columns_dict, file_path):
        
        use_columns_with_index = []
        column_names_in_db = []

        column_names_from_file = cls.get_column_names_from_file(file_path)
        if not set(columns_in_file_expected).issubset(column_names_from_file):
            log.exception(
                '%s columns are not a subset of columns %s in file %s',
                columns_in_file_expected,
                column_names_from_file,
                file_path
            )
        else:
            for index, column in enumerate(column_names_from_file):
                if column in columns_dict:
                    use_columns_with_index.append(index)
                    column_names_in_db.append(columns_dict[column])
        return use_columns_with_index, column_names_in_db
726935
def metadata(self, file_path):

        ''' 
        '''

        __name__ = '%s.metadata(...)' % self.__class__.__name__

    # validate input
        self.fields.validate(file_path, '.file_path')
        file_exists = False
        if os.path.exists(file_path):
            if os.path.isfile(file_path):
                file_exists = True
        if not file_exists:
            err_msg = __name__.replace('...', 'file_path=%s' % file_path)
            raise ValueError('%s must be a valid file.' % err_msg)

    # construct metadata dictionary
        abs_path = os.path.abspath(file_path)
        file_stats = os.stat(file_path)
        file_metadata = {
            'path_segments': abs_path.split(os.sep),
            'file_name': os.path.split(abs_path)[1],
            'file_path': abs_path,
            'file_size': file_stats.st_size,
            'create_date': file_stats.st_ctime,
            'update_date': file_stats.st_mtime,
            'access_date': file_stats.st_atime
        }

        return file_metadata
1348458
def GetExtAttrs(filepath):
  
  path = CanonicalPathToLocalPath(filepath)

  try:
    attr_names = xattr.listxattr(path)
  except (IOError, OSError, UnicodeDecodeError) as error:
    msg = "Failed to retrieve extended attributes for '%s': %s"
    logging.error(msg, path, error)
    return

  # `xattr` (version 0.9.2) decodes names as UTF-8. Since we (and the system)
  # allows for names and values to be arbitrary byte strings, we use `bytes`
  # rather than `unicode` objects here. Therefore we have to re-encode what
  # `xattr` has decoded. Additionally, because the decoding that `xattr` does
  # may fail, we additionally guard against such exceptions.
  def EncodeUtf8(attr_name):
    if isinstance(attr_name, Text):
      return attr_name.encode("utf-8")
    if isinstance(attr_name, bytes):
      return attr_name
    raise TypeError("Unexpected type `%s`" % type(attr_name))

  for attr_name in attr_names:
    attr_name = EncodeUtf8(attr_name)
    try:
      attr_value = xattr.getxattr(path, attr_name)
    except (IOError, OSError) as error:
      msg = "Failed to retrieve attribute '%s' for '%s': %s"
      logging.error(msg, attr_name, path, error)
      continue

    yield rdf_client_fs.ExtAttr(name=attr_name, value=attr_value)
526340
def _load_significant_pathways_file(path_to_file):
    
    feature_pathway_df = pd.read_table(
        path_to_file, header=0,
        usecols=["feature", "side", "pathway"])
    feature_pathway_df = feature_pathway_df.sort_values(
        by=["feature", "side"])
    return feature_pathway_df
1267008
def filenames(self):
        
        return [os.path.basename(source) for source in self.sources if source]
177231
def get_connection_filename(filename, tmp_path = None, replace_file = False, verbose = False):
	
	def mktmp(path, suffix = ".sqlite", verbose = False):
		with temporary_files_lock:
			# make sure the clean-up signal traps are installed
			install_signal_trap()
			# create the remporary file and replace it's
			# unlink() function
			temporary_file = tempfile.NamedTemporaryFile(suffix = suffix, dir = path if path != "_CONDOR_SCRATCH_DIR" else os.getenv("_CONDOR_SCRATCH_DIR"))
			def new_unlink(self, orig_unlink = temporary_file.unlink):
				# also remove a -journal partner, ignore all errors
				try:
					orig_unlink("%s-journal" % self)
				except:
					pass
				orig_unlink(self)
			temporary_file.unlink = new_unlink
			filename = temporary_file.name
			# hang onto reference to prevent its removal
			temporary_files[filename] = temporary_file
		if verbose:
			print >>sys.stderr, "using '%s' as workspace" % filename
		# mkstemp() ignores umask, creates all files accessible
		# only by owner;  we should respect umask.  note that
		# os.umask() sets it, too, so we have to set it back after
		# we know what it is
		umsk = os.umask(0777)
		os.umask(umsk)
		os.chmod(filename, 0666 & ~umsk)
		return filename

	def truncate(filename, verbose = False):
		if verbose:
			print >>sys.stderr, "'%s' exists, truncating ..." % filename,
		try:
			fd = os.open(filename, os.O_WRONLY | os.O_TRUNC)
		except Exception as e:
			if verbose:
				print >>sys.stderr, "cannot truncate '%s': %s" % (filename, str(e))
			return
		os.close(fd)
		if verbose:
			print >>sys.stderr, "done."

	def cpy(srcname, dstname, verbose = False):
		if verbose:
			print >>sys.stderr, "copying '%s' to '%s' ..." % (srcname, dstname),
		shutil.copy2(srcname, dstname)
		if verbose:
			print >>sys.stderr, "done."
		try:
			# try to preserve permission bits.  according to
			# the documentation, copy() and copy2() are
			# supposed preserve them but don't.  maybe they
			# don't preserve them if the destination file
			# already exists?
			shutil.copystat(srcname, dstname)
		except Exception as e:
			if verbose:
				print >>sys.stderr, "warning: ignoring failure to copy permission bits from '%s' to '%s': %s" % (filename, target, str(e))

	database_exists = os.access(filename, os.F_OK)

	if tmp_path is not None:
		# for suffix, can't use splitext() because it only keeps
		# the last bit, e.g. won't give ".xml.gz" but just ".gz"
		target = mktmp(tmp_path, suffix = ".".join(os.path.split(filename)[-1].split(".")[1:]), verbose = verbose)
		if database_exists:
			if replace_file:
				# truncate database so that if this job
				# fails the user won't think the database
				# file is valid
				truncate(filename, verbose = verbose)
			else:
				# need to copy existing database to work
				# space for modifications
				i = 1
				while True:
					try:
						cpy(filename, target, verbose = verbose)
					except IOError as e:
						import errno
						import time
						if e.errno not in (errno.EPERM, errno.ENOSPC):
							# anything other
							# than out-of-space
							# is a real error
							raise
						if i < 5:
							if verbose:
								print >>sys.stderr, "warning: attempt %d: %s, sleeping and trying again ..." % (i, errno.errorcode[e.errno])
							time.sleep(10)
							i += 1
							continue
						if verbose:
							print >>sys.stderr, "warning: attempt %d: %s: working with original file '%s'" % (i, errno.errorcode[e.errno], filename)
						with temporary_files_lock:
							del temporary_files[target]
						target = filename
					break
	else:
		with temporary_files_lock:
			if filename in temporary_files:
				raise ValueError("file '%s' appears to be in use already as a temporary database file and is to be deleted" % filename)
		target = filename
		if database_exists and replace_file:
			truncate(target, verbose = verbose)

	del mktmp
	del truncate
	del cpy

	return target
112422
def _get_gtf_column(column_name, gtf_path, df):
    
    if column_name in df.columns:
        return list(df[column_name])

    else:
        raise ValueError(
            "Missing '%s' in columns of %s, available: %s" % (
                column_name,
                gtf_path,
                list(df.columns)))