{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceType":"competition","sourceId":116062,"databundleVersionId":14084779},{"sourceType":"datasetVersion","sourceId":13418063,"datasetId":8516164,"databundleVersionId":14131373}],"dockerImageVersionId":31153,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# 🧬 CAFA-6 Quantum GO Predictor - Streaming Inference\n\nThis notebook uses the **FoT Quantum GO Modules** dataset for memory-efficient inference.\n\n**Dataset:** https://www.kaggle.com/datasets/bliztafree/fot-quantum-go-modules\n\n## ⚠️ IMPORTANT: If you see BioPython errors, RESTART THE KERNEL!\n\nThe dataset was updated to remove BioPython dependency. If you see `ModuleNotFoundError: No module named 'Bio'`, click **\"Session\" → \"Restart Session\"** to load the latest dataset version.\n\n**Strategy:**\n- ✅ Process proteins in batches (100 at a time)\n- ✅ Write to disk immediately (no RAM storage)\n- ✅ Memory: ~2GB (fits in Kaggle's 29GB limit)\n- ✅ Time: 15-30 minutes for 224K proteins\n- ✅ **ZERO external dependencies** (pure Python!)\n","metadata":{}},{"cell_type":"code","source":"# Verify pre-installed packages (BioPython and PyTorch are already in Kaggle)\nimport sys\nprint(f\"Python version: {sys.version}\")\n\ntry:\n    import Bio\n    print(f\"✅ BioPython {Bio.__version__} available\")\nexcept ImportError:\n    print(\"❌ BioPython not found\")\n\ntry:\n    import torch\n    print(f\"✅ PyTorch {torch.__version__} available\")\nexcept ImportError:\n    print(\"❌ PyTorch not found\")\n\nprint(\"\\n✅ All dependencies ready!\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-17T19:23:11.441753Z","iopub.execute_input":"2025-10-17T19:23:11.442037Z","iopub.status.idle":"2025-10-17T19:23:13.614896Z","shell.execute_reply.started":"2025-10-17T19:23:11.442014Z","shell.execute_reply":"2025-10-17T19:23:13.613559Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Add dataset to path\nimport sys\nsys.path.insert(0, '/kaggle/input/fot-quantum-go-modules')\n\nprint(\"✅ Module path added\")\nprint(\"   Available modules:\")\n!ls -lh /kaggle/input/fot-quantum-go-modules/*.py | head -5\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-17T19:23:13.616038Z","iopub.execute_input":"2025-10-17T19:23:13.616445Z","iopub.status.idle":"2025-10-17T19:23:13.778363Z","shell.execute_reply.started":"2025-10-17T19:23:13.616417Z","shell.execute_reply":"2025-10-17T19:23:13.776997Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Import the streaming predictor\nfrom quantum_inference_streaming import StreamingQuantumGOPredictor\n\nprint(\"✅ StreamingQuantumGOPredictor imported successfully!\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-17T19:23:13.780221Z","iopub.execute_input":"2025-10-17T19:23:13.780697Z","iopub.status.idle":"2025-10-17T19:23:14.281206Z","shell.execute_reply.started":"2025-10-17T19:23:13.780653Z","shell.execute_reply":"2025-10-17T19:23:14.280067Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Initialize predictor\nprint(\"🔧 Initializing streaming predictor...\\\\n\")\npredictor = StreamingQuantumGOPredictor()\nprint(\"\\\\n✅ Predictor ready!\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-17T19:23:14.282137Z","iopub.execute_input":"2025-10-17T19:23:14.282505Z","iopub.status.idle":"2025-10-17T19:23:15.509173Z","shell.execute_reply.started":"2025-10-17T19:23:14.282482Z","shell.execute_reply":"2025-10-17T19:23:15.508152Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Run streaming inference on all test proteins\nTEST_FASTA = \"/kaggle/input/cafa-6-protein-function-prediction/Test/testsuperset.fasta\"\nOUTPUT_TSV = \"submission.tsv\"\n\nprint(\"🚀 Starting streaming inference...\\\\n\")\npredictor.stream_inference(\n    test_fasta=TEST_FASTA,\n    output_tsv=OUTPUT_TSV,\n    write_every=1000  # Write buffer every 1000 proteins\n)\nprint(\"\\\\n🎉 COMPLETE!\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-17T19:23:15.510264Z","iopub.execute_input":"2025-10-17T19:23:15.510529Z","iopub.status.idle":"2025-10-17T20:15:35.605953Z","shell.execute_reply.started":"2025-10-17T19:23:15.510507Z","shell.execute_reply":"2025-10-17T20:15:35.604448Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Verify output format\nimport os\nimport pandas as pd\n\nprint(\"📊 Submission Statistics:\\\\n\")\nprint(f\"   File size: {os.path.getsize(OUTPUT_TSV) / 1024 / 1024:.1f} MB\")\n\n# Load first 10 lines\ndf = pd.read_csv(OUTPUT_TSV, sep='\\\\t', header=None, names=['protein_id', 'GO_term', 'confidence'], nrows=10)\nprint(f\"\\\\n   First 10 predictions:\")\nprint(df)\n\n# Count total predictions\n!wc -l {OUTPUT_TSV}\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-17T20:15:35.608595Z","iopub.execute_input":"2025-10-17T20:15:35.609287Z","iopub.status.idle":"2025-10-17T20:15:37.709207Z","shell.execute_reply.started":"2025-10-17T20:15:35.609257Z","shell.execute_reply":"2025-10-17T20:15:37.707864Z"}},"outputs":[],"execution_count":null}]}