Beispiel #1
0
def parse_csv(filename):
    separator = ','
    if filename.endswith('.tsv'):
        separator = '\t'
    try:
        table = []
        id = 1
        contents = read_file(filename)
        lines = [
            l.strip().split(separator) for l in contents.split('\n')
            if l.strip() and not (l.strip().startswith('#'))
        ]
        for linetokens in lines:
            if len(linetokens) >= 3:
                table.append(
                    dict(Experimental=float(linetokens[0]),
                         Predicted=float(linetokens[1]),
                         ID=str(linetokens[2])))
            elif len(linetokens) == 2:
                table.append(
                    dict(Experimental=float(linetokens[0]),
                         Predicted=float(linetokens[1]),
                         ID=id))
                id += 1
            else:
                raise Exception(
                    'At least two columns (experimental DDG, predicted DDG) are expected.'
                )
        return table
    except Exception, e:
        raise Exception('An exception occurred parsing the CSV/TSV file: %s' %
                        str(e))
Beispiel #2
0
def read_json(filename):
    try:
        try:
            import json
        except:
            import simplejson as json
        return json.loads(read_file(filename))
    except:
        return None
Beispiel #3
0
def read_json(filename):
    try:
        try:
            import json
        except:
            import simplejson as json
        return json.loads(read_file(filename))
    except:
        return None
Beispiel #4
0
def parse_csv(filename):
    separator = ','
    if filename.endswith('.tsv'):
        separator = '\t'
    try:
        table = []
        id = 1
        contents = read_file(filename)
        lines = [l.strip().split(separator) for l in contents.split('\n') if l.strip() and not(l.strip().startswith('#'))]
        for linetokens in lines:
            if len(linetokens) >= 3:
                table.append(dict(Experimental = float(linetokens[0]), Predicted = float(linetokens[1]), ID = str(linetokens[2])))
            elif len(linetokens) == 2:
                table.append(dict(Experimental = float(linetokens[0]), Predicted = float(linetokens[1]), ID = id))
                id += 1
            else:
                raise Exception('At least two columns (experimental DDG, predicted DDG) are expected.')
        return table
    except Exception, e:
        raise Exception('An exception occurred parsing the CSV/TSV file: %s' % str(e))