Identifies the separator of data in a filepath.
    It reads the first line of the file and counts supported separators.
    Currently supported separators: ['|', ';', ',','\t',':']
7563
def identify_sep(filepath):
    
    ext = os.path.splitext(filepath)[1].lower()
    allowed_exts = ['.csv', '.txt', '.tsv']
    assert ext in ['.csv', '.txt'], "Unexpected file extension {}. \
                                    Supported extensions {}\n filename: {}".format(
                                    ext, allowed_exts, os.path.basename(filepath))
    maybe_seps = ['|',
                  ';',
                  ',',
                  '\t',
                  ':']

    with open(filepath,'r') as fp:
        header = fp.__next__()

    count_seps_header = {sep: _count(sep, header) for sep in maybe_seps}
    count_seps_header = {sep: count for sep,
                         count in count_seps_header.items() if count > 0}

    if count_seps_header:
        return max(count_seps_header.__iter__(),
                   key=(lambda key: count_seps_header[key]))
    else:
        raise Exception("Couldn't identify the sep from the header... here's the information:\n HEADER: {}\n SEPS SEARCHED: {}".format(header, maybe_seps))
77265
def _parse_line(sep, line):
    
    strs = line.split(sep, 1)
    return (strs[0].strip(), None) if len(strs) == 1 else (strs[0].strip(), strs[1].strip())
1142272
def _preprocessContaminantOutFilePath(outPath):
        
        if '/' in outPath:
            splitPath = outPath.split('/')

        elif '\\' in outPath:
            splitPath = outPath.split('\\')

        else:
            splitPath = [outPath, ]

        if splitPath[-1] == '':
            outputFilename = splitPath[-2]

        else:
            outputFilename = splitPath[-1]

        if '.' in outputFilename:
            outputFilename = outputFilename.split('.')[0]

        return outputFilename
318961
def separator_line(cls, sep='-', size=10):
        
        if cls.intty():
            cls.echo(sep * size)
373601
def read_file(filename, prepend_paths=[]):
  
  if prepend_paths is True:
    prepend_paths = [
      os.path.abspath(os.path.dirname(__file__)),
    ]
  if prepend_paths:
    prepend_paths.append(filename)
    filename = os.path.join(*prepend_paths)
  print(filename)
  with open(filename, encoding='utf-8') as f:
    return f.read()
471990
def read_csv(filepath):
    
    symbols = []
    with open(filepath, 'rb') as csvfile:
        spamreader = csv.DictReader(csvfile, delimiter=',', quotechar='"')
        for row in spamreader:
            symbols.append(row)
    return symbols
728094
def read_filepath(filepath, encoding='utf-8'):
    """"""
    with codecs.open(filepath, 'r', encoding=encoding) as fo:
        return fo.read()
507679
def readTableFromDelimited(f, separator="\t"):
    
    rowNames = []
    columnNames = []
    matrix = []

    first = True
    for line in f.readlines():
        line = line.rstrip()
        if len(line) == 0:
            continue

        row = line.split(separator)
        if first:
            columnNames = row[1:]
            first = False
        else:
            rowNames.append(row[0])
            matrix.append([float(c) for c in row[1:]])

    return Table(rowNames, columnNames, matrix)
705458
def spacing_file(path):
    
    # TODO: read line by line
    with open(os.path.abspath(path)) as f:
        return spacing_text(f.read())
956218
def read_struct(fstream):
    
    line = fstream.readline().strip()
    fragments = line.split(",")
    fragments = [x for x in fragments if x is not None]
    partition = dict()
    if not len(fragments) >= 3:
        return None

    partition["struct"] = fragments[0]
    partition["info"] = fragments[1]
    partition["num_lines"] = fragments[2]

    struct = None
    if partition is not None and partition["struct"] == "STRUCT":
        num_lines = int(partition["num_lines"].strip())
        struct = {}
        for _ in range(num_lines):
            cols = fetch_cols(fstream)
            struct.update({cols[0]: cols[1:]})
    return struct
1337677
public static String separatorsToSystem(final String path) {
        if (path == null) {
            return null;
        }
        if (IOUtil.IS_OS_WINDOWS) {
            return separatorsToWindows(path);
        } else {
            return separatorsToUnix(path);
        }
    }
1008216
def path_entry(self, path):
        
        if path[0] != '/':
            return None
        path_parts = path.split('/')
        # Note that here the first element will be '' because it's before the
        # first separator.  That's OK, the join puts it back together.
        directory = '/'.join(path_parts[:-1])
        name = path_parts[-1]
        if directory not in self.listings:
            return None
        if name not in self.listings[directory]['entries']:
            return None
        return self.listings[directory]['entries'][name]
434540
def read(file_path):
    
    # Read in file
    actual_file_path = os.path.expanduser(file_path)
    with open(actual_file_path, 'r') as f:
        lines = f.readlines()
    
    # Create GMT object
    gmt = []
    
    # Iterate over each line
    for line_num, line in enumerate(lines):
        # Separate along tabs
        fields = line.split('\t')

        assert len(fields) > 2, (
            "Each line must have at least 3 tab-delimited items. " +
            "line_num: {}, fields: {}").format(line_num, fields)
        
        # Get rid of trailing whitespace
        fields[-1] = fields[-1].rstrip()
        
        # Collect entries
        entries = fields[2:]
        
        # Remove empty entries
        entries = [x for x in entries if x]

        assert len(set(entries)) == len(entries), (
            "There should not be duplicate entries for the same set. " +
            "line_num: {}, entries: {}").format(line_num, entries)

        # Store this line as a dictionary
        line_dict = {SET_IDENTIFIER_FIELD: fields[0],
                     SET_DESC_FIELD: fields[1],
                     SET_MEMBERS_FIELD: entries}
        gmt.append(line_dict)

    verify_gmt_integrity(gmt)

    return gmt
761391
def parse_lines(stream, separator=None):
    
    separator = None if separator is None else unicode(separator)
    for line in stream:
        line = line.rstrip(u'\r\n')
        row = [interpret_segment(i) for i in line.split(separator)]
        yield line, row
544274
def pre_process_data(filepath):
    
    positive_path = os.path.join(filepath, 'pos')
    negative_path = os.path.join(filepath, 'neg')

    pos_label = 1
    neg_label = 0

    dataset = []

    for filename in glob.glob(os.path.join(positive_path, '*.txt')):
        with open(filename, 'r') as f:
            dataset.append((pos_label, f.read()))

    for filename in glob.glob(os.path.join(negative_path, '*.txt')):
        with open(filename, 'r') as f:
            dataset.append((neg_label, f.read()))

    shuffle(dataset)

    return dataset
1012973
def read_id_list(filepath):
    
    if not filepath:
        return None
    id_list = []
    with open(filepath) as f:
        for line in f:
            line = line.rstrip()
            if not re.match('^[0-9]{8}$', line):
                raise('Each line in whitelist or blacklist is expected '
                      'to contain an eight digit ID, and nothing else.')
            else:
                id_list.append(line)
    return id_list
694297
def separators(self, reordered = True):
        
        if reordered:
            return [list(self.snrowidx[self.sncolptr[k]+self.snptr[k+1]-self.snptr[k]:self.sncolptr[k+1]]) for k in range(self.Nsn)] 
        else:
            return [list(self.__p[self.snrowidx[self.sncolptr[k]+self.snptr[k+1]-self.snptr[k]:self.sncolptr[k+1]]]) for k in range(self.Nsn)]