Beispiel #1
0
def read_fam_file(in_file):
    out = {}
    header = ped.get_ped_fields(in_file)
    with open(in_file) as in_handle:
        for line in in_handle:
            if not line.startswith("#"):
                field = line.split(None, 7)[:7]
                if len(field) > 1:
                    info = dict(zip(header, field))
                    out[info["name"]] = info
    return out
Beispiel #2
0
def read_fam_file(in_file):
    out = {}
    header = ped.get_ped_fields(in_file)
    with open(in_file) as in_handle:
        for line in in_handle:
            if not line.startswith("#"):
                field = line.split(None, 8)[:8]
                if len(field) > 1:
                    info = dict(zip(header, field))
                    out[info["name"]] = info
    return out
Beispiel #3
0
def amend_sample(args):
    loaded_subjects = get_subjects(args)
    ped_dict = load_ped_file(args.sample)
    header = get_ped_fields(args.sample)
    with database_transaction(args.db) as c:
        add_columns(header, c, args.clear)
        for k, v in loaded_subjects.items():
            if k in ped_dict:
                item_list = map(quote_string, ped_dict[k])
                sample = zip(header, item_list)
                set_str = ",".join([str(x) + "=" + str(y) for (x, y) in sample])
                sql_query = "update samples set {0} where sample_id={1}"
                c.execute(sql_query.format(set_str, v.sample_id))
Beispiel #4
0
def create_sample_table(cursor, metadata, args):
    NUM_BUILT_IN = 6
    cols = [sql.Column("sample_id", sql.Integer, primary_key=True)]
    fields = get_ped_fields(args.ped_file)
    optional_fields = ["family_id", "name", "paternal_id", "maternal_id",
                       "sex", "phenotype"]
    optional_fields += fields[NUM_BUILT_IN:]
    for field in optional_fields:
        if field == "name":
            cols.append(sql.Column(field, sql.String(50)))
        else:
            cols.append(sql.Column(field, sql.TEXT))

    t = sql.Table("samples", metadata, *cols)
    t.drop(checkfirst=True)
    metadata.create_all(tables=[t])
Beispiel #5
0
def create_sample_table(cursor, metadata, args):
    NUM_BUILT_IN = 6
    cols = [sql.Column("sample_id", sql.Integer, primary_key=True)]
    fields = get_ped_fields(args.ped_file)
    optional_fields = ["family_id", "name", "paternal_id", "maternal_id",
                       "sex", "phenotype"]
    optional_fields += fields[NUM_BUILT_IN:]
    for field in optional_fields:
        if field == "name":
            cols.append(sql.Column(field, sql.String(50)))
        else:
            cols.append(sql.Column(field, sql.TEXT))

    t = sql.Table("samples", metadata, *cols)
    t.drop(checkfirst=True)
    metadata.create_all(tables=[t])