{"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"}],"dockerImageVersionId":31192,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# CAFA 6 - Simple Frequency Baseline\n# This creates a valid submission using term frequencies\n\nimport pandas as pd\nimport numpy as np\nfrom collections import Counter\nimport os\n\nprint('Simple baseline approach - no external dependencies')\n\nDATA_PATH = '/kaggle/input/cafa-6-protein-function-prediction/'\n\n# Load training labels\nprint('Loading training data...')\ntrain_df = pd.read_csv(f'{DATA_PATH}Train/train_terms.tsv', sep='\\t', \n                       names=['protein_id', 'go_term', 'ontology'])\nprint(f'Loaded {len(train_df)} annotations')\n\n# Calculate term frequencies\nterm_counts = Counter(train_df['go_term'])\ntotal = len(train_df)\n\n# Get top terms with probabilities\ntop_terms = [(term, count/total) for term, count in term_counts.most_common(500)]\nprint(f'Using top {len(top_terms)} terms')\n\n# Load test sequences\nprint('Loading test sequences...')\ntest_proteins = []\nwith open(f'{DATA_PATH}Test/testsuperset.fasta', 'r') as f:\n    for line in f:\n        if line.startswith('>'):\n            prot_id = line.split('|')[1] if '|' in line else line[1:].split()[0]\n            test_proteins.append(prot_id)\n\nprint(f'Found {len(test_proteins)} test proteins')\n\n# Create predictions\nprint('Generating predictions...')\npredictions = []\nfor i, prot_id in enumerate(test_proteins):\n    if (i + 1) % 5000 == 0:\n        print(f'  Processed {i+1}/{len(test_proteins)}')\n    \n    # Predict top terms for each protein\n    for term, base_prob in top_terms[:300]:  # Use top 300 terms per protein\n        # Add some noise\n        prob = base_prob * (0.7 + 0.6 * np.random.random())\n        prob = max(0.001, min(1.0, prob))\n        prob = round(prob, 3)\n        predictions.append(f\"{prot_id}\\t{term}\\t{prob:.3f}\")\n\nprint(f'\\nGenerated {len(predictions)} predictions')\nprint(f'Avg per protein: {len(predictions)/len(test_proteins):.1f}')\n\n# Save submission\nwith open('submission.tsv', 'w') as f:\n    for pred in predictions:\n        f.write(pred + '\\n')\n\nprint('\\nSubmission saved!')\nprint('Sample predictions:')\nfor pred in predictions[:10]:\n    print(pred)\n\nprint('\\n✓ Done!')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null}]}