예제 #1
0
def convert_phyche_index_to_dict(phyche_index, alphabet):
    """Convert phyche index from list to dict."""
    # for e in phyche_index:
    #     print e
    len_index_value = len(phyche_index[0])
    k = 0
    for i in range(1, 10):
        if len_index_value < 4**i:
            error_infor = 'Sorry, the number of each index value is must be 4^k.'
            sys.stdout.write(error_infor)
            sys.exit(0)
        if len_index_value == 4**i:
            k = i
            break
    from repDNA.nacutil import make_kmer_list
    kmer_list = make_kmer_list(k, alphabet)
    # print kmer_list
    len_kmer = len(kmer_list)
    phyche_index_dict = {}
    for kmer in kmer_list:
        phyche_index_dict[kmer] = []
    # print phyche_index_dict
    phyche_index = list(zip(*phyche_index))
    for i in range(len_kmer):
        phyche_index_dict[kmer_list[i]] = list(phyche_index[i])

    return phyche_index_dict
def convert_phyche_index_to_dict(phyche_index, alphabet):
    """Convert phyche index from list to dict."""
    # for e in phyche_index:
    #     print e
    len_index_value = len(phyche_index[0])
    k = 0
    for i in range(1, 10):
        if len_index_value < 4**i:
            error_infor = 'Sorry, the number of each index value is must be 4^k.'
            sys.stdout.write(error_infor)
            sys.exit(0)
        if len_index_value == 4**i:
            k = i
            break
    from repDNA.nacutil import make_kmer_list
    kmer_list = make_kmer_list(k, alphabet)
    # print kmer_list
    len_kmer = len(kmer_list)
    phyche_index_dict = {}
    for kmer in kmer_list:
        phyche_index_dict[kmer] = []
    # print phyche_index_dict
    phyche_index = list(zip(*phyche_index))
    for i in range(len_kmer):
        phyche_index_dict[kmer_list[i]] = list(phyche_index[i])

    return phyche_index_dict
예제 #3
0
def write_rna(rna_dict, filename):
    kmer_list = make_kmer_list(k=2, alphabet='ACGU')

    dinucle_prop_vals = {}
    for _property, vals in rna_dict.items():
        for ind, val in enumerate(vals):
            dinucle = kmer_list[ind]
            if dinucle not in dinucle_prop_vals:
                dinucle_prop_vals[dinucle] = []
            dinucle_prop_vals[dinucle].append((_property, val))

    print(len(dinucle_prop_vals['AA']), dinucle_prop_vals)

    with open(filename, 'wb') as f_write:
        pickle.dump(dinucle_prop_vals, f_write, protocol=2)
def write_rna(rna_dict, filename):
    kmer_list = make_kmer_list(k=2, alphabet='ACGU')

    dinucle_prop_vals = {}
    for _property, vals in rna_dict.items():
        for ind, val in enumerate(vals):
            dinucle = kmer_list[ind]
            if dinucle not in dinucle_prop_vals:
                dinucle_prop_vals[dinucle] = []
            dinucle_prop_vals[dinucle].append((_property, val))

    print(len(dinucle_prop_vals['AA']), dinucle_prop_vals)

    with open(filename, 'wb') as f_write:
        pickle.dump(dinucle_prop_vals, f_write, protocol=2)
예제 #5
0
def combine_dna_dict(dna_dict, alphabet, write_file):
    tri_dna_file = os.path.abspath('..') + '/data/mmc3.data'
    with open(tri_dna_file, 'rb') as f:
        dinucle_property_val = pickle.load(f)
        kmer_list = make_kmer_list(k=2, alphabet=alphabet)

        for _property, vals in dna_dict.items():
            for ind, val in enumerate(vals):
                for e in dinucle_property_val[kmer_list[ind]]:
                    if e[0] == _property:
                        print(kmer_list[ind], e, _property)
                        break
                dinucle_property_val[kmer_list[ind]].append((_property, val))

        with open(write_file, 'wb') as f_write:
            pickle.dump(dinucle_property_val, f_write, protocol=2)

    return dinucle_property_val
def combine_dna_dict(dna_dict, alphabet, write_file):
    tri_dna_file = os.path.abspath('..') + '/data/mmc3.data'
    with open(tri_dna_file, 'rb') as f:
        dinucle_property_val = pickle.load(f)
        kmer_list = make_kmer_list(k=2, alphabet=alphabet)

        for _property, vals in dna_dict.items():
            for ind, val in enumerate(vals):
                for e in dinucle_property_val[kmer_list[ind]]:
                    if e[0] == _property:
                        print(kmer_list[ind], e, _property)
                        break
                dinucle_property_val[kmer_list[ind]].append((_property, val))

        with open(write_file, 'wb') as f_write:
            pickle.dump(dinucle_property_val, f_write, protocol=2)

    return dinucle_property_val