{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(\"../Jiggins_Zenodo_Img_Master.csv\", low_memory=False)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 12586\n", "X 49359\n", "Image_name 37821\n", "View 10\n", "zenodo_name 36\n", "zenodo_link 32\n", "Sequence 11301\n", "Taxonomic_Name 363\n", "Locality 645\n", "Sample_accession 1571\n", "Collected_by 12\n", "Other_ID 3088\n", "Date 810\n", "Dataset 8\n", "Store 142\n", "Brood 226\n", "Death_Date 82\n", "Cross_Type 30\n", "Stage 1\n", "Sex 3\n", "Unit_Type 6\n", "file_type 3\n", "dtype: int64" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.nunique()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "file_type\n", "jpg 37072\n", "raw 12226\n", "tif 61\n", "Name: count, dtype: int64" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.file_type.value_counts()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "View\n", "dorsal 15128\n", "ventral 13424\n", "Dorsal 8360\n", "Ventral 8090\n", "ventral 1644\n", "forewing dorsal 406\n", "hindwing dorsal 406\n", "forewing ventral 406\n", "hindwing ventral 406\n", "Dorsal and Ventral 18\n", "Name: count, dtype: int64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.View.value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Not great that `ventral` gets listed twice as lowercase and _again_ as `Ventral`.\n", "\n", "### Standardize `View` Column\n", "Let's standardize `View` so that there isn't a discrepancy based on case." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "View\n", "dorsal 23488\n", "ventral 21514\n", "ventral 1644\n", "forewing dorsal 406\n", "hindwing dorsal 406\n", "forewing ventral 406\n", "hindwing ventral 406\n", "dorsal and ventral 18\n", "Name: count, dtype: int64" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[\"View\"] = df.View.str.lower()\n", "df.View.value_counts()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['dorsal' 'ventral' nan 'dorsal and ventral' 'ventral ' 'forewing dorsal'\n", " 'hindwing dorsal' 'forewing ventral' 'hindwing ventral']\n" ] } ], "source": [ "print(df.View.unique())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Yes, one has a space after it, so we'll replace that." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "View\n", "dorsal 23488\n", "ventral 23158\n", "forewing dorsal 406\n", "hindwing dorsal 406\n", "forewing ventral 406\n", "hindwing ventral 406\n", "dorsal and ventral 18\n", "Name: count, dtype: int64" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[df[\"View\"] == \"ventral \", \"View\"] = \"ventral\"\n", "df.View.value_counts() " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add Record Number Column\n", "We'll add a `record_number` column for easier matching to the license/citation file." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def get_record_number(url):\n", " num = url.split(sep = \"/\")[-1]\n", " return num" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "32" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[\"record_number\"] = df.zenodo_link.apply(get_record_number)\n", "df.record_number.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have 32 unique records represented in the full dataset. When we reduce down to just the Heliconius images, this will probably be less." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add `species` and `subspecies` Columns\n", "This will make some analysis easier and allow for easy viewing on the [Data Dashboard](https://huggingface.co./spaces/imageomics/dashboard-prototype)." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def get_species(taxa_name):\n", " if type(taxa_name) != float: #taxa name not null\n", " species = taxa_name.split(sep = \" ssp\")[0]\n", " return species\n", " else:\n", " return taxa_name" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "def get_subspecies(taxa_name):\n", " if type(taxa_name) != float:\n", " if \"ssp.\" in taxa_name:\n", " subspecies = taxa_name.split(sep = \"ssp. \")[1]\n", " elif \"ssp \" in taxa_name:\n", " subspecies = taxa_name.split(sep = \"ssp \")[1]\n", " else:\n", " subspecies = None\n", " else:\n", " subspecies = None\n", " return subspecies" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "246" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[\"species\"] = df.Taxonomic_Name.apply(get_species)\n", "df.species.nunique()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "139" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[\"subspecies\"] = df.Taxonomic_Name.apply(get_subspecies)\n", "df.subspecies.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Cross Types are labeled differently:\n", "They are all abbreviations, we have `malleti (mal), plesseni (ple), notabilis (not), lativitta (lat)`, and Neil would guess that `latRo` refers to lativitta with a rounded apical band (e.g., a phenotypic variant of lativitta), but he couldn't say for sure without some more digging, so that will have to stay as-is. We will leave the `Test cross...` ones, but there is not much more to do with them." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['mal', 'mal x ple', 'ple', 'ple x mal', 'latRo x not',\n", " '(latRo x not) x not', '(mal x ple) x mal', '(mal x ple) x ple',\n", " 'ple x (mal x ple)', '(ple x mal) x (mal x ple)', 'lat x not',\n", " '(ple x mal) x ple', '(mal x ple) x (mal x ple)',\n", " '(ple x mal) x mal', '(ple x mal) x (ple x mal)',\n", " '(mal x ple) x (ple x mal)', 'hybrid', 'mal x (ple x mal)',\n", " '(lat x not) x lat', '(lat x not) x not', 'Ac heterozygote',\n", " 'ple x (ple x mal)', '2 banded', 'lat',\n", " 'Test cross (2 banded F2 x 2 banded F2)',\n", " 'Test cross (4 spots x 2 banded)', 'Test cross (N heterozygozity)',\n", " 'Test cross (short HW bar)', 'Test cross (4 spots x 4 spots)',\n", " 'Test cross (N heterozygocity - NBNN x mal - thin)'], dtype=object)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.Cross_Type.dropna().unique()" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "def clean_cross_types(cross_type):\n", " if type(cross_type) != float:\n", " cross_type = cross_type.replace(\"mal\", \"malleti\")\n", " cross_type = cross_type.replace(\"ple\", \"plesseni\")\n", " cross_type = cross_type.replace(\"not\", \"notabilis\")\n", " if \"latRo\" not in cross_type:\n", " #latRo does not cross with lativitta, so only apply when latRo isn't present\n", " cross_type = cross_type.replace(\"lat\", \"lativitta\")\n", " return cross_type" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "df[\"Cross_Type\"] = df[\"Cross_Type\"].apply(clean_cross_types)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can fill these cross types in for the `subspecies` column (all Cross Types are just labeled to the spceies level in `Taxonomic_Name`, so they did not get processed previously)." ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "156" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cross_type_subspecies = [ct for ct in list(df.Cross_Type.dropna().unique()) if \"Test\" not in ct and \"banded\" not in ct]\n", "cross_type_subspecies.remove(\"hybrid\")\n", "cross_type_subspecies.remove(\"Ac heterozygote\")\n", "\n", "for ct in cross_type_subspecies:\n", " df.loc[df[\"Cross_Type\"] == ct, \"subspecies\"] = ct\n", "\n", "df.subspecies.nunique()\n" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "21" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(cross_type_subspecies)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "subspecies\n", "(malleti x plesseni) x malleti 1204\n", "plesseni x (malleti x plesseni) 600\n", "malleti x (plesseni x malleti) 370\n", "(plesseni x malleti) x plesseni 363\n", "(plesseni x malleti) x (malleti x plesseni) 354\n", "(plesseni x malleti) x (plesseni x malleti) 286\n", "(malleti x plesseni) x plesseni 278\n", "plesseni x malleti 234\n", "malleti x plesseni 192\n", "lativitta x notabilis 136\n", "(lativitta x notabilis) x lativitta 110\n", "plesseni x (plesseni x malleti) 106\n", "(lativitta x notabilis) x notabilis 106\n", "(malleti x plesseni) x (malleti x plesseni) 98\n", "(plesseni x malleti) x malleti 80\n", "(malleti x plesseni) x (plesseni x malleti) 56\n", "malleti 28\n", "plesseni 28\n", "(latRo x notabilis) x notabilis 16\n", "latRo x notabilis 4\n", "lativitta 4\n", "Name: count, dtype: int64" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[df[\"Cross_Type\"].notna(), \"subspecies\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4\n" ] }, { "data": { "text/plain": [ "['malleti', 'plesseni', 'plesseni x malleti', 'lativitta']" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "already_present_subspecies = []\n", "\n", "for subspecies in list(df.loc[df[\"Cross_Type\"].notna(), \"subspecies\"].dropna().unique()):\n", " if subspecies in list(df.loc[~df[\"Cross_Type\"].notna(), \"subspecies\"].dropna().unique()):\n", " already_present_subspecies.append(subspecies)\n", "\n", "print(len(already_present_subspecies))\n", "already_present_subspecies" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Perfect, this adds 17 more subspecies (`lativitta`, `plessani`, `maletti`, and `plesseni x malleti` were already represented). Note, this is based on _exact_ duplicates. `notabilis x lativitta` is also already in the dataset, but the order (where the cross types are concerned) general goes `maternal x paternal`." ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | CAMID | \n", "X | \n", "Image_name | \n", "View | \n", "zenodo_name | \n", "zenodo_link | \n", "Sequence | \n", "Taxonomic_Name | \n", "Locality | \n", "Sample_accession | \n", "... | \n", "Brood | \n", "Death_Date | \n", "Cross_Type | \n", "Stage | \n", "Sex | \n", "Unit_Type | \n", "file_type | \n", "record_number | \n", "species | \n", "subspecies | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1986 | \n", "19N1989 | \n", "21369 | \n", "19N1989_v.JPG | \n", "ventral | \n", "0.sheffield.ps.nn.ikiam.batch2.csv | \n", "https://zenodo.org/record/4288311 | \n", "1,989 | \n", "Heliconius melpomene ssp. malleti | \n", "Ikiam Mariposario | \n", "NaN | \n", "... | \n", "IKIAM.P44 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "Male | \n", "reared | \n", "jpg | \n", "4288311 | \n", "Heliconius melpomene | \n", "malleti | \n", "
45062 | \n", "CAM044423 | \n", "34391 | \n", "CAM044423_d.CR2 | \n", "dorsal | \n", "batch2.Peru.image.names.Zenodo.csv | \n", "https://zenodo.org/record/4287444 | \n", "44,423 | \n", "Taygetis cleopatra | \n", "B6old6 | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "raw | \n", "4287444 | \n", "Taygetis cleopatra | \n", "None | \n", "
48534 | \n", "E23 | \n", "37555 | \n", "E23_d.CR2 | \n", "dorsal | \n", "Anniina.Matilla.Field.Caught.E.csv | \n", "https://zenodo.org/record/2554218 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "raw | \n", "2554218 | \n", "NaN | \n", "None | \n", "
45206 | \n", "CAM044445 | \n", "37132 | \n", "CAM044445_d.JPG | \n", "dorsal | \n", "batch3.Peru.image.names.Zenodo.csv | \n", "https://zenodo.org/record/4288250 | \n", "44,445 | \n", "Taygetis cleopatra | \n", "B4old2 | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "jpg | \n", "4288250 | \n", "Taygetis cleopatra | \n", "None | \n", "
12212 | \n", "CAM010238 | \n", "23307 | \n", "10238v.jpg | \n", "ventral | \n", "Heliconius_wing_old_photos_2001_2019_part1.csv | \n", "https://zenodo.org/record/2552371 | \n", "10,238 | \n", "Heliconius sp. | \n", "NaN | \n", "NaN | \n", "... | \n", "B043 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "Female | \n", "reared | \n", "jpg | \n", "2552371 | \n", "Heliconius sp. | \n", "None | \n", "
39059 | \n", "CAM043418 | \n", "30654 | \n", "CAM043418_v.JPG | \n", "ventral | \n", "batch1.Peru.image.names.Zenodo.csv | \n", "https://zenodo.org/record/3569598 | \n", "43,418 | \n", "Archaeoprepona licomedes | \n", "B6rec6 | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "jpg | \n", "3569598 | \n", "Archaeoprepona licomedes | \n", "None | \n", "
38163 | \n", "CAM043170 | \n", "29755 | \n", "CAM043170_d.CR2 | \n", "dorsal | \n", "batch1.Peru.image.names.Zenodo.csv | \n", "https://zenodo.org/record/3569598 | \n", "43,170 | \n", "Adelpha mesentina | \n", "F3rec2 | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "raw | \n", "3569598 | \n", "Adelpha mesentina | \n", "None | \n", "
7 rows × 25 columns
\n", "\n", " | CAMID | \n", "X | \n", "Image_name | \n", "View | \n", "zenodo_name | \n", "zenodo_link | \n", "Sequence | \n", "Taxonomic_Name | \n", "Locality | \n", "Sample_accession | \n", "... | \n", "Death_Date | \n", "Cross_Type | \n", "Stage | \n", "Sex | \n", "Unit_Type | \n", "file_type | \n", "record_number | \n", "species | \n", "subspecies | \n", "genus | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
48538 | \n", "E24 | \n", "37559 | \n", "E24_d.CR2 | \n", "dorsal | \n", "Anniina.Matilla.Field.Caught.E.csv | \n", "https://zenodo.org/record/2554218 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "raw | \n", "2554218 | \n", "NaN | \n", "None | \n", "NaN | \n", "
37246 | \n", "CAM042045 | \n", "43973 | \n", "CAM042045_v.JPG | \n", "ventral | \n", "Collection_August2019.csv | \n", "https://zenodo.org/record/5731587 | \n", "42,045 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "jpg | \n", "5731587 | \n", "NaN | \n", "None | \n", "NaN | \n", "
37484 | \n", "CAM042166 | \n", "44211 | \n", "CAM042166_v.JPG | \n", "ventral | \n", "Collection_August2019.csv | \n", "https://zenodo.org/record/5731587 | \n", "42,166 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "jpg | \n", "5731587 | \n", "NaN | \n", "None | \n", "NaN | \n", "
48780 | \n", "E83 | \n", "37777 | \n", "E83_v.CR2 | \n", "ventral | \n", "Anniina.Matilla.Field.Caught.E.csv | \n", "https://zenodo.org/record/2554218 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "raw | \n", "2554218 | \n", "NaN | \n", "None | \n", "NaN | \n", "
3118 | \n", "19N2627 | \n", "22498 | \n", "19N2627_v.CR2 | \n", "NaN | \n", "0.sheffield.ps.nn.ikiam.batch2.csv | \n", "https://zenodo.org/record/4288311 | \n", "0 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "raw | \n", "4288311 | \n", "NaN | \n", "None | \n", "NaN | \n", "
46111 | \n", "CAM045060 | \n", "42806 | \n", "CAM045060_v.CR2 | \n", "ventral | \n", "image.names.cook.island.erato.csv | \n", "https://zenodo.org/record/5526257 | \n", "45,060 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "raw | \n", "5526257 | \n", "NaN | \n", "None | \n", "NaN | \n", "
39502 | \n", "CAM043576 | \n", "31097 | \n", "CAM043576_v.CR2 | \n", "ventral | \n", "batch2.Peru.image.names.Zenodo.csv | \n", "https://zenodo.org/record/4287444 | \n", "43,576 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "raw | \n", "4287444 | \n", "NaN | \n", "None | \n", "NaN | \n", "
7 rows × 26 columns
\n", "