{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "034d02b4-d912-43d1-acd6-9cb635370674",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Enter your name:  Eshani\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Hello Eshani\n",
      "\n",
      "\u001b[95m\u001b[95m\n",
      "\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Enter input file name here, e.g., input.csv: listk.csv\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loaded 1998 peptides from listk.csv\n",
      "\u001b[95m\u001b[95m\n",
      "\n",
      "Preview: First 10 peptides\n",
      "SLHTLFGDELCK\n",
      "SLHTLFGDELCK\n",
      "SLHTLFGDELCK\n",
      "SLHTLFGDELCK\n",
      "RPCFSALTPDETYVPKAFDEKLFTFHADICTLPDTEK\n",
      "FWGKYLYEIARR\n",
      "FWGKYLYEIARR\n",
      "FWGKYLYEIARR\n",
      "FWGKYLYEIARR\n",
      "FWGKYLYEIARR\n",
      "\u001b[95m\u001b[95m\n",
      "\n",
      "Duplicates removed. Result saved in 'output.csv'.\n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 312928 characters]",
      "text/plain": [
       "<Figure size 800x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[94m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[94m\n",
      "\u001b[94m~Eshani Hettiarachchi,Ph.D.\u001b[94m\n",
      "\u001b[93mAnalysis run by: Eshani\u001b[93m\n",
      "\u001b[95m\u001b[95m\n",
      "2025-11-17\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "This is a supporting program for Proteomics Peptide Analysis to remove duplicate entries in a spreadsheet\n",
    "by Eshani Hettiarachchi, Chemistry & Biochemitry at University of California San Diego. \n",
    "\n",
    "- input.csv will be the input\n",
    "- will generate and output.csv with duplicates removed.\n",
    "\n",
    "\"\"\"\n",
    "import csv\n",
    "import pandas as pd\n",
    "\n",
    "print(\"\")\n",
    "user_name = input(\"Enter your name: \") \n",
    "print(\"\")\n",
    "print(\"Hello\", user_name)\n",
    "print(\"\")\n",
    "print(\"\\033[95m\\033[95m\")\n",
    "print(\"\")\n",
    "input_file = input(\"Enter input file name here, e.g., input.csv:\")\n",
    "\n",
    "#input_file = \"input.csv\"\n",
    "output_file = \"output.csv\"\n",
    "\n",
    "#\n",
    "\n",
    "peptide = pd.read_csv(input_file, header=None)[0].dropna().tolist()\n",
    "\n",
    "print(f\"Loaded {len(peptide)} peptides from {input_file}\")\n",
    "print(\"\\033[95m\\033[95m\")\n",
    "print(\"\\nPreview: First 10 peptides\")\n",
    "for p in peptide[:10]:\n",
    "    print(p)\n",
    "print(\"\\033[95m\\033[95m\")\n",
    "#\n",
    "\n",
    "seen = set()  \n",
    "rows_to_write = []\n",
    "\n",
    "with open(input_file, newline='') as csvfile:\n",
    "    reader = csv.reader(csvfile)\n",
    "    for row in reader:\n",
    "        if row[0] not in seen:\n",
    "            seen.add(row[0])\n",
    "            rows_to_write.append(row)\n",
    "\n",
    "with open(output_file, \"w\", newline='') as csvfile:\n",
    "    writer = csv.writer(csvfile)\n",
    "    writer.writerows(rows_to_write)\n",
    "print(\"\")\n",
    "print(f\"Duplicates removed. Result saved in '{output_file}'.\")\n",
    "print(\"\")\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.image as mpimg\n",
    "import numpy as np\n",
    "\n",
    "img = mpimg.imread('flowchart.jpeg')\n",
    "img_rot = np.rot90(img, k=-1)\n",
    "\n",
    "plt.figure(figsize=(8, 6))\n",
    "plt.imshow(img_rot)\n",
    "plt.axis('off')\n",
    "plt.show()\n",
    "\n",
    "print(\"\\033[94m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\033[94m\")\n",
    "print(\"\\033[94m~Eshani Hettiarachchi,Ph.D.\\033[94m\")\n",
    "\n",
    "from datetime import date\n",
    "today = date.today()\n",
    "print(f\"\\033[93mAnalysis run by: {user_name}\\033[93m\")\n",
    "print(\"\\033[95m\\033[95m\")\n",
    "print(today)\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03ccdc04-1f6a-4475-a224-2d82b832c0db",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6bed7eb4-b69f-4f89-acd8-3864ca58840c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "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.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
