<reponame>lee-vivian/foldit-view-data
import csv

BINARY_OPTIONS = ["advanced_mode",
                  "electron_density_panel__backface_culling",
                  "music",
                  "puzzle_dialog__show_beginner",
                  "puzzle_dialog__show_old",
                  "rank_popups",
                  "selection_mode",
                  "selection_mode__show_notes",
                  "sound",
                  "switch_middle_right_click",
                  "switch_residue_colors",
                  "tooltips",
                  "view_options__dark_background",
                  "view_options__gui_fade",
                  "view_options__guide_pulse",
                  "view_options__relative_score_coloring",
                  "view_options__show_backbone_issues",
                  "view_options__show_bondable_atoms",
                  "view_options__show_buried_polars",
                  "view_options__show_clashes",
                  "view_options__show_contact_map_geoms",
                  "view_options__show_hbonds",
                  "view_options__show_helix_hbonds",
                  "view_options__show_issues",
                  "view_options__show_non_protein_hbonds",
                  "view_options__show_other_hbonds",
                  "view_options__show_outlines",
                  "view_options__show_residue_burial",
                  "view_options__show_sidechain_hbonds",
                  "view_options__show_sidechains_with_issues",
                  "view_options__show_voids",
                  "view_options__sym_chain_colors",
                  "view_options__working_pulse_style",
                  ]

CAT_KEYS = ["view_options__current_visor", "view_options__render_style", "view_options__sidechain_mode"]

CAT_OPTIONS = {
    "view_options__current_visor": ["AAColor", "AbegoColor", "CPK", "EnzDes", "Hydro", "Hydro/Score", "Hydro/Score+CPK",
                                    "Hydrophobic", "Ligand Specific", "Rainbow", "Score", "Score/Hydro",
                                    "Score/Hydro+CPK"],
    "view_options__render_style": ["Cartoon", "<NAME>", "<NAME>", "Line", "Line+H", "Line+polarH",
                                   "Sphere", "Stick", "Stick+H", "Stick+polarH", "Trace Line", "Trace Tube"],
    "view_options__sidechain_mode": ["Don't Show (Fast)", "Show All (Slow)", "Show Stubs"]
}

cluster0 = [0.8113829256115827, 0.18642036944583126, 0.4895656515227159, 0.13749375936095856, 0.10773839241138293,
            0.9779331003494758, 0.11063404892661008, 0.9398901647528707, 0.6143784323514728, 0.03195207189216176,
            0.03374937593609586, 0.9027458811782326, 0.3560659011482776, 0.8479281078382427, 0.9333999001497754,
            0.25961058412381427, 0.12131802296555168, 0.3017473789316026, 0.009286070893659511, 0.7596605092361458, 1.0,
            0.5681477783325013, 0.0708936595107339, 0.4215676485272092, 0.046729905142286574, 0.056415376934598103,
            0.1182226660009985, 0.05102346480279581, 0.09775336994508238, 0.8203694458312532, 0.363554667998003,
            0.01108337493759361, 0.7682476285571642, 0.008287568647029456, 0.0012980529206190715, 0.011882176734897654,
            0.004992511233150275, 0.007788317523714428, 0.008187718422366451, 0.0068896655017473786, 0.0,
            0.00019970044932601097, 0.020569146280579133, 0.023564653020469298, 0.8332501248127808, 0.07309036445332003,
            0.7428856714927609, 0.0018971542685971043, 0.2109835247129306, 0.006789815277084373, 0.0016974538192710933,
            0.002196704942586121, 0.0020968547179231155, 0.008487269096355467, 0.0029955067398901645,
            0.0052920619071392914, 0.004193709435846231, 0.010484273589615577, 0.24962556165751373, 0.35656515227159263,
            0.39380928607089366]
cluster1 = [0.9672712933753943, 0.2518730283911672, 0.028686908517350156, 0.06052839116719243, 0.08261041009463722,
            0.9828470031545742, 0.11602917981072555, 0.8286671924290221, 0.11573343848580442, 0.02050473186119874,
            0.03598186119873817, 0.8501577287066246, 0.4953667192429022, 0.7124408517350158, 0.7196372239747634,
            0.42448738170347006, 0.07245662460567823, 0.14018138801261829, 0.018730283911671926, 0.26774447949526814,
            0.9997042586750788, 0.4066443217665615, 0.059739747634069404, 0.20623028391167192, 0.04938880126182965,
            0.060232649842271294, 0.17675473186119875, 0.02651813880126183, 0.1492507886435331, 0.3910686119873817,
            0.14077287066246058, 0.018237381703470033, 0.36001577287066244, 0.01695583596214511, 0.0005914826498422713,
            0.002858832807570978, 0.0015772870662460567, 0.03726340694006309, 0.010745268138801263, 0.01212539432176656,
            0.0, 0.0, 0.09079258675078865, 0.13032334384858044, 0.5668375394321766, 0.12992902208201892,
            0.8578470031545742, 0.0001971608832807571, 0.114846214511041, 0.009660883280757098, 0.0015772870662460567,
            0.0007886435331230284, 0.001084384858044164, 0.0029574132492113563, 9.858044164037855e-05,
            0.0018730283911671925, 0.006309148264984227, 0.0027602523659305996, 0.5256309148264984, 0.25088722397476343,
            0.22348186119873817]
cluster2 = [0.9917398038203408, 0.23128549303045948, 0.15608329031147822, 0.08053691275167785, 0.0770951643434865,
            0.9707451385303735, 0.18206849079332302, 0.880055067974531, 0.276888659438995, 0.011357769747031492,
            0.021510927551196008, 0.8857339528480468, 0.49543968335914645, 0.6933402168301497, 0.8205128205128205,
            0.3939081053175013, 0.17225950782997762, 0.562553777318878, 0.014111168473584582, 0.4654964722078816,
            0.9991395628979521, 0.9144725520564446, 0.8365169506109104, 0.3949406298399587, 0.6005850972293926,
            0.8943383238685252, 0.21562553777318877, 0.1502323180175529, 0.8518327310273619, 0.5303734297022887,
            0.28859060402684567, 0.05506797453106178, 0.5353639648941663, 0.009636895542935812, 0.0012046119428669765,
            0.008432283600068835, 0.012906556530717605, 0.03269660987781793, 0.020994665289967303, 0.02392015143692996,
            0.0, 0.0, 0.0328686972982275, 0.08363448631905007, 0.5140251247633798, 0.2596799173980382,
            0.3293753226639133, 0.0, 0.6217518499397694, 0.008604371020478403, 0.0018929616245052486,
            0.003097573567372225, 0.0017208742040956805, 0.006711409395973154, 0.003097573567372225,
            0.00791602133884013, 0.008604371020478403, 0.007227671657201859, 0.3336775081741525, 0.5468938220616073,
            0.11942866976424023]
cluster3 = [0.9996502273522211, 0.31211379270141076, 0.07939839104582022, 0.04523726244607672, 0.07123702926431152,
            0.9537134196105864, 0.3621312813337997, 0.7443161944735922, 0.2149935875014574, 0.022268858575259416,
            0.037658855077532936, 0.8342077649527807, 0.6503439431036493, 0.559286463798531, 0.5598694182114958,
            0.5760755508919203, 0.15110178384050368, 0.1439897400023318, 0.05363180599277136, 0.1969220006995453,
            0.9979013641133263, 0.4776728459834441, 0.09618747813920951, 0.22840153899965024, 0.09665384166958144,
            0.15926314562201235, 0.19657222805176636, 0.04103999067272939, 0.35944969103416113, 0.3210912906610703,
            0.1198554273055847, 0.04582021685904162, 0.1993704092339979, 0.05083362481053982, 0.0030313629474175117,
            0.002564999417045587, 0.01713885974116824, 0.04896817068905212, 0.028214993587501458, 0.024250903579340094,
            0.0, 0.0, 0.0515331701060977, 0.10551474874664801, 0.22140608604407136, 0.4465430803311181,
            0.07042089308616066, 0.00023318176518596245, 0.8711670747347557, 0.026349539466013757,
            0.0009327270607438498, 0.002098635886673662, 0.002564999417045587, 0.007694998251136761,
            0.0011659088259298124, 0.00466363530371925, 0.009793634137810424, 0.0029147720648245307, 0.3372974233414947,
            0.5511251020170223, 0.11157747464148303]
cluster4 = [0.7504585052728107, 0.18535075653370015, 0.4006189821182944, 0.20437872535534157, 0.11164603392939018,
            0.9825767996331958, 0.11187528656579551, 0.9403943145346172, 0.5499770747363595, 0.026364053186611645,
            0.03255387436955525, 0.9256075194864741, 0.31006419073819347, 0.880903255387437, 0.9635488308115543,
            0.306854653828519, 0.22890875745071068, 0.7127464465841357, 0.0069922054103622195, 0.7132049518569463, 1.0,
            0.9487620357634112, 0.782668500687758, 0.5441311325080238, 0.8247363594681338, 0.8038743695552499,
            0.1020174232003668, 0.202888583218707, 0.9416552040348464, 0.8587803759743237, 0.4649243466299862,
            0.048143053645116916, 0.8345942228335625, 0.01364053186611646, 0.0004585052728106373, 0.003782668500687758,
            0.0034387895460797797, 0.009399358092618064, 0.010774873911049978, 0.013869784502521779, 0.0, 0.0,
            0.030032095369096744, 0.04585052728106373, 0.7723521320495186, 0.0964007336084365, 0.9314534617148097,
            0.00022925263640531865, 0.039775332416322785, 0.0020632737276478678, 0.0009170105456212746,
            0.0009170105456212746, 0.0014901421366345714, 0.007221458046767538, 0.0022925263640531865,
            0.004011921137093076, 0.0019486474094452086, 0.007679963319578175, 0.22627235213204952, 0.4986244841815681,
            0.2751031636863824]
cluster5 = [0.9986497434512558, 0.19038617337294086, 0.05049959492303538, 0.034026465028355386, 0.086821496084256,
            0.9612476370510397, 0.3575479341074804, 0.6797191466378611, 0.16743181204428842, 0.011477180664326223,
            0.014447745071563597, 0.7955711585201188, 0.6574399135835809, 0.6284093977855792, 0.6473129894679989,
            0.36699972994869023, 0.05711585201188226, 0.08344585471239535, 0.03753713205509047, 0.07507426411018094,
            0.9950040507696463, 0.2961112611396165, 0.062381852551984876, 0.12786929516608156, 0.03483661895760194,
            0.06359708344585471, 0.10261949770456387, 0.016608155549554415, 0.1296246286794491, 0.15527950310559005,
            0.054550364569268164, 0.020928976505536052, 0.15257899000810154, 0.014852822036186876, 0.004995949230353767,
            0.016608155549554415, 0.018768566027545234, 0.21347556035646773, 0.012287334593572778, 0.011747231974075074,
            0.0, 0.0, 0.12246826897110451, 0.13597083445854713, 0.40737240075614367, 0.041452876046448824,
            0.07817985417229273, 0.0008101539292465569, 0.5275452335943829, 0.23534971644612476, 0.013097488522819336,
            0.003780718336483932, 0.002835538752362949, 0.004995949230353767, 0.0012152308938698352,
            0.0024304617877396704, 0.12773426951120712, 0.002025384823116392, 0.896705374021064, 0.060626519038617335,
            0.04266810694031866]

clusters = [cluster0, cluster1, cluster2, cluster3, cluster4, cluster5]
cluster_dictionaries = []

for i in range(len(clusters)):
    cluster = clusters[i]
    cluster_dict = dict()

    # Add binary option keys

    for j in range(len(BINARY_OPTIONS)):
        cluster_dict[BINARY_OPTIONS[j]] = int(round(cluster[j]))

    # Add category option keys

    start_idx = len(BINARY_OPTIONS)

    for key in CAT_KEYS:
        options = CAT_OPTIONS[key]
        freq = cluster[start_idx:start_idx+len(options)]
        most_freq_idx = freq.index(max(freq))
        cluster_dict[key] = options[most_freq_idx]
        start_idx += len(options)

    # Add cluster dictionary to list
    cluster_dictionaries.append(cluster_dict)

# Write options values for each cluster to csv file

total_options = cluster_dictionaries[0].keys()
cluster0_values = cluster_dictionaries[0].values()
cluster1_values = cluster_dictionaries[1].values()
cluster2_values = cluster_dictionaries[2].values()
cluster3_values = cluster_dictionaries[3].values()
cluster4_values = cluster_dictionaries[4].values()
cluster5_values = cluster_dictionaries[5].values()

with open('clusters_options.csv', 'w') as csv_file:
    writer = csv.writer(csv_file)
    writer.writerow(['Option', 'Cluster 0', 'Cluster 1', 'Cluster 2', 'Cluster 3', 'Cluster 4', 'Cluster 5'])
    for i in range(len(total_options)):
        writer.writerow([total_options[i], cluster0_values[i], cluster1_values[i], cluster2_values[i],
                         cluster3_values[i], cluster4_values[i], cluster5_values[i]])
