diff --git a/HW2/HW2.ipynb b/HW2/HW2.ipynb new file mode 100644 index 0000000..b1d56ea --- /dev/null +++ b/HW2/HW2.ipynb @@ -0,0 +1,621 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# HW2 – Using APIs for UniProt and Ensembl\n", + "**Author:** Victoria Orlova " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "import json\n", + "import re\n", + "import pandas as pd\n", + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def http_function(endpoint, **kwargs):\n", + " \"\"\"\n", + " Generic HTTP GET function that returns the JSON response.\n", + " \"\"\"\n", + " headers = kwargs.get('headers', {})\n", + " kwargs['headers'] = headers\n", + " response = requests.get(endpoint, **kwargs)\n", + " return response" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def get_uniprot(accession):\n", + " \"\"\"\n", + " Retrieve protein data from UniProt REST API for a single accession.\n", + " Returns a Response object.\n", + " \"\"\"\n", + " endpoint = f\"https://rest.uniprot.org/uniprotkb/{accession}\"\n", + " return http_function(endpoint, headers={'Accept': 'application/json'})" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "def uniprot_parse_response(resp):\n", + " \"\"\"\n", + " Parse UniProt JSON response (requests.Response object) and extract:\n", + " organism, geneInfo, sequenceInfo, type.\n", + " Returns a dictionary with those fields, or {'error': ...} on failure.\n", + " \"\"\"\n", + " try:\n", + " data = resp.json()\n", + " except Exception as e:\n", + " return {'error': f'Failed to parse JSON: {str(e)}'}\n", + "\n", + " try:\n", + " organism = data.get('organism', {}).get('scientificName', 'N/A')\n", + " geneInfo = data.get('genes', [])\n", + " seq = data.get('sequence', {})\n", + " sequenceInfo = {\n", + " 'value': seq.get('value', ''),\n", + " 'length': seq.get('length', 'N/A'),\n", + " 'molWeight': seq.get('molWeight', 'N/A'),\n", + " 'crc64': seq.get('crc64', 'N/A'),\n", + " 'md5': seq.get('md5', 'N/A')\n", + " }\n", + " entry_type = 'protein'\n", + " return {\n", + " 'organism': organism,\n", + " 'geneInfo': geneInfo,\n", + " 'sequenceInfo': sequenceInfo,\n", + " 'type': entry_type\n", + " }\n", + " except Exception as e:\n", + " return {'error': f'UniProt parsing failed: {str(e)}'}" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "def get_ensembl(id):\n", + " \"\"\"\n", + " Retrieve gene/transcript/protein data from Ensembl REST API.\n", + " Returns a Response object.\n", + " \"\"\"\n", + " endpoint = f\"https://rest.ensembl.org/lookup/id/{id}\"\n", + " headers = {'Content-Type': 'application/json'}\n", + " return http_function(endpoint, headers=headers)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "def ensembl_parse_response(resp: dict):\n", + " \"\"\"\n", + " Parse Ensembl JSON response and extract:\n", + " object_type, assembly_name, species, db_type, biotype,\n", + " display_name, id, description, canonical_transcript, source\n", + " \"\"\"\n", + " \n", + " try:\n", + " resp = resp.json()\n", + " except Exception as e:\n", + " return {'error': f'Failed to parse JSON: {str(e)}'}\n", + " \n", + " try:\n", + " if 'error' in resp:\n", + " return {'error': resp['error']}\n", + " \n", + " return {\n", + " 'object_type': resp.get('object_type', 'N/A'),\n", + " 'assembly_name': resp.get('assembly_name', 'N/A'),\n", + " 'species': resp.get('species', 'N/A'),\n", + " 'db_type': resp.get('db_type', 'N/A'),\n", + " 'biotype': resp.get('biotype', 'N/A'),\n", + " 'display_name': resp.get('display_name', 'N/A'),\n", + " 'id': resp.get('id', 'N/A'),\n", + " 'description': resp.get('description', 'N/A'),\n", + " 'canonical_transcript': resp.get('canonical_transcript', 'N/A'),\n", + " 'source': resp.get('source', 'N/A')\n", + " }\n", + " except Exception as e:\n", + " return {'error': f'Ensembl parsing failed: {str(e)}'}" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "def main(ids):\n", + " \"\"\"\n", + " Accepts a list of IDs, determines their type (UniProt or Ensembl) using regex,\n", + " fetches and parses data from the appropriate API, and returns a pandas DataFrame.\n", + " If an ID is invalid or an error occurs, an error column is added.\n", + " \"\"\"\n", + " uniprot_pattern = r'^[A-Z][0-9][A-Z0-9]{3,}[0-9]$'\n", + " ensembl_pattern = r'^ENS[A-Z]*[GTEP][0-9]{11}$'\n", + "\n", + " records = []\n", + "\n", + " for raw_id in ids:\n", + " acc = raw_id.strip()\n", + " record = {'ID': acc}\n", + "\n", + " try:\n", + " if re.match(uniprot_pattern, acc):\n", + " resp = get_uniprot(acc)\n", + " info = uniprot_parse_response(resp)\n", + " if 'error' in info:\n", + " record['error'] = info['error']\n", + " else:\n", + " record.update(info)\n", + " record['geneInfo'] = json.dumps(record['geneInfo'])\n", + " record['sequenceInfo'] = json.dumps(record['sequenceInfo'])\n", + "\n", + " elif re.match(ensembl_pattern, acc):\n", + " resp = get_ensembl(acc)\n", + " info = ensembl_parse_response(resp)\n", + " if 'error' in info:\n", + " record['error'] = info['error']\n", + " else:\n", + " record.update(info)\n", + "\n", + " else:\n", + " record['error'] = 'ID format not recognized'\n", + "\n", + " except requests.exceptions.HTTPError as e:\n", + " error_msg = f'HTTP error: {e.response.status_code}'\n", + " try:\n", + " err_data = e.response.json()\n", + " if 'messages' in err_data:\n", + " error_msg += ' - ' + ', '.join(err_data['messages'])\n", + " elif 'error' in err_data:\n", + " error_msg += ' - ' + err_data['error']\n", + " except:\n", + " pass\n", + " record['error'] = error_msg\n", + " except Exception as e:\n", + " record['error'] = f'Unexpected error: {str(e)}'\n", + "\n", + " records.append(record)\n", + "\n", + " df = pd.DataFrame(records)\n", + " if 'error' in df.columns:\n", + " cols = [c for c in df.columns if c != 'error'] + ['error']\n", + " df = df[cols]\n", + " return df" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Testing with the example IDs from test_data.txt" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_uniprot('P11473')" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_uniprot('helloworld')" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'url': 'http://rest.uniprot.org/uniprotkb/helloworld',\n", + " 'messages': [\"The 'accession' value has invalid format. It should be a valid UniProtKB accession\"]}" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_uniprot('helloworld').json()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'organism': 'Homo sapiens',\n", + " 'geneInfo': [{'geneName': {'evidences': [{'evidenceCode': 'ECO:0000312',\n", + " 'source': 'HGNC',\n", + " 'id': 'HGNC:12679'}],\n", + " 'value': 'VDR'},\n", + " 'synonyms': [{'value': 'NR1I1'}]}],\n", + " 'sequenceInfo': {'value': 'MEAMAASTSLPDPGDFDRNVPRICGVCGDRATGFHFNAMTCEGCKGFFRRSMKRKALFTCPFNGDCRITKDNRRHCQACRLKRCVDIGMMKEFILTDEEVQRKREMILKRKEEEALKDSLRPKLSEEQQRIIAILLDAHHKTYDPTYSDFCQFRPPVRVNDGGGSHPSRPNSRHTPSFSGDSSSSCSDHCITSSDMMDSSSFSNLDLSEEDSDDPSVTLELSQLSMLPHLADLVSYSIQKVIGFAKMIPGFRDLTSEDQIVLLKSSAIEVIMLRSNESFTMDDMSWTCGNQDYKYRVSDVTKAGHSLELIEPLIKFQVGLKKLNLHEEEHVLLMAICIVSPDRPGVQDAALIEAIQDRLSNTLQTYIRCRHPPPGSHLLYAKMIQKLADLRSLNEEHSKQYRCLSFQPECSMKLTPLVLEVFGNEIS',\n", + " 'length': 427,\n", + " 'molWeight': 48289,\n", + " 'crc64': 'F95F300D042C4CB7',\n", + " 'md5': '0D963ACD4A34674368324EE026023597'},\n", + " 'type': 'protein'}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "uniprot_parse_response(get_uniprot('P11473'))" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_ensembl('ENSMUSG00000041147')" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_ensembl('helloworld')" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'error': \"ID 'helloworld' not found\"}" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_ensembl('helloworld').json()" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'object_type': 'Gene',\n", + " 'assembly_name': 'GRCm39',\n", + " 'species': 'mus_musculus',\n", + " 'db_type': 'core',\n", + " 'biotype': 'protein_coding',\n", + " 'display_name': 'Brca2',\n", + " 'id': 'ENSMUSG00000041147',\n", + " 'description': 'breast cancer 2, early onset [Source:MGI Symbol;Acc:MGI:109337]',\n", + " 'canonical_transcript': 'ENSMUST00000044620.11',\n", + " 'source': 'ensembl_havana'}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ensembl_parse_response(get_ensembl('ENSMUSG00000041147'))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
IDorganismgeneInfosequenceInfotypeobject_typeassembly_namespeciesdb_typebiotypedisplay_nameiddescriptioncanonical_transcriptsourceerror
0P11473Homo sapiens[{\"geneName\": {\"evidences\": [{\"evidenceCode\": ...{\"value\": \"MEAMAASTSLPDPGDFDRNVPRICGVCGDRATGFH...proteinNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
1Q91XI3Ictidomys tridecemlineatus[{\"geneName\": {\"value\": \"INS\"}}]{\"value\": \"MALWTRLLPLLALLALLGPDPAQAFVNQHLCGSHL...proteinNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
2helloNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNID format not recognized
3ENSG00000157764NaNNaNNaNNaNGeneGRCh38homo_sapienscoreprotein_codingBRAFENSG00000157764B-Raf proto-oncogene, serine/threonine kinase ...ENST00000646891.2ensembl_havanaNaN
4ENSG00000139618NaNNaNNaNNaNGeneGRCh38homo_sapienscoreprotein_codingBRCA2ENSG00000139618BRCA2 DNA repair associated [Source:HGNC Symbo...ENST00000380152.8ensembl_havanaNaN
\n", + "
" + ], + "text/plain": [ + " ID organism \\\n", + "0 P11473 Homo sapiens \n", + "1 Q91XI3 Ictidomys tridecemlineatus \n", + "2 hello NaN \n", + "3 ENSG00000157764 NaN \n", + "4 ENSG00000139618 NaN \n", + "\n", + " geneInfo \\\n", + "0 [{\"geneName\": {\"evidences\": [{\"evidenceCode\": ... \n", + "1 [{\"geneName\": {\"value\": \"INS\"}}] \n", + "2 NaN \n", + "3 NaN \n", + "4 NaN \n", + "\n", + " sequenceInfo type object_type \\\n", + "0 {\"value\": \"MEAMAASTSLPDPGDFDRNVPRICGVCGDRATGFH... protein NaN \n", + "1 {\"value\": \"MALWTRLLPLLALLALLGPDPAQAFVNQHLCGSHL... protein NaN \n", + "2 NaN NaN NaN \n", + "3 NaN NaN Gene \n", + "4 NaN NaN Gene \n", + "\n", + " assembly_name species db_type biotype display_name \\\n", + "0 NaN NaN NaN NaN NaN \n", + "1 NaN NaN NaN NaN NaN \n", + "2 NaN NaN NaN NaN NaN \n", + "3 GRCh38 homo_sapiens core protein_coding BRAF \n", + "4 GRCh38 homo_sapiens core protein_coding BRCA2 \n", + "\n", + " id description \\\n", + "0 NaN NaN \n", + "1 NaN NaN \n", + "2 NaN NaN \n", + "3 ENSG00000157764 B-Raf proto-oncogene, serine/threonine kinase ... \n", + "4 ENSG00000139618 BRCA2 DNA repair associated [Source:HGNC Symbo... \n", + "\n", + " canonical_transcript source error \n", + "0 NaN NaN NaN \n", + "1 NaN NaN NaN \n", + "2 NaN NaN ID format not recognized \n", + "3 ENST00000646891.2 ensembl_havana NaN \n", + "4 ENST00000380152.8 ensembl_havana NaN " + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "main(['P11473', 'Q91XI3', 'hello', 'ENSG00000157764', 'ENSG00000139618'])" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.7" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/HW3/HW3.ipynb b/HW3/HW3.ipynb new file mode 100644 index 0000000..ce360be --- /dev/null +++ b/HW3/HW3.ipynb @@ -0,0 +1,460 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# HW3 " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#!pip install openmeteo_requests" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import openmeteo_requests\n", + "from datetime import datetime" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Iterator classes" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "class IncreaseSpeed:\n", + " \"\"\"\n", + " Iterator for increasing speed step by step.\n", + " \"\"\"\n", + " def __init__(self, current_speed: int, max_speed: int, step: int = 10):\n", + " self.current = current_speed\n", + " self.max_speed = max_speed\n", + " self.step = step\n", + "\n", + " def __iter__(self):\n", + " return self\n", + "\n", + " def __next__(self):\n", + " if self.current + self.step > self.max_speed:\n", + " raise StopIteration\n", + " self.current += self.step\n", + " return self.current" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "class DecreaseSpeed:\n", + " \"\"\"\n", + " Iterator for decreasing speed step by step.\n", + " \"\"\"\n", + " def __init__(self, current_speed: int, min_speed: int = 0, step: int = 10):\n", + " self.current = current_speed\n", + " self.min_speed = min_speed\n", + " self.step = step\n", + "\n", + " def __iter__(self):\n", + " return self\n", + "\n", + " def __next__(self):\n", + " if self.current - self.step < self.min_speed:\n", + " raise StopIteration\n", + " self.current -= self.step\n", + " return self.current" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Car class" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "class Car:\n", + " _total_cars_on_road = 0\n", + "\n", + " def __init__(self, max_speed: int, current_speed: int = 0):\n", + " self.max_speed = max_speed\n", + " self.current_speed = current_speed\n", + " # Car is considered on the road if its speed > 0\n", + " self.state = current_speed > 0\n", + " if self.state:\n", + " Car._total_cars_on_road += 1\n", + "\n", + " # --- regular methods ---\n", + " def accelerate(self, upper_border=None, step=10):\n", + " \"\"\"Increase speed, optionally to a given border.\"\"\"\n", + " old_speed = self.current_speed\n", + "\n", + " if not self.state: # car is parked\n", + " self.state = True\n", + " Car._total_cars_on_road += 1\n", + " target = upper_border if upper_border is not None else step\n", + " if target > self.max_speed:\n", + " target = self.max_speed\n", + " self.current_speed = target\n", + " print(f\"INFO: The speed of this car has been increased from {old_speed} to {self.current_speed}\")\n", + " return\n", + " \n", + " inc = IncreaseSpeed(self.current_speed, self.max_speed, step) # Car on road\n", + " if upper_border is not None:\n", + " # gradually increase up to upper_border\n", + " for new_speed in inc:\n", + " if new_speed > upper_border:\n", + " break\n", + " self.current_speed = new_speed\n", + " print(f\"INFO: Speed increases by {step}\")\n", + " if self.current_speed < upper_border: # ensure final speed == upper_border\n", + " self.current_speed = upper_border\n", + " else:\n", + " try: # increase by one step\n", + " self.current_speed = next(inc)\n", + " print(f\"INFO: Speed increases by {step}\")\n", + " except StopIteration:\n", + " pass\n", + " print(f\"INFO: The speed of this car has been increased from {old_speed} to {self.current_speed}\")\n", + "\n", + " def brake(self, lower_border=None, step=10):\n", + " \"\"\"Decrease speed, optionally to a given border.\"\"\"\n", + " if not self.state:\n", + " print(\"INFO: Car is already parked.\")\n", + " return\n", + "\n", + " old_speed = self.current_speed\n", + " dec = DecreaseSpeed(self.current_speed, min_speed=0, step=step)\n", + " if lower_border is not None:\n", + " for new_speed in dec:\n", + " if new_speed < lower_border:\n", + " break\n", + " self.current_speed = new_speed\n", + " print(f\"INFO: Speed decreases by {step}\")\n", + " if self.current_speed > lower_border:\n", + " self.current_speed = max(lower_border, 0)\n", + " else:\n", + " try:\n", + " self.current_speed = next(dec)\n", + " print(f\"INFO: Speed decreases by {step}\")\n", + " except StopIteration:\n", + " pass\n", + " print(f\"INFO: The speed of this car has been decreased from {old_speed} to {self.current_speed}\")\n", + "\n", + "\n", + " def parking(self):\n", + " \"\"\"Take the car off the road (speed must be 0).\"\"\"\n", + " if not self.state:\n", + " print(\"INFO: Car is already parked.\")\n", + " return\n", + " # bring speed to 0 if needed\n", + " if self.current_speed > 0:\n", + " self.brake(lower_border=0)\n", + " else:\n", + " print(f\"INFO: The speed of this car has been decreased from {self.current_speed} to {self.current_speed}\")\n", + " self.state = False\n", + " Car._total_cars_on_road -= 1\n", + " print(\"Parking the car...\")\n", + "\n", + " @classmethod\n", + " def total_cars(cls):\n", + " \"\"\"Return the total number of cars currently on the road.\"\"\"\n", + " return cls._total_cars_on_road\n", + "\n", + " @staticmethod\n", + " def show_weather():\n", + " \"\"\"Fetch and display current weather in St. Petersburg.\"\"\"\n", + " openmeteo = openmeteo_requests.Client()\n", + " url = \"https://api.open-meteo.com/v1/forecast\"\n", + " params = {\n", + " \"latitude\": 59.9386,\n", + " \"longitude\": 30.3141,\n", + " \"current\": [\"temperature_2m\", \"apparent_temperature\", \"rain\", \"wind_speed_10m\"],\n", + " \"wind_speed_unit\": \"ms\",\n", + " \"timezone\": \"Europe/Moscow\"\n", + " }\n", + " try:\n", + " response = openmeteo.weather_api(url, params=params)[0]\n", + " current = response.Current()\n", + " temp = current.Variables(0).Value()\n", + " apparent_temp = current.Variables(1).Value()\n", + " rain = current.Variables(2).Value()\n", + " wind = current.Variables(3).Value()\n", + "\n", + " print(f\"Current temperature: {round(temp, 0)} C\")\n", + " print(f\"Current apparent_temperature: {round(apparent_temp, 0)} C\")\n", + " print(f\"Current rain: {rain} mm\")\n", + " print(f\"Current wind_speed: {round(wind, 1)} m/s\")\n", + " except Exception as e:\n", + " print(f\"Weather service error: {e}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Testing with the provided example" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total cars on road: 2\n" + ] + } + ], + "source": [ + "car1 = Car(100, 20) # max_speed = 100, initial speed = 5\n", + "car2 = Car(60, 30) # max_speed = 60, initial speed = 30\n", + "car3 = Car(100, 0) # a car that is off road upon creation\n", + "print(f\"Total cars on road: {Car.total_cars()}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "INFO: Speed increases by 10\n", + "INFO: Speed increases by 10\n", + "INFO: Speed increases by 10\n", + "INFO: Speed increases by 10\n", + "INFO: Speed increases by 10\n", + "INFO: Speed increases by 10\n", + "INFO: Speed increases by 10\n", + "INFO: Speed increases by 10\n", + "INFO: The speed of this car has been increased from 20 to 100\n" + ] + } + ], + "source": [ + "car1.accelerate(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "INFO: Speed increases by 10\n", + "INFO: Speed increases by 10\n", + "INFO: The speed of this car has been increased from 30 to 50\n" + ] + } + ], + "source": [ + "car2.accelerate(50)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Speed of car 1: 100\n" + ] + } + ], + "source": [ + "print(\"Speed of car 1:\", car1.current_speed)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Speed of car 2: 50\n" + ] + } + ], + "source": [ + "print(\"Speed of car 2:\", car2.current_speed)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: The speed of this car has been decreased from 100 to 10\n" + ] + } + ], + "source": [ + "car1.brake(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: Speed decreases by 10\n", + "INFO: The speed of this car has been decreased from 50 to 0\n", + "Total cars on road: 2\n", + "INFO: The speed of this car has been decreased from 0 to 0\n", + "Parking the car...\n", + "Total cars on road: 1\n" + ] + } + ], + "source": [ + "car2.brake(0)\n", + "print(\"Total cars on road:\", Car.total_cars())\n", + "car2.parking()\n", + "print(\"Total cars on road:\", Car.total_cars())" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "INFO: The speed of this car has been increased from 0 to 80\n", + "Current temperature: 6.0 C\n", + "Current apparent_temperature: 1.0 C\n", + "Current rain: 0.0 mm\n", + "Current wind_speed: 5.9 m/s\n", + "Total cars on road: 2\n" + ] + } + ], + "source": [ + "car3.accelerate(80)# car3 is now on the road\n", + "car3.show_weather()\n", + "print(\"Total cars on road:\", Car.total_cars())" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "INFO: The speed of this car has been increased from 0 to 10\n", + "Total cars on road: 3\n" + ] + } + ], + "source": [ + "car2.accelerate(10) # # car2 goes from parking on the road\n", + "print(\"Total cars on road:\", Car.total_cars())" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Current temperature: 6.0 C\n", + "Current apparent_temperature: 1.0 C\n", + "Current rain: 0.0 mm\n", + "Current wind_speed: 5.9 m/s\n" + ] + } + ], + "source": [ + "Car.show_weather()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.7" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/HW4/HW4.ipynb b/HW4/HW4.ipynb new file mode 100644 index 0000000..1c22519 --- /dev/null +++ b/HW4/HW4.ipynb @@ -0,0 +1,1118 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "01aeccd3", + "metadata": {}, + "outputs": [], + "source": [ + "import re\n", + "import json\n", + "import subprocess\n", + "import requests\n", + "import os\n", + "from Bio import SeqIO\n", + "from Bio.Seq import Seq\n", + "from Bio.SeqRecord import SeqRecord\n", + "from collections import Counter" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "60bcff78", + "metadata": {}, + "outputs": [], + "source": [ + "class MyFastaParser:\n", + " def __init__(self, file_name):\n", + " self.filename = file_name\n", + "\n", + " # API helpers (from HW2)\n", + " def _http_function(self, endpoint, **kwargs):\n", + " \"\"\"Generic HTTP GET function returning response object.\"\"\"\n", + " headers = kwargs.get('headers', {})\n", + " if 'User-Agent' not in headers:\n", + " headers['User-Agent'] = 'HW4/1.0 (student@example.com)'\n", + " kwargs['headers'] = headers\n", + " response = requests.get(endpoint, **kwargs)\n", + " return response\n", + "\n", + " def _get_uniprot(self, accession):\n", + " \"\"\"Get UniProt entry for a single accession.\"\"\"\n", + " endpoint = f\"https://rest.uniprot.org/uniprotkb/{accession}\"\n", + " return self._http_function(endpoint, headers={'Accept': 'application/json'})\n", + "\n", + " def _get_ensembl(self, id):\n", + " \"\"\"Get Ensembl entry for a single ID.\"\"\"\n", + " endpoint = f\"https://rest.ensembl.org/lookup/id/{id}\"\n", + " headers = {'Content-Type': 'application/json'}\n", + " return self._http_function(endpoint, headers=headers)\n", + "\n", + " def _uniprot_parse_response(self, resp):\n", + " \"\"\"Parse UniProt JSON response.\"\"\"\n", + " try:\n", + " data = resp.json()\n", + " except Exception as e:\n", + " return {'error': f'Failed to parse JSON: {str(e)}'}\n", + "\n", + " try:\n", + " organism = data.get('organism', {}).get('scientificName', 'N/A')\n", + " geneInfo = data.get('genes', [])\n", + " seq = data.get('sequence', {})\n", + " sequenceInfo = {\n", + " 'value': seq.get('value', ''),\n", + " 'length': seq.get('length', 'N/A'),\n", + " 'molWeight': seq.get('molWeight', 'N/A'),\n", + " 'crc64': seq.get('crc64', 'N/A'),\n", + " 'md5': seq.get('md5', 'N/A')\n", + " }\n", + " entry_type = 'protein'\n", + " return {\n", + " 'organism': organism,\n", + " 'geneInfo': geneInfo,\n", + " 'sequenceInfo': sequenceInfo,\n", + " 'type': entry_type\n", + " }\n", + " except Exception as e:\n", + " return {'error': f'UniProt parsing failed: {str(e)}'}\n", + "\n", + " def _ensembl_parse_response(self, resp):\n", + " \"\"\"Parse Ensembl JSON response.\"\"\"\n", + " try:\n", + " data = resp.json()\n", + " except Exception as e:\n", + " return {'error': f'Failed to parse JSON: {str(e)}'}\n", + "\n", + " try:\n", + " if 'error' in data:\n", + " return {'error': data['error']}\n", + " return {\n", + " 'object_type': data.get('object_type', 'N/A'),\n", + " 'assembly_name': data.get('assembly_name', 'N/A'),\n", + " 'species': data.get('species', 'N/A'),\n", + " 'db_type': data.get('db_type', 'N/A'),\n", + " 'biotype': data.get('biotype', 'N/A'),\n", + " 'display_name': data.get('display_name', 'N/A'),\n", + " 'id': data.get('id', 'N/A'),\n", + " 'description': data.get('description', 'N/A'),\n", + " 'canonical_transcript': data.get('canonical_transcript', 'N/A'),\n", + " 'source': data.get('source', 'N/A')\n", + " }\n", + " except Exception as e:\n", + " return {'error': f'Ensembl parsing failed: {str(e)}'}\n", + "\n", + " def _access_database(self, id, database, seq_description, seq_sequence):\n", + " \"\"\"\n", + " Call the appropriate API and parse the response.\n", + " Returns a dictionary with database info.\n", + " \"\"\"\n", + " if database == 'uniprot':\n", + " resp = self._get_uniprot(id)\n", + " info = self._uniprot_parse_response(resp)\n", + " return {'DB_name': 'uniprot', 'info': info}\n", + " elif database == 'ensembl':\n", + " resp = self._get_ensembl(id)\n", + " info = self._ensembl_parse_response(resp)\n", + " return {'DB_name': 'ensembl', 'info': info}\n", + " else:\n", + " return {'error': f'Unknown database: {database}'}\n", + "\n", + " # fallback stats with biopython\n", + " def _compute_stats_biopython(self):\n", + " \"\"\"Compute FASTA statistics using Biopython (fallback if seqkit not found).\"\"\"\n", + " sequences = list(SeqIO.parse(self.filename, 'fasta'))\n", + " if not sequences:\n", + " return {'error': 'No sequences found in file'}\n", + "\n", + " lengths = [len(rec.seq) for rec in sequences]\n", + " lengths_sorted = sorted(lengths)\n", + " n = len(lengths_sorted)\n", + "\n", + " # Basic stats\n", + " total_len = sum(lengths)\n", + " min_len = min(lengths)\n", + " max_len = max(lengths)\n", + " avg_len = total_len / n\n", + "\n", + " # Quartiles\n", + " q1_index = n // 4\n", + " q2_index = n // 2\n", + " q3_index = 3 * n // 4\n", + " q1 = lengths_sorted[q1_index]\n", + " q2 = lengths_sorted[q2_index] if n % 2 == 0 else lengths_sorted[q2_index]\n", + " q3 = lengths_sorted[q3_index]\n", + "\n", + " # N50\n", + " half_total = total_len / 2\n", + " cum = 0\n", + " n50 = 0\n", + " for l in lengths_sorted[::-1]:\n", + " cum += l\n", + " if cum >= half_total:\n", + " n50 = l\n", + " break\n", + " n50_num = sum(1 for l in lengths if l >= n50)\n", + "\n", + " # GC content\n", + " all_seq = ''.join(str(rec.seq) for rec in sequences)\n", + " gc_count = all_seq.count('G') + all_seq.count('C')\n", + " gc_percent = (gc_count / len(all_seq) * 100) if all_seq else 0\n", + "\n", + " # type (DNA/Protein)\n", + " allowed_dna = set('ATGCUatgcuNn')\n", + " is_dna = True\n", + " for rec in sequences:\n", + " if any(ch not in allowed_dna for ch in str(rec.seq).upper()):\n", + " is_dna = False\n", + " break\n", + " seq_type = 'DNA' if is_dna else 'Protein'\n", + "\n", + " return {\n", + " 'fasta_seqkit_stat_info': {\n", + " 'format': 'FASTA',\n", + " 'type': seq_type,\n", + " 'num_seqs': n,\n", + " 'sum_len': total_len,\n", + " 'min_len': min_len,\n", + " 'avg_len': round(avg_len, 2),\n", + " 'max_len': max_len,\n", + " 'Q1': q1,\n", + " 'Q2': q2,\n", + " 'Q3': q3,\n", + " 'sum_gap': 0, # not computed\n", + " 'N50': n50,\n", + " 'N50_num': n50_num,\n", + " 'Q20(%)': 0, # not relevant for FASTA\n", + " 'Q30(%)': 0,\n", + " 'AvgQual': 0,\n", + " 'GC(%)': round(gc_percent, 2),\n", + " 'sum_n': all_seq.upper().count('N')\n", + " },\n", + " 'fasta_type': seq_type,\n", + " 'fasta_num_seqs': n\n", + " }\n", + "\n", + " def seqkit_stats(self):\n", + " \"\"\"Call seqkit stats; if seqkit not found, use biopython fallback.\"\"\"\n", + " try:\n", + " result = subprocess.run(\n", + " ['seqkit', 'stats', self.filename],\n", + " capture_output=True,\n", + " text=True,\n", + " check=False\n", + " )\n", + " if result.returncode != 0:\n", + " # seqkit returned an error – fall back to biopython\n", + " return self._compute_stats_biopython()\n", + "\n", + " # parse the tab-separated output\n", + " lines = result.stdout.strip().split('\\n')\n", + " if len(lines) < 2:\n", + " return self._compute_stats_biopython()\n", + " \n", + " # the header line: file format type num_seqs sum_len min_len avg_len max_len\n", + " header = lines[0].split('\\t')\n", + " data = lines[1].split('\\t')\n", + " stats = dict(zip(header, data))\n", + "\n", + " # determine file type: \"DNA\" or \"Protein\" from the 'type' column\n", + " file_type = stats.get('type', 'Unknown').strip()\n", + " if file_type not in ('DNA', 'Protein', 'RNA'):\n", + " file_type = 'Unknown'\n", + "\n", + " numeric_fields = ['num_seqs', 'sum_len', 'min_len', 'avg_len', 'max_len',\n", + " 'Q1', 'Q2', 'Q3', 'sum_gap', 'N50', 'N50_num',\n", + " 'Q20(%)', 'Q30(%)', 'AvgQual', 'GC(%)', 'sum_n']\n", + " for field in numeric_fields:\n", + " if field in stats:\n", + " try:\n", + " stats[field] = int(stats[field]) if '.' not in stats[field] else float(stats[field])\n", + " except:\n", + " pass\n", + "\n", + " return {\n", + " 'fasta_seqkit_stat_info': stats,\n", + " 'fasta_type': file_type,\n", + " 'fasta_num_seqs': int(stats.get('num_seqs', 0))\n", + " }\n", + "\n", + " except FileNotFoundError:\n", + " # seqkit not installed – use Biopython fallback\n", + " return self._compute_stats_biopython()\n", + " except Exception as e:\n", + " return {'error': str(e)}\n", + "\n", + " def biopython_parser(self, seqkit_result):\n", + " \"\"\"\n", + " Parse FASTA file with Biopython, extract IDs from descriptions,\n", + " and call the appropriate database.\n", + " Returns dictionary with results.\n", + " \"\"\"\n", + " # determine which regex to use based on file type\n", + " file_type = seqkit_result.get('fasta_type', 'Unknown')\n", + " if file_type == 'Protein':\n", + " # uniProt pattern: [A-Z][0-9][A-Z0-9]{3,}[0-9]\n", + " id_pattern = re.compile(r'[A-Z][0-9][A-Z0-9]{3,}[0-9]')\n", + " database = 'uniprot'\n", + " elif file_type == 'DNA':\n", + " # ensembl pattern: ENS[A-Z]*[GTEP][0-9]{11}\n", + " id_pattern = re.compile(r'ENS[A-Z]*[GTEP][0-9]{11}')\n", + " database = 'ensembl'\n", + " else:\n", + " id_pattern = None\n", + " database = None\n", + "\n", + " output = {}\n", + " warnings = []\n", + "\n", + " try:\n", + " for record in SeqIO.parse(self.filename, 'fasta'):\n", + " desc = record.description\n", + " seq = str(record.seq)\n", + "\n", + " # for known ID patterns\n", + " id_found = None\n", + " if id_pattern:\n", + " # pre-determined pattern\n", + " match = id_pattern.search(desc)\n", + " if match:\n", + " id_found = match.group()\n", + " else:\n", + " # Try both patterns if type unknown\n", + " uniprot_pat = re.compile(r'[A-Z][0-9][A-Z0-9]{3,}[0-9]')\n", + " ensembl_pat = re.compile(r'ENS[A-Z]*[GTEP][0-9]{11}')\n", + " match = uniprot_pat.search(desc)\n", + " if match:\n", + " id_found = match.group()\n", + " database = 'uniprot'\n", + " else:\n", + " match = ensembl_pat.search(desc)\n", + " if match:\n", + " id_found = match.group()\n", + " database = 'ensembl'\n", + "\n", + " if id_found and database:\n", + " # call the API\n", + " result = self._access_database(id_found, database, desc, seq)\n", + " if 'error' in result.get('info', {}):\n", + " warnings.append({'No ID match found.'})\n", + " else:\n", + " output[f'file_info_{id_found}'] = {\n", + " 'description': desc,\n", + " 'sequence': seq\n", + " }\n", + " output[f'database_info_{id_found}'] = result['info']\n", + " else:\n", + " # no ID found\n", + " warnings.append({'No ID match found.'})\n", + "\n", + " if database:\n", + " output['DB_name'] = database\n", + "\n", + " # Add warning(s) as a single dict if exactly one, else as list\n", + " if warnings:\n", + " if len(warnings) == 1:\n", + " output['WARNING'] = warnings[0]\n", + " else:\n", + " output['WARNING'] = warnings\n", + "\n", + " return output\n", + "\n", + " except Exception as e:\n", + " return {'error': str(e)}\n", + "\n", + " def show_output(self, output, indent=0):\n", + " \"\"\"Print the dictionary.\"\"\"\n", + " for key, value in output.items():\n", + " print('\\t' * indent + str(key))\n", + " if isinstance(value, dict):\n", + " self.show_output(value, indent + 1)\n", + " else:\n", + " print('\\t' * (indent + 1) + str(value))" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "e022fe2b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'fasta_seqkit_stat_info': {'format': 'FASTA',\n", + " 'type': 'Protein',\n", + " 'num_seqs': 2,\n", + " 'sum_len': 456,\n", + " 'min_len': 29,\n", + " 'avg_len': 228.0,\n", + " 'max_len': 427,\n", + " 'Q1': 29,\n", + " 'Q2': 427,\n", + " 'Q3': 427,\n", + " 'sum_gap': 0,\n", + " 'N50': 427,\n", + " 'N50_num': 1,\n", + " 'Q20(%)': 0,\n", + " 'Q30(%)': 0,\n", + " 'AvgQual': 0,\n", + " 'GC(%)': 8.33,\n", + " 'sum_n': 14},\n", + " 'fasta_type': 'Protein',\n", + " 'fasta_num_seqs': 2}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "parser = MyFastaParser('test_file.fasta')\n", + "stats = parser.seqkit_stats()\n", + "stats" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "f6d54531", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "file_info_P11473\n", + "\tdescription\n", + "\t\tsp|P11473|VDR_HUMAN Vitamin D3 receptor OS=Homo sapiens OX=9606 GN=VDR PE=1 SV=1\n", + "\tsequence\n", + "\t\tMEAMAASTSLPDPGDFDRNVPRICGVCGDRATGFHFNAMTCEGCKGFFRRSMKRKALFTCPFNGDCRITKDNRRHCQACRLKRCVDIGMMKEFILTDEEVQRKREMILKRKEEEALKDSLRPKLSEEQQRIIAILLDAHHKTYDPTYSDFCQFRPPVRVNDGGGSHPSRPNSRHTPSFSGDSSSSCSDHCITSSDMMDSSSFSNLDLSEEDSDDPSVTLELSQLSMLPHLADLVSYSIQKVIGFAKMIPGFRDLTSEDQIVLLKSSAIEVIMLRSNESFTMDDMSWTCGNQDYKYRVSDVTKAGHSLELIEPLIKFQVGLKKLNLHEEEHVLLMAICIVSPDRPGVQDAALIEAIQDRLSNTLQTYIRCRHPPPGSHLLYAKMIQKLADLRSLNEEHSKQYRCLSFQPECSMKLTPLVLEVFGNEIS\n", + "database_info_P11473\n", + "\torganism\n", + "\t\tHomo sapiens\n", + "\tgeneInfo\n", + "\t\t[{'geneName': {'evidences': [{'evidenceCode': 'ECO:0000312', 'source': 'HGNC', 'id': 'HGNC:12679'}], 'value': 'VDR'}, 'synonyms': [{'value': 'NR1I1'}]}]\n", + "\tsequenceInfo\n", + "\t\tvalue\n", + "\t\t\tMEAMAASTSLPDPGDFDRNVPRICGVCGDRATGFHFNAMTCEGCKGFFRRSMKRKALFTCPFNGDCRITKDNRRHCQACRLKRCVDIGMMKEFILTDEEVQRKREMILKRKEEEALKDSLRPKLSEEQQRIIAILLDAHHKTYDPTYSDFCQFRPPVRVNDGGGSHPSRPNSRHTPSFSGDSSSSCSDHCITSSDMMDSSSFSNLDLSEEDSDDPSVTLELSQLSMLPHLADLVSYSIQKVIGFAKMIPGFRDLTSEDQIVLLKSSAIEVIMLRSNESFTMDDMSWTCGNQDYKYRVSDVTKAGHSLELIEPLIKFQVGLKKLNLHEEEHVLLMAICIVSPDRPGVQDAALIEAIQDRLSNTLQTYIRCRHPPPGSHLLYAKMIQKLADLRSLNEEHSKQYRCLSFQPECSMKLTPLVLEVFGNEIS\n", + "\t\tlength\n", + "\t\t\t427\n", + "\t\tmolWeight\n", + "\t\t\t48289\n", + "\t\tcrc64\n", + "\t\t\tF95F300D042C4CB7\n", + "\t\tmd5\n", + "\t\t\t0D963ACD4A34674368324EE026023597\n", + "\ttype\n", + "\t\tprotein\n", + "DB_name\n", + "\tuniprot\n", + "WARNING\n", + "\t{'No ID match found.'}\n" + ] + } + ], + "source": [ + "biopython = parser.biopython_parser(stats)\n", + "parser.show_output(biopython)" + ] + }, + { + "cell_type": "markdown", + "id": "c91b9148", + "metadata": {}, + "source": [ + "### Testing files ensembl_download_1.fasta, ensembl_download_2.fasta, uniprot_download.fasta" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "dbdd462d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'fasta_seqkit_stat_info': {'format': 'FASTA',\n", + " 'type': 'DNA',\n", + " 'num_seqs': 6,\n", + " 'sum_len': 86,\n", + " 'min_len': 9,\n", + " 'avg_len': 14.33,\n", + " 'max_len': 23,\n", + " 'Q1': 10,\n", + " 'Q2': 16,\n", + " 'Q3': 17,\n", + " 'sum_gap': 0,\n", + " 'N50': 16,\n", + " 'N50_num': 3,\n", + " 'Q20(%)': 0,\n", + " 'Q30(%)': 0,\n", + " 'AvgQual': 0,\n", + " 'GC(%)': 45.35,\n", + " 'sum_n': 0},\n", + " 'fasta_type': 'DNA',\n", + " 'fasta_num_seqs': 6}" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "parser_ed1 = MyFastaParser('ensembl_download_1.fasta')\n", + "stats_ed1 = parser_ed1.seqkit_stats()\n", + "stats_ed1" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "dde79041", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "file_info_ENSMUST00000196221\n", + "\tdescription\n", + "\t\tENSMUST00000196221.2 cds chromosome:GRCm39:14:54350925:54350933:1 gene:ENSMUSG00000096749.3 gene_biotype:TR_D_gene transcript_biotype:TR_D_gene gene_symbol:Trdd1 description:T cell receptor delta diversity 1 [Source:MGI Symbol;Acc:MGI:4439547]\n", + "\tsequence\n", + "\t\tATGGCATAT\n", + "database_info_ENSMUST00000196221\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCm39\n", + "\tspecies\n", + "\t\tmus_musculus\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\tTR_D_gene\n", + "\tdisplay_name\n", + "\t\tTrdd1-202\n", + "\tid\n", + "\t\tENSMUST00000196221\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\thavana\n", + "file_info_ENSMUST00000177564\n", + "\tdescription\n", + "\t\tENSMUST00000177564.2 cds chromosome:GRCm39:14:54359683:54359698:1 gene:ENSMUSG00000096176.2 gene_biotype:TR_D_gene transcript_biotype:TR_D_gene gene_symbol:Trdd2 description:T cell receptor delta diversity 2 [Source:MGI Symbol;Acc:MGI:4439546]\n", + "\tsequence\n", + "\t\tATCGGAGGGATACGAG\n", + "database_info_ENSMUST00000177564\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCm39\n", + "\tspecies\n", + "\t\tmus_musculus\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\tTR_D_gene\n", + "\tdisplay_name\n", + "\t\tTrdd2-201\n", + "\tid\n", + "\t\tENSMUST00000177564\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\tensembl_havana\n", + "file_info_ENST00000605284\n", + "\tdescription\n", + "\t\tENST00000605284.1 cds chromosome:GRCh38:15:20011153:20011169:-1 gene:ENSG00000271336.1 gene_biotype:IG_D_gene transcript_biotype:IG_D_gene gene_symbol:IGHD1OR15-1A description:immunoglobulin heavy diversity 1/OR15-1A (non-functional) [Source:HGNC Symbol;Acc:HGNC:5487]\n", + "\tsequence\n", + "\t\tGGTATAACTGGAACAAC\n", + "database_info_ENST00000605284\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCh38\n", + "\tspecies\n", + "\t\thomo_sapiens\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\tIG_D_gene\n", + "\tdisplay_name\n", + "\t\tIGHD1OR15-1A-201\n", + "\tid\n", + "\t\tENST00000605284\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\thavana\n", + "file_info_ENST00000604642\n", + "\tdescription\n", + "\t\tENST00000604642.1 cds chromosome:GRCh38:15:20003840:20003862:-1 gene:ENSG00000270961.1 gene_biotype:IG_D_gene transcript_biotype:IG_D_gene gene_symbol:IGHD5OR15-5A description:immunoglobulin heavy diversity 5/OR15-5A (non-functional) [Source:HGNC Symbol;Acc:HGNC:5512]\n", + "\tsequence\n", + "\t\tGTGGATATAGTGTCTACGATTAC\n", + "database_info_ENST00000604642\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCh38\n", + "\tspecies\n", + "\t\thomo_sapiens\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\tIG_D_gene\n", + "\tdisplay_name\n", + "\t\tIGHD5OR15-5A-201\n", + "\tid\n", + "\t\tENST00000604642\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\thavana\n", + "file_info_ENSDART00000189400\n", + "\tdescription\n", + "\t\tENSDART0000018940031 cds chromosome:GRCz11:2:36087769:36087779:1 gene:ENSDARG00000116509.1 gene_biotype:TR_D_gene transcript_biotype:TR_D_gene gene_symbol:BX681417.25\n", + "\tsequence\n", + "\t\tGATTGGGGTAC\n", + "database_info_ENSDART00000189400\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCz11\n", + "\tspecies\n", + "\t\tdanio_rerio\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\trRNA\n", + "\tdisplay_name\n", + "\t\t5S_rRNA.1223-201\n", + "\tid\n", + "\t\tENSDART00000189400\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\tensembl\n", + "file_info_ENSDART00000189226\n", + "\tdescription\n", + "\t\tENSDART00000189226.1 cds chromosome:GRCz11:2:36088047:36088056:1 gene:ENSDARG00000116470.1 gene_biotype:TR_D_gene transcript_biotype:TR_D_gene gene_symbol:BX681417.24\n", + "\tsequence\n", + "\t\tTCTGGACTAC\n", + "database_info_ENSDART00000189226\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCz11\n", + "\tspecies\n", + "\t\tdanio_rerio\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\tTR_D_gene\n", + "\tdisplay_name\n", + "\t\tN/A\n", + "\tid\n", + "\t\tENSDART00000189226\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\thavana\n", + "DB_name\n", + "\tensembl\n" + ] + } + ], + "source": [ + "biopython_ed1 = parser_ed1.biopython_parser(stats_ed1)\n", + "parser_ed1.show_output(biopython_ed1)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "5dabf4ed", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'fasta_seqkit_stat_info': {'format': 'FASTA',\n", + " 'type': 'DNA',\n", + " 'num_seqs': 6,\n", + " 'sum_len': 463,\n", + " 'min_len': 11,\n", + " 'avg_len': 77.17,\n", + " 'max_len': 350,\n", + " 'Q1': 12,\n", + " 'Q2': 16,\n", + " 'Q3': 60,\n", + " 'sum_gap': 0,\n", + " 'N50': 350,\n", + " 'N50_num': 1,\n", + " 'Q20(%)': 0,\n", + " 'Q30(%)': 0,\n", + " 'AvgQual': 0,\n", + " 'GC(%)': 43.84,\n", + " 'sum_n': 0},\n", + " 'fasta_type': 'DNA',\n", + " 'fasta_num_seqs': 6}" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "parser_ed2 = MyFastaParser('ensembl_download_2.fasta')\n", + "stats_ed2 = parser_ed2.seqkit_stats()\n", + "stats_ed2" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "03382b1a", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "file_info_ENSDART00000165410\n", + "\tdescription\n", + "\t\tENSDART00000165410.2 cds chromosome:GRCz11:2:31869121:31869554:-1 gene:ENSDARG00000100191.2 gene_biotype:TR_V_gene transcript_biotype:TR_V_gene gene_symbol:trgv6 description:T cell receptor gamma variable 6 [Source:ZFIN;Acc:ZDB-GENE-051115-10]\n", + "\tsequence\n", + "\t\tATGAGTCTTCAAATGCTCTTCTGCTTTTTCTTTCTTTTTAACTTTTATGCAGTTGAAGGACAAGTGACGCTGCGACAGAAAATATCCTCAACCAAATCTCAGGACAAGACTGTTGTCATAGACTGTGATTACCCTTCAGACTGCCGCAGCTACATTCACTGGTACCAACTAAAAGGACAAACCTTAAAGAGAATATTATATGCACAAATTTCAGGAGGAGAACCAGCCAAAGATGCTGGCTTTGAGTTGTTTAAAATAGACCGTAAACAGTCAAATATTGCTCTGAAAATACCTGAACTGAAAACAGAGCATTCAGCAGTCTATTACTGTGCTTGTTGGGTCTCGGGCGG\n", + "database_info_ENSDART00000165410\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCz11\n", + "\tspecies\n", + "\t\tdanio_rerio\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\tTR_V_gene\n", + "\tdisplay_name\n", + "\t\ttrgv6-201\n", + "\tid\n", + "\t\tENSDART00000165410\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\thavana\n", + "file_info_ENSDART00000163675\n", + "\tdescription\n", + "\t\tENSDART00000163675.2 cds chromosome:GRCz11:2:31873021:31873470:-1 gene:ENSDARG00000103544.2 gene_biotype:TR_V_gene transcript_biotype:TR_V_gene gene_symbol:trgv5 description:T cell receptor gamma variable 5 [Source:ZFIN;Acc:ZDB-GENE-051115-11]\n", + "\tsequence\n", + "\t\tATGTTCATAAACTTGTGCAGTGTTTTACTCTTTATAATCCATGGGGTGGAAGGTTTGAGT\n", + "database_info_ENSDART00000163675\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCz11\n", + "\tspecies\n", + "\t\tdanio_rerio\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\tTR_V_gene\n", + "\tdisplay_name\n", + "\t\ttrgv5-201\n", + "\tid\n", + "\t\tENSDART00000163675\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\thavana\n", + "file_info_ENST00000632684\n", + "\tdescription\n", + "\t\tENST00000632684.1 cds chromosome:GRCh38:7:142786213:142786224:1 gene:ENSG00000282431.1 gene_biotype:TR_D_gene transcript_biotype:TR_D_gene gene_symbol:TRBD1 description:T cell receptor beta diversity 1 [Source:HGNC Symbol;Acc:HGNC:12158]\n", + "\tsequence\n", + "\t\tGGGACAGGGGGC\n", + "database_info_ENST00000632684\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCh38\n", + "\tspecies\n", + "\t\thomo_sapiens\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\tTR_D_gene\n", + "\tdisplay_name\n", + "\t\tTRBD1-202\n", + "\tid\n", + "\t\tENST00000632684\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\thavana\n", + "file_info_ENST00000710614\n", + "\tdescription\n", + "\t\tENST00000710614.1 cds chromosome:GRCh38:7:142795705:142795720:1 gene:ENSG00000292271.1 gene_biotype:TR_D_gene transcript_biotype:TR_D_gene description:T cell receptor beta diversity 2\n", + "\tsequence\n", + "\t\tGGGACTAGCGGGAGGG\n", + "database_info_ENST00000710614\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCh38\n", + "\tspecies\n", + "\t\thomo_sapiens\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\tTR_D_gene\n", + "\tdisplay_name\n", + "\t\tN/A\n", + "\tid\n", + "\t\tENST00000710614\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\thavana\n", + "file_info_ENSMUST00000178862\n", + "\tdescription\n", + "\t\tENSMUST00000178862.2 cds chromosome:GRCm39:6:41519097:41519110:1 gene:ENSMUSG00000094569.2 gene_biotype:TR_D_gene transcript_biotype:TR_D_gene gene_symbol:Trbd2 description:T cell receptor beta, D region 2 [Source:MGI Symbol;Acc:MGI:4439727]\n", + "\tsequence\n", + "\t\tGGGACTGGGGGGGC\n", + "database_info_ENSMUST00000178862\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCm39\n", + "\tspecies\n", + "\t\tmus_musculus\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\tTR_D_gene\n", + "\tdisplay_name\n", + "\t\tTrbd2-201\n", + "\tid\n", + "\t\tENSMUST00000178862\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\tensembl_havana\n", + "file_info_ENSMUST00000179520\n", + "\tdescription\n", + "\t\tENSMUST00000179520.2 cds chromosome:GRCm39:12:113394148:113394158:-1 gene:ENSMUSG00000094028.2 gene_biotype:IG_D_gene transcript_biotype:IG_D_gene gene_symbol:Ighd4-1 description:immunoglobulin heavy diversity 4-1 [Source:MGI Symbol;Acc:MGI:4439801]\n", + "\tsequence\n", + "\t\tCTAACTGGGAC\n", + "database_info_ENSMUST00000179520\n", + "\tobject_type\n", + "\t\tTranscript\n", + "\tassembly_name\n", + "\t\tGRCm39\n", + "\tspecies\n", + "\t\tmus_musculus\n", + "\tdb_type\n", + "\t\tcore\n", + "\tbiotype\n", + "\t\tIG_D_gene\n", + "\tdisplay_name\n", + "\t\tIghd4-1-201\n", + "\tid\n", + "\t\tENSMUST00000179520\n", + "\tdescription\n", + "\t\tN/A\n", + "\tcanonical_transcript\n", + "\t\tN/A\n", + "\tsource\n", + "\t\tensembl_havana\n", + "DB_name\n", + "\tensembl\n" + ] + } + ], + "source": [ + "biopython_ed2 = parser_ed2.biopython_parser(stats_ed2)\n", + "parser_ed2.show_output(biopython_ed2)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "1b04e8b6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'fasta_seqkit_stat_info': {'format': 'FASTA',\n", + " 'type': 'Protein',\n", + " 'num_seqs': 7,\n", + " 'sum_len': 3861,\n", + " 'min_len': 180,\n", + " 'avg_len': 551.57,\n", + " 'max_len': 1382,\n", + " 'Q1': 427,\n", + " 'Q2': 441,\n", + " 'Q3': 532,\n", + " 'sum_gap': 0,\n", + " 'N50': 468,\n", + " 'N50_num': 3,\n", + " 'Q20(%)': 0,\n", + " 'Q30(%)': 0,\n", + " 'AvgQual': 0,\n", + " 'GC(%)': 9.14,\n", + " 'sum_n': 165},\n", + " 'fasta_type': 'Protein',\n", + " 'fasta_num_seqs': 7}" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "parser_ud = MyFastaParser('uniprot_download.fasta')\n", + "stats_ud = parser_ud.seqkit_stats()\n", + "stats_ud" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "37ef1a9b", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "file_info_Q9R1A7\n", + "\tdescription\n", + "\t\tsp|Q9R1A7|NR1I2_RAT Nuclear receptor subfamily 1 group I member 2 OS=Rattus norvegicus OX=10116 GN=Nr1i2 PE=2 SV=1\n", + "\tsequence\n", + "\t\tMRPEERWNHVGLVQREEADSVLEEPINVDEEDGGLQICRVCGDKANGYHFNVMTCEGCKGFFRRAMKRNVRLRCPFRKGTCEITRKTRRQCQACRLRKCLESGMKKEMIMSDAAVEQRRALIKRKKREKIEAPPPGGQGLTEEQQALIQELMDAQMQTFDTTFSHFKDFRLPAVFHSDCELPEVLQASLLEDPATWSQIMKDSVPMKISVQLRGEDGSIWNYQPPSKSDGKEIIPLLPHLADVSTYMFKGVINFAKVISHFRELPIEDQISLLKGATFEMCILRFNTMFDTETGTWECGRLAYCFEDPNGGFQKLLLDPLMKFHCMLKKLQLREEEYVLMQAISLFSPDRPGVVQRSVVDQLQERFALTLKAYIECSRPYPAHRFLFLKIMAVLTELRSINAQQTQQLLRIQDTHPFATPLMQELFSSTDG\n", + "database_info_Q9R1A7\n", + "\torganism\n", + "\t\tRattus norvegicus\n", + "\tgeneInfo\n", + "\t\t[{'geneName': {'value': 'Nr1i2'}, 'synonyms': [{'value': 'Pxr'}]}]\n", + "\tsequenceInfo\n", + "\t\tvalue\n", + "\t\t\tMRPEERWNHVGLVQREEADSVLEEPINVDEEDGGLQICRVCGDKANGYHFNVMTCEGCKGFFRRAMKRNVRLRCPFRKGTCEITRKTRRQCQACRLRKCLESGMKKEMIMSDAAVEQRRALIKRKKREKIEAPPPGGQGLTEEQQALIQELMDAQMQTFDTTFSHFKDFRLPAVFHSDCELPEVLQASLLEDPATWSQIMKDSVPMKISVQLRGEDGSIWNYQPPSKSDGKEIIPLLPHLADVSTYMFKGVINFAKVISHFRELPIEDQISLLKGATFEMCILRFNTMFDTETGTWECGRLAYCFEDPNGGFQKLLLDPLMKFHCMLKKLQLREEEYVLMQAISLFSPDRPGVVQRSVVDQLQERFALTLKAYIECSRPYPAHRFLFLKIMAVLTELRSINAQQTQQLLRIQDTHPFATPLMQELFSSTDG\n", + "\t\tlength\n", + "\t\t\t431\n", + "\t\tmolWeight\n", + "\t\t\t49660\n", + "\t\tcrc64\n", + "\t\t\t4B545F21F9439697\n", + "\t\tmd5\n", + "\t\t\tE7D1198F8590B2D5A184DEAA15155E4D\n", + "\ttype\n", + "\t\tprotein\n", + "file_info_P23204\n", + "\tdescription\n", + "\t\tsp|P23204|PPARA_MOUSE Peroxisome proliferator-activated receptor alpha OS=Mus musculus OX=10090 GN=Ppara PE=1 SV=2\n", + "\tsequence\n", + "\t\tMVDTESPICPLSPLEADDLESPLSEEFLQEMGNIQEISQSIGEESSGSFGFADYQYLGSCPGSEGSVITDTLSPASSPSSVSCPVIPASTDESPGSALNIECRICGDKASGYHYGVHACEGCKGFFRRTIRLKLVYDKCDRSCKIQKKNRNKCQYCRFHKCLSVGMSHNAIRFGRMPRSEKAKLKAEILTCEHDLKDSETADLKSLGKRIHEAYLKNFNMNKVKARVILAGKTSNNPPFVIHDMETLCMAEKTLVAKMVANGVEDKEAEVRFFHCCQCMSVETVTELTEFAKAIPGFANLDLNDQVTLLKYGVYEAIFTMLSSLMNKDGMLIAYGNGFITREFLKNLRKPFCDIMEPKFDFAMKFNALELDDSDISLFVAAIICCGDRPGLLNIGYIEKLQEGIVHVLKLHLQSNHPDDTFLFPKLLQKMVDLRQLVTEHAQLVQVIKKTESDAALHPLLQEIYRDMY\n", + "database_info_P23204\n", + "\torganism\n", + "\t\tMus musculus\n", + "\tgeneInfo\n", + "\t\t[{'geneName': {'value': 'Ppara'}, 'synonyms': [{'value': 'Nr1c1'}, {'value': 'Ppar'}]}]\n", + "\tsequenceInfo\n", + "\t\tvalue\n", + "\t\t\tMVDTESPICPLSPLEADDLESPLSEEFLQEMGNIQEISQSIGEESSGSFGFADYQYLGSCPGSEGSVITDTLSPASSPSSVSCPVIPASTDESPGSALNIECRICGDKASGYHYGVHACEGCKGFFRRTIRLKLVYDKCDRSCKIQKKNRNKCQYCRFHKCLSVGMSHNAIRFGRMPRSEKAKLKAEILTCEHDLKDSETADLKSLGKRIHEAYLKNFNMNKVKARVILAGKTSNNPPFVIHDMETLCMAEKTLVAKMVANGVEDKEAEVRFFHCCQCMSVETVTELTEFAKAIPGFANLDLNDQVTLLKYGVYEAIFTMLSSLMNKDGMLIAYGNGFITREFLKNLRKPFCDIMEPKFDFAMKFNALELDDSDISLFVAAIICCGDRPGLLNIGYIEKLQEGIVHVLKLHLQSNHPDDTFLFPKLLQKMVDLRQLVTEHAQLVQVIKKTESDAALHPLLQEIYRDMY\n", + "\t\tlength\n", + "\t\t\t468\n", + "\t\tmolWeight\n", + "\t\t\t52347\n", + "\t\tcrc64\n", + "\t\t\t2930A5191C610B6B\n", + "\t\tmd5\n", + "\t\t\tD8C927E524E62FF35965CD559C6D6529\n", + "\ttype\n", + "\t\tprotein\n", + "file_info_P01275\n", + "\tdescription\n", + "\t\tsp|P01275|GLUC_HUMAN Pro-glucagon OS=Homo sapiens OX=9606 GN=GCG PE=1 SV=3\n", + "\tsequence\n", + "\t\tMKSIYFVAGLFVMLVQGSWQRSLQDTEEKSRSFSASQADPLSDPDQMNEDKRHSQGTFTSDYSKYLDSRRAQDFVQWLMNTKRNRNNIAKRHDEFERHAEGTFTSDVSSYLEGQAAKEFIAWLVKGRGRRDFPEEVAIVEELGRRHADGSFSDEMNTILDNLAARDFINWLIQTKITDRK\n", + "database_info_P01275\n", + "\torganism\n", + "\t\tHomo sapiens\n", + "\tgeneInfo\n", + "\t\t[{'geneName': {'evidences': [{'evidenceCode': 'ECO:0000312', 'source': 'HGNC', 'id': 'HGNC:4191'}], 'value': 'GCG'}}]\n", + "\tsequenceInfo\n", + "\t\tvalue\n", + "\t\t\tMKSIYFVAGLFVMLVQGSWQRSLQDTEEKSRSFSASQADPLSDPDQMNEDKRHSQGTFTSDYSKYLDSRRAQDFVQWLMNTKRNRNNIAKRHDEFERHAEGTFTSDVSSYLEGQAAKEFIAWLVKGRGRRDFPEEVAIVEELGRRHADGSFSDEMNTILDNLAARDFINWLIQTKITDRK\n", + "\t\tlength\n", + "\t\t\t180\n", + "\t\tmolWeight\n", + "\t\t\t20909\n", + "\t\tcrc64\n", + "\t\t\t7A99EEC629B2862C\n", + "\t\tmd5\n", + "\t\t\t9A908D05335E61234613A736E703A54B\n", + "\ttype\n", + "\t\tprotein\n", + "file_info_P06213\n", + "\tdescription\n", + "\t\tsp|P06213|INSR_HUMAN Insulin receptor OS=Homo sapiens OX=9606 GN=INSR PE=1 SV=4\n", + "\tsequence\n", + "\t\tMATGGRRGAAAAPLLVAVAALLLGAAGHLYPGEVCPGMDIRNNLTRLHELENCSVIEGHLQILLMFKTRPEDFRDLSFPKLIMITDYLLLFRVYGLESLKDLFPNLTVIRGSRLFFNYALVIFEMVHLKELGLYNLMNITRGSVRIEKNNELCYLATIDWSRILDSVEDNYIVLNKDDNEECGDICPGTAKGKTNCPATVINGQFVERCWTHSHCQKVCPTICKSHGCTAEGLCCHSECLGNCSQPDDPTKCVACRNFYLDGRCVETCPPPYYHFQDWRCVNFSFCQDLHHKCKNSRRQGCHQYVIHNNKCIPECPSGYTMNSSNLLCTPCLGPCPKVCHLLEGEKTIDSVTSAQELRGCTVINGSLIINIRGGNNLAAELEANLGLIEEISGYLKIRRSYALVSLSFFRKLRLIRGETLEIGNYSFYALDNQNLRQLWDWSKHNLTITQGKLFFHYNPKLCLSEIHKMEEVSGTKGRQERNDIALKTNGDQASCENELLKFSYIRTSFDKILLRWEPYWPPDFRDLLGFMLFYKEAPYQNVTEFDGQDACGSNSWTVVDIDPPLRSNDPKSQNHPGWLMRGLKPWTQYAIFVKTLVTFSDERRTYGAKSDIIYVQTDATNPSVPLDPISVSNSSSQIILKWKPPSDPNGNITHYLVFWERQAEDSELFELDYCLKGLKLPSRTWSPPFESEDSQKHNQSEYEDSAGECCSCPKTDSQILKELEESSFRKTFEDYLHNVVFVPRKTSSGTGAEDPRPSRKRRSLGDVGNVTVAVPTVAAFPNTSSTSVPTSPEEHRPFEKVVNKESLVISGLRHFTGYRIELQACNQDTPEERCSVAAYVSARTMPEAKADDIVGPVTHEIFENNVVHLMWQEPKEPNGLIVLYEVSYRRYGDEELHLCVSRKHFALERGCRLRGLSPGNYSVRIRATSLAGNGSWTEPTYFYVTDYLDVPSNIAKIIIGPLIFVFLFSVVIGSIYLFLRKRQPDGPLGPLYASSNPEYLSASDVFPCSVYVPDEWEVSREKITLLRELGQGSFGMVYEGNARDIIKGEAETRVAVKTVNESASLRERIEFLNEASVMKGFTCHHVVRLLGVVSKGQPTLVVMELMAHGDLKSYLRSLRPEAENNPGRPPPTLQEMIQMAAEIADGMAYLNAKKFVHRDLAARNCMVAHDFTVKIGDFGMTRDIYETDYYRKGGKGLLPVRWMAPESLKDGVFTTSSDMWSFGVVLWEITSLAEQPYQGLSNEQVLKFVMDGGYLDQPDNCPERVTDLMRMCWQFNPKMRPTFLEIVNLLKDDLHPSFPEVSFFHSEENKAPESEELEMEFEDMENVPLDRSSHCQREEAGGRDGGSSLGFKRSYEEHIPYTHMNGGKKNGRILTLPRSNPS\n", + "database_info_P06213\n", + "\torganism\n", + "\t\tHomo sapiens\n", + "\tgeneInfo\n", + "\t\t[{'geneName': {'value': 'INSR'}}]\n", + "\tsequenceInfo\n", + "\t\tvalue\n", + "\t\t\tMATGGRRGAAAAPLLVAVAALLLGAAGHLYPGEVCPGMDIRNNLTRLHELENCSVIEGHLQILLMFKTRPEDFRDLSFPKLIMITDYLLLFRVYGLESLKDLFPNLTVIRGSRLFFNYALVIFEMVHLKELGLYNLMNITRGSVRIEKNNELCYLATIDWSRILDSVEDNYIVLNKDDNEECGDICPGTAKGKTNCPATVINGQFVERCWTHSHCQKVCPTICKSHGCTAEGLCCHSECLGNCSQPDDPTKCVACRNFYLDGRCVETCPPPYYHFQDWRCVNFSFCQDLHHKCKNSRRQGCHQYVIHNNKCIPECPSGYTMNSSNLLCTPCLGPCPKVCHLLEGEKTIDSVTSAQELRGCTVINGSLIINIRGGNNLAAELEANLGLIEEISGYLKIRRSYALVSLSFFRKLRLIRGETLEIGNYSFYALDNQNLRQLWDWSKHNLTITQGKLFFHYNPKLCLSEIHKMEEVSGTKGRQERNDIALKTNGDQASCENELLKFSYIRTSFDKILLRWEPYWPPDFRDLLGFMLFYKEAPYQNVTEFDGQDACGSNSWTVVDIDPPLRSNDPKSQNHPGWLMRGLKPWTQYAIFVKTLVTFSDERRTYGAKSDIIYVQTDATNPSVPLDPISVSNSSSQIILKWKPPSDPNGNITHYLVFWERQAEDSELFELDYCLKGLKLPSRTWSPPFESEDSQKHNQSEYEDSAGECCSCPKTDSQILKELEESSFRKTFEDYLHNVVFVPRKTSSGTGAEDPRPSRKRRSLGDVGNVTVAVPTVAAFPNTSSTSVPTSPEEHRPFEKVVNKESLVISGLRHFTGYRIELQACNQDTPEERCSVAAYVSARTMPEAKADDIVGPVTHEIFENNVVHLMWQEPKEPNGLIVLYEVSYRRYGDEELHLCVSRKHFALERGCRLRGLSPGNYSVRIRATSLAGNGSWTEPTYFYVTDYLDVPSNIAKIIIGPLIFVFLFSVVIGSIYLFLRKRQPDGPLGPLYASSNPEYLSASDVFPCSVYVPDEWEVSREKITLLRELGQGSFGMVYEGNARDIIKGEAETRVAVKTVNESASLRERIEFLNEASVMKGFTCHHVVRLLGVVSKGQPTLVVMELMAHGDLKSYLRSLRPEAENNPGRPPPTLQEMIQMAAEIADGMAYLNAKKFVHRDLAARNCMVAHDFTVKIGDFGMTRDIYETDYYRKGGKGLLPVRWMAPESLKDGVFTTSSDMWSFGVVLWEITSLAEQPYQGLSNEQVLKFVMDGGYLDQPDNCPERVTDLMRMCWQFNPKMRPTFLEIVNLLKDDLHPSFPEVSFFHSEENKAPESEELEMEFEDMENVPLDRSSHCQREEAGGRDGGSSLGFKRSYEEHIPYTHMNGGKKNGRILTLPRSNPS\n", + "\t\tlength\n", + "\t\t\t1382\n", + "\t\tmolWeight\n", + "\t\t\t156333\n", + "\t\tcrc64\n", + "\t\t\t709A955660739066\n", + "\t\tmd5\n", + "\t\t\t8EB04104BE33F0A0CB376ED145E684FF\n", + "\ttype\n", + "\t\tprotein\n", + "file_info_P11473\n", + "\tdescription\n", + "\t\tsp|P11473|VDR_HUMAN Vitamin D3 receptor OS=Homo sapiens OX=9606 GN=VDR PE=1 SV=1\n", + "\tsequence\n", + "\t\tMEAMAASTSLPDPGDFDRNVPRICGVCGDRATGFHFNAMTCEGCKGFFRRSMKRKALFTCPFNGDCRITKDNRRHCQACRLKRCVDIGMMKEFILTDEEVQRKREMILKRKEEEALKDSLRPKLSEEQQRIIAILLDAHHKTYDPTYSDFCQFRPPVRVNDGGGSHPSRPNSRHTPSFSGDSSSSCSDHCITSSDMMDSSSFSNLDLSEEDSDDPSVTLELSQLSMLPHLADLVSYSIQKVIGFAKMIPGFRDLTSEDQIVLLKSSAIEVIMLRSNESFTMDDMSWTCGNQDYKYRVSDVTKAGHSLELIEPLIKFQVGLKKLNLHEEEHVLLMAICIVSPDRPGVQDAALIEAIQDRLSNTLQTYIRCRHPPPGSHLLYAKMIQKLADLRSLNEEHSKQYRCLSFQPECSMKLTPLVLEVFGNEIS\n", + "database_info_P11473\n", + "\torganism\n", + "\t\tHomo sapiens\n", + "\tgeneInfo\n", + "\t\t[{'geneName': {'evidences': [{'evidenceCode': 'ECO:0000312', 'source': 'HGNC', 'id': 'HGNC:12679'}], 'value': 'VDR'}, 'synonyms': [{'value': 'NR1I1'}]}]\n", + "\tsequenceInfo\n", + "\t\tvalue\n", + "\t\t\tMEAMAASTSLPDPGDFDRNVPRICGVCGDRATGFHFNAMTCEGCKGFFRRSMKRKALFTCPFNGDCRITKDNRRHCQACRLKRCVDIGMMKEFILTDEEVQRKREMILKRKEEEALKDSLRPKLSEEQQRIIAILLDAHHKTYDPTYSDFCQFRPPVRVNDGGGSHPSRPNSRHTPSFSGDSSSSCSDHCITSSDMMDSSSFSNLDLSEEDSDDPSVTLELSQLSMLPHLADLVSYSIQKVIGFAKMIPGFRDLTSEDQIVLLKSSAIEVIMLRSNESFTMDDMSWTCGNQDYKYRVSDVTKAGHSLELIEPLIKFQVGLKKLNLHEEEHVLLMAICIVSPDRPGVQDAALIEAIQDRLSNTLQTYIRCRHPPPGSHLLYAKMIQKLADLRSLNEEHSKQYRCLSFQPECSMKLTPLVLEVFGNEIS\n", + "\t\tlength\n", + "\t\t\t427\n", + "\t\tmolWeight\n", + "\t\t\t48289\n", + "\t\tcrc64\n", + "\t\t\tF95F300D042C4CB7\n", + "\t\tmd5\n", + "\t\t\t0D963ACD4A34674368324EE026023597\n", + "\ttype\n", + "\t\tprotein\n", + "file_info_Q90416\n", + "\tdescription\n", + "\t\tsp|Q90416|RXRGA_DANRE Retinoic acid receptor RXR-gamma-A OS=Danio rerio OX=7955 GN=rxrga PE=2 SV=2\n", + "\tsequence\n", + "\t\tMDNNDTYLHLSSSLQVAHGHLSSPPSQPPLSSMVSHHHPSIINGLGSPYSVITSSSLGSPSASMPTTSNMGYGALNSPQMNSLNSVSSSEDIKPPPGLAGLGSYPCGSPGSLSKHICAICGDRSSGKHYGVYSCEGCKGFFKRTIRKDLTYTCRDNKDCQIDKRQRNRCQYCRYQKCLAMGMKREAVQEERQRGRERSDNEVDSSSSFNEEMPVEKILDAELAVEPKTEAYMESSMSNSTNDPVTNICQAADKQLFTLVEWAKRIPHFSDLPLDDQVILLRAGWNELLIASFSHRSVTVKDGILLATGLHVHRSSAHSAGVGSIFDRVLTELVSKMRDMQMDKTELGCLRAIVLFNPDAKGLSNPSEVEALREKVYASLEGYTKHNYPDQPGRFAKLLLRLPALRSIGLKCLEHLFFFKLIGDTPIDTFLMEMLEAPHQIT\n", + "database_info_Q90416\n", + "\torganism\n", + "\t\tDanio rerio\n", + "\tgeneInfo\n", + "\t\t[{'geneName': {'value': 'rxrga'}, 'synonyms': [{'value': 'nr2b1'}, {'value': 'nr2b3a'}, {'value': 'rxr'}, {'value': 'rxra'}, {'value': 'rxrg'}]}]\n", + "\tsequenceInfo\n", + "\t\tvalue\n", + "\t\t\tMDNNDTYLHLSSSLQVAHGHLSSPPSQPPLSSMVSHHHPSIINGLGSPYSVITSSSLGSPSASMPTTSNMGYGALNSPQMNSLNSVSSSEDIKPPPGLAGLGSYPCGSPGSLSKHICAICGDRSSGKHYGVYSCEGCKGFFKRTIRKDLTYTCRDNKDCQIDKRQRNRCQYCRYQKCLAMGMKREAVQEERQRGRERSDNEVDSSSSFNEEMPVEKILDAELAVEPKTEAYMESSMSNSTNDPVTNICQAADKQLFTLVEWAKRIPHFSDLPLDDQVILLRAGWNELLIASFSHRSVTVKDGILLATGLHVHRSSAHSAGVGSIFDRVLTELVSKMRDMQMDKTELGCLRAIVLFNPDAKGLSNPSEVEALREKVYASLEGYTKHNYPDQPGRFAKLLLRLPALRSIGLKCLEHLFFFKLIGDTPIDTFLMEMLEAPHQIT\n", + "\t\tlength\n", + "\t\t\t441\n", + "\t\tmolWeight\n", + "\t\t\t48720\n", + "\t\tcrc64\n", + "\t\t\tF169ADE221F2F13C\n", + "\t\tmd5\n", + "\t\t\tCB5B4F3222CAF577FE8A80CB934529A3\n", + "\ttype\n", + "\t\tprotein\n", + "file_info_A9C3R8\n", + "\tdescription\n", + "\t\tsp|A9C3R8|RP65C_DANRE Retinal Mueller cells isomerohydrolase OS=Danio rerio OX=7955 GN=rpe65c PE=1 SV=1\n", + "\tsequence\n", + "\t\tMVSRLEHPAGGYKKVFESCEELAEPIPAHVSGEIPAWLSGSLLRMGPGLFEVGDEPFYHLFDGQALLHKFDLKDGRVTYHRRFIRTDAYVRAMTEKRVVITEFGTTAYPDPCKNIFSRFFTYFQGIEVTDNCLVNIYPIGEDFYACTETNFITKVDPDTLETVKKVDLCNYLSVNGLTAHPHIEADGTVYNIGNCFGKNMSLAYNIVKIPPLQEDKSDQFEKSKILVQFPSSERFKPSYVHSFGITENHFVFVETPVKINLLKFLTSWSIRGSNYMDCFESNDKMGTWFHLAAKNPGKYIDHKFRTSAFNIFHHINCFEDQGFIVVDLCTWKGHEFVYNYLYLANLRQNWEEVKKAALRAPQPEVRRYVLPLDIHREEQGKNLVSLPYTTATAVMRSDGTVWLEPEVLFSGPRQAFEFPQINYSKFNGKDYTFAYGLGLNHFVPDRICKLNVKSKETWIWQEPDAYPSEPLFVQSPDAEDEDDGVLLSIVVKPGVSQRPAFLLILKATDLTEIARAEVDVLIPVTLHGIYKP\n", + "database_info_A9C3R8\n", + "\torganism\n", + "\t\tDanio rerio\n", + "\tgeneInfo\n", + "\t\t[{'geneName': {'value': 'rpe65c'}, 'orfNames': [{'value': 'si:ch211-198n5.12'}]}]\n", + "\tsequenceInfo\n", + "\t\tvalue\n", + "\t\t\tMVSRLEHPAGGYKKVFESCEELAEPIPAHVSGEIPAWLSGSLLRMGPGLFEVGDEPFYHLFDGQALLHKFDLKDGRVTYHRRFIRTDAYVRAMTEKRVVITEFGTTAYPDPCKNIFSRFFTYFQGIEVTDNCLVNIYPIGEDFYACTETNFITKVDPDTLETVKKVDLCNYLSVNGLTAHPHIEADGTVYNIGNCFGKNMSLAYNIVKIPPLQEDKSDQFEKSKILVQFPSSERFKPSYVHSFGITENHFVFVETPVKINLLKFLTSWSIRGSNYMDCFESNDKMGTWFHLAAKNPGKYIDHKFRTSAFNIFHHINCFEDQGFIVVDLCTWKGHEFVYNYLYLANLRQNWEEVKKAALRAPQPEVRRYVLPLDIHREEQGKNLVSLPYTTATAVMRSDGTVWLEPEVLFSGPRQAFEFPQINYSKFNGKDYTFAYGLGLNHFVPDRICKLNVKSKETWIWQEPDAYPSEPLFVQSPDAEDEDDGVLLSIVVKPGVSQRPAFLLILKATDLTEIARAEVDVLIPVTLHGIYKP\n", + "\t\tlength\n", + "\t\t\t532\n", + "\t\tmolWeight\n", + "\t\t\t60879\n", + "\t\tcrc64\n", + "\t\t\tC890C678BAB2B92B\n", + "\t\tmd5\n", + "\t\t\t56978F57F018FC2562A8AC77C0C0CFDE\n", + "\ttype\n", + "\t\tprotein\n", + "DB_name\n", + "\tuniprot\n" + ] + } + ], + "source": [ + "biopython_ud = parser_ud.biopython_parser(stats_ud)\n", + "parser_ud.show_output(biopython_ud)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}