{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":116062,"databundleVersionId":14084779,"sourceType":"competition"},{"sourceId":13603083,"sourceType":"datasetVersion","datasetId":8644104}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# Import required libraries\nimport pandas as pd","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Define the function to blend submissions\ndef blend_submissions(sub1_path, sub2_path, sub3_path, weights, output_path):\n    # Load the three submission files\n    sub1 = pd.read_csv(sub1_path, sep=\"\\t\", header=None, names=[\"sequence_id\", \"go_term\", \"score\"])\n    sub2 = pd.read_csv(sub2_path, sep=\"\\t\", header=None, names=[\"sequence_id\", \"go_term\", \"score\"])\n    sub3 = pd.read_csv(sub3_path, sep=\"\\t\", header=None, names=[\"sequence_id\", \"go_term\", \"score\"])\n\n    # Extract weights for each submission\n    w1, w2, w3 = weights\n\n    # Merge all three submissions on sequence_id and go_term\n    merged = sub1.merge(sub2, on=[\"sequence_id\", \"go_term\"], suffixes=(\"_1\", \"_2\"))\n    merged = merged.merge(sub3, on=[\"sequence_id\", \"go_term\"])\n    merged.rename(columns={\"score\": \"score_3\"}, inplace=True)\n\n    # Compute the blended score using weighted sum\n    merged[\"blended_score\"] = (\n        w1 * merged[\"score_1\"] +\n        w2 * merged[\"score_2\"] +\n        w3 * merged[\"score_3\"]\n    )\n\n    # Select final columns\n    final = merged[[\"sequence_id\", \"go_term\", \"blended_score\"]]\n\n    # Save the blended output\n    final.to_csv(output_path, sep=\"\\t\", index=False, header=False)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Define the main function\ndef main():\n    # Define input file paths\n    sub1_path = \"/kaggle/input/cafa-6-protein-function-vault/submission (1).tsv\"\n    sub2_path = \"/kaggle/input/cafa-6-protein-function-vault/submission (2).tsv\"\n    sub3_path = \"/kaggle/input/cafa-6-protein-function-vault/submission (3).tsv\"\n\n    # Define output file path\n    output_path = \"submission.tsv\"\n\n    # Define blending weights (do not need to sum to 1)\n    weights = (1.2, 0.9, 0.7)\n\n    # Call the blending function\n    blend_submissions(sub1_path, sub2_path, sub3_path, weights, output_path)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Call the main function\nif __name__ == \"__main__\":\n    main()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null}]}