<jupyter_start><jupyter_text>converted to markdown so i don't accidentally run this again. random colors? colors coded by base? not so sure...codon_list = ['AAA', 'AAT', 'AAC', 'AAG', 'ATA', 'ATT', 'ATC', 'ATG', 'ACA', 'ACT',              'ACC', 'ACG', 'AGA', 'AGT', 'AGC', 'AGG', 'TAA', 'TAT', 'TAC', 'TAG',              'TTA', 'TTT', 'TTC', 'TTG', 'TCA', 'TCT', 'TCC', 'TCG', 'TGA', 'TGT',              'TGC', 'TGG', 'CAA', 'CAT', 'CAC', 'CAG', 'CTA', 'CTT', 'CTC', 'CTG',              'CCA', 'CCT', 'CCC', 'CCG', 'CGA', 'CGT', 'CGC', 'CGG', 'GAA', 'GAT',              'GAC', 'GAG', 'GTA', 'GTT', 'GTC', 'GTG', 'GCA', 'GCT', 'GCC', 'GCG',              'GGA', 'GGT', 'GGC', 'GGG'] start with random color generator to build color dict...def random_color_generator():    r = np.random.uniform(0, 1)    g = np.random.uniform(0, 1)    b = np.random.uniform(0, 1)    a = np.random.uniform(0, 1)    return [r, g, b, a] 'official' codon colors... this is probably going to make for a real ugly barcodecodon_colors = {}for codon in codon_list:    codon_colors[codon] = random_color_generator()codon_colors save to a json for reuseimport jsonwith open('codon_colors.json', 'w') as f:     sort and indent for to make more prettier    json.dump(codon_colors, f, sort_keys=True, indent=4)  start here if we're sticking with those random colors<jupyter_code>with open('codon_colors.json', 'r') as fp:
    codon_colors = json.load(fp)
def list_to_color_matrix(codon_array):
    # mark for garbage if codon_array is nan
    if str(codon_array[0]) == 'nan':
        return

    # otherwise return color matrix
    color_matrix = np.ndarray(shape=(len(codon_array), 4))
    for idx, codon in enumerate(codon_array):
        color_matrix[idx] = np.array(codon_colors[codon])
        
    return color_matrix

data['color_matrix'] = data['codon_array'].apply(list_to_color_matrix)
# can't really figure out why this is thinking we have nan values...
data[data['color_matrix'] == np.nan]
data['color_matrix'][0].shape
# show sequence barcode (chose row 45000 since it's short and the visualization is better)
barcode = data['color_matrix'][45000].reshape(1, len(data['color_matrix'][45000]), 4)

plt.figure(figsize=(12, 8))
plt.imshow(barcode, interpolation='nearest')
plt.show()
color_data = data[['prest_id', 'uniprot_id', 'conc_cf', 'color_matrix']]
color_data.shape
color_data.loc[:11301, :].to_csv('DF_color_1.csv')
color_data.loc[11301:22601, :].to_csv('DF_color_2.csv')
color_data.loc[22601:33901, :].to_csv('DF_color_3.csv')
color_data.loc[33901:, :].to_csv('DF_color_4.csv')
reduced_data = data[['prest_id', 'uniprot_id', 'conc_cf', 'true_nt_seq', 'codon_array']]
reduced_data.to_csv('reduced_features_data.csv')
codon_colors
color_data['color_matrix'][0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17903458213256485, 'fraction_numerical': 0.024135446685878963, 'mean_word_length': 4.678936605316974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '254542', 'license': 'MIT', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1015, 'n_words': 260, 'path': 'archive/josh/color_encoding.ipynb', 'repo_name': 'cnyambura/NovoNordisk_Capstone', 'size': '2776'}