{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It turns out [record 3082688](https://zenodo.org/records/3082688) is version 2 of [record 1247307](https://zenodo.org/records/1247307), where some mislabeling was fixed. Images from record 1247307 should not be used, so we will remove them here.\n", "\n", "Will also add `hybrid_stat` and `file_url` columns so these can be explored with all functionality of the [data dashboard](https://huggingface.co./spaces/imageomics/dashboard-prototype)." ] }, { "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 7\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", "record_number 32\n", "species 246\n", "subspecies 155\n", "genus 94\n", "dtype: int64" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.nunique()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 49359 entries, 0 to 49358\n", "Series name: record_number\n", "Non-Null Count Dtype\n", "-------------- -----\n", "49359 non-null int64\n", "dtypes: int64(1)\n", "memory usage: 385.7 KB\n" ] } ], "source": [ "df.record_number.info()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 12586\n", "X 46439\n", "Image_name 37821\n", "View 7\n", "zenodo_name 35\n", "zenodo_link 31\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", "record_number 31\n", "species 246\n", "subspecies 155\n", "genus 94\n", "dtype: int64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = df.loc[df.record_number != 1247307]\n", "df.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Checking all records on Zenodo for the [Butterfly Genetics Group](https://zenodo.org/communities/butterfly/records) (the overall source of the Jiggins data), [record 3477891](https://zenodo.org/records/3477891) and [record 2548678](https://zenodo.org/records/2548678) are marked as version 2 of records 3477412 & 1880783, respectively. Let's check that the first versions are not included.\n", "\n", "It is also noted in [record 2548678](https://zenodo.org/records/2548678):\n", ">Some images overlap with 'Cambridge butterfly wing collection batch 1', taken by Eva Whiltshire. Images here differ in having a white reflectance standard for calibration. Information on duplicates can be found in 'CAM.coll.patricio.batch2.csv'.\n", "\n", "Note that this is a reference to [record 1247307](https://zenodo.org/records/1247307), so the overlap is in fact with Cambridge butterfly wing collection batch 1- version 2 ([record 3082688](https://zenodo.org/records/3082688)); it is unclear as yet if the duplication information will be acurate considering the mislabelings fixed between the versions." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0, 26)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v1s = [3477412, 1880783]\n", "df.loc[df[\"record_number\"].isin(v1s)].shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The good news is that neither of these earlier versions seem to have been picked up, so we can move on to assessing this and adding the `hybrid_stat` and `file_url` columns." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "file_type\n", "jpg 34152\n", "raw 12226\n", "tif 61\n", "Name: count, dtype: int64" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.file_type.value_counts()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "View\n", "dorsal 22022\n", "ventral 21704\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.View.value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have 31 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 File URL Column" ] }, { "cell_type": "code", "execution_count": 9, "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", " \n", " \n", " \n", " \n", " \n", " \n", "
CAMIDXImage_nameViewzenodo_namezenodo_linkSequenceTaxonomic_NameLocalitySample_accession...Cross_TypeStageSexUnit_Typefile_typerecord_numberspeciessubspeciesgenusfile_url
34925CAM04145738799CAM041457_d.CR2dorsal0.gmk.broods.all.csvhttps://zenodo.org/record/429109541,457Heliconius timaretaReventador road 2NaN...NaNNaNMaleNaNraw4291095Heliconius timaretaNaNHeliconiushttps://zenodo.org/record/4291095/files/CAM041...
28286CAM03614541369CAM036145_v.JPGventralFilelist.csvhttps://zenodo.org/record/556124636,145Methona singularisGuaribas - RG16NaN...NaNNaNMaleNaNjpg5561246Methona singularisNaNMethonahttps://zenodo.org/record/5561246/files/CAM036...
21858CAM01740919047CAM017409_d.CR2dorsalCAM.coll.PS.list.individuals.haplotagging.new....https://zenodo.org/record/415350217,409Heliconius erato ssp. lativittaSan Pedro de Arajuno, Río ArajunoERS353373...NaNNaNFemalewildraw4153502Heliconius eratolativittaHeliconiushttps://zenodo.org/record/4153502/files/CAM017...
12708CAM01041226792CAM010412_v.CR2ventral2001_2.broods.batch.1.csvhttps://zenodo.org/record/254952410,412Heliconius sp.NaNNaN...NaNNaNUnknownrearedraw2549524Heliconius sp.NaNHeliconiushttps://zenodo.org/record/2549524/files/CAM010...
\n", "

4 rows × 27 columns

\n", "
" ], "text/plain": [ " CAMID X Image_name View \\\n", "34925 CAM041457 38799 CAM041457_d.CR2 dorsal \n", "28286 CAM036145 41369 CAM036145_v.JPG ventral \n", "21858 CAM017409 19047 CAM017409_d.CR2 dorsal \n", "12708 CAM010412 26792 CAM010412_v.CR2 ventral \n", "\n", " zenodo_name \\\n", "34925 0.gmk.broods.all.csv \n", "28286 Filelist.csv \n", "21858 CAM.coll.PS.list.individuals.haplotagging.new.... \n", "12708 2001_2.broods.batch.1.csv \n", "\n", " zenodo_link Sequence \\\n", "34925 https://zenodo.org/record/4291095 41,457 \n", "28286 https://zenodo.org/record/5561246 36,145 \n", "21858 https://zenodo.org/record/4153502 17,409 \n", "12708 https://zenodo.org/record/2549524 10,412 \n", "\n", " Taxonomic_Name Locality \\\n", "34925 Heliconius timareta Reventador road 2 \n", "28286 Methona singularis Guaribas - RG16 \n", "21858 Heliconius erato ssp. lativitta San Pedro de Arajuno, Río Arajuno \n", "12708 Heliconius sp. NaN \n", "\n", " Sample_accession ... Cross_Type Stage Sex Unit_Type file_type \\\n", "34925 NaN ... NaN NaN Male NaN raw \n", "28286 NaN ... NaN NaN Male NaN jpg \n", "21858 ERS353373 ... NaN NaN Female wild raw \n", "12708 NaN ... NaN NaN Unknown reared raw \n", "\n", " record_number species subspecies genus \\\n", "34925 4291095 Heliconius timareta NaN Heliconius \n", "28286 5561246 Methona singularis NaN Methona \n", "21858 4153502 Heliconius erato lativitta Heliconius \n", "12708 2549524 Heliconius sp. NaN Heliconius \n", "\n", " file_url \n", "34925 https://zenodo.org/record/4291095/files/CAM041... \n", "28286 https://zenodo.org/record/5561246/files/CAM036... \n", "21858 https://zenodo.org/record/4153502/files/CAM017... \n", "12708 https://zenodo.org/record/2549524/files/CAM010... \n", "\n", "[4 rows x 27 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[\"file_url\"] = df[\"zenodo_link\"] + \"/files/\" + df[\"Image_name\"]\n", "df.sample(4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add Proper Taxonomic Name for Crosstypes\n", "\n", "We want the cross types to also have full taxonomic names (`Heliconius `) so this can be used in downloading to appropriate branches and also for easier diversity counts. Cross Types will still be easily filtered using the `Cross_Type` column." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "subspecies\n", "(malleti x plesseni) x malleti 1007\n", "plesseni x (malleti x plesseni) 462\n", "(plesseni x malleti) x (malleti x plesseni) 348\n", "(plesseni x malleti) x plesseni 345\n", "malleti x (plesseni x malleti) 324\n", "(plesseni x malleti) x (plesseni x malleti) 228\n", "(malleti x plesseni) x plesseni 216\n", "plesseni x malleti 212\n", "malleti x plesseni 156\n", "lativitta x notabilis 111\n", "plesseni x (plesseni x malleti) 106\n", "(lativitta x notabilis) x notabilis 90\n", "(lativitta x notabilis) x lativitta 90\n", "(malleti x plesseni) x (malleti x plesseni) 81\n", "(plesseni x malleti) x malleti 80\n", "(malleti x plesseni) x (plesseni x malleti) 42\n", "malleti 28\n", "plesseni 28\n", "(latRo x notabilis) x notabilis 12\n", "latRo x notabilis 4\n", "lativitta 4\n", "Name: count, dtype: int64" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[df[\"Cross_Type\"].notna(), \"subspecies\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Cross_Type\n", "Test cross (4 spots x 4 spots) 150\n", "Test cross (N heterozygocity - NBNN x malleti - thin) 114\n", "Test cross (N heterozygozity) 78\n", "Test cross (short HW bar) 54\n", "Test cross (4 spots x 2 banded) 48\n", "2 banded 16\n", "hybrid 10\n", "Ac heterozygote 4\n", "Test cross (2 banded F2 x 2 banded F2) 4\n", "Name: count, dtype: int64" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[(df[\"Cross_Type\"].notna()) & (df[\"subspecies\"].isna()), \"Cross_Type\"].value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice that we have hybrids here which should be indicated as such though they don't all have an ` x ` in their name. We'll remember this for the `hybrid_stat` column and generate using the Cross Type indicator. Our only non-hybrid Cross Types are `malleti`, `plesseni`, and `lativitta`." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['hybrid', 'Ac heterozygote', '2 banded',\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 malleti - thin)'],\n", " dtype=object)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "non_specific_cross_hybrids = df.loc[(df[\"Cross_Type\"].notna()) & (df[\"subspecies\"].isna()), \"Cross_Type\"].unique()\n", "non_specific_cross_hybrids" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['cythera', 'cyrbia', 'venus', 'venus x chestertonii', 'vulcanus',\n", " 'chestertonii', 'vulcanus x melpomene', 'lativitta', 'malleti',\n", " 'erato', 'ssp.nov.P', 'melpomene', 'willmotti',\n", " 'chestertonii x venus', 'eleuchia', 'cydnides', 'weymeri',\n", " 'chioneus', 'demophoon', 'hydara', 'sapho', 'numata', 'iulia',\n", " 'melpomene x thelxiope', 'wallacei', 'rosina', 'formosus',\n", " 'melpomene x rosina', 'menapis', 'hydara x petiverana', 'decumana',\n", " 'relata', 'agna', 'isthmia', 'bicoloratus', 'euphrasius',\n", " 'salapia', 'matronalis', 'ethica', 'agnosia', 'andromica',\n", " 'hippocrenis', 'saturata', 'evanides', 'lyra', 'pagasa',\n", " 'staudingeri', 'valora', 'cassotis', 'chiriquensis', 'alithea',\n", " 'timareta', 'plesseni', 'notabilis', 'amaryllis', 'thelxinoe',\n", " 'doris', 'amaryllis x aglaope', 'aglaope', 'carbo', 'lycaste',\n", " 'idae', 'macrinus', 'abida', 'notilla', 'neustetteri', 'giulia',\n", " 'panamensis', 'eleusinus', 'agalla', 'xanthina', 'ecuadorensis',\n", " 'congener', 'etylus', 'derasa', 'lenaeus', 'petiverana',\n", " 'melicerta', 'thelxiopeia', 'meriana', 'plesseni x malleti',\n", " 'notabilis x lativitta', 'sara', 'silvana', 'amalfreda',\n", " 'hydara x amalfreda', 'flavescens', 'hydara x erato',\n", " 'meriana x melpomene', 'nanna', 'daetina', 'nesaea', 'phyllis',\n", " 'laphria', 'paraiya', 'lysimnia', 'daeta', 'yanetta', 'pyrrha',\n", " 'casabranca', 'tristero', 'dignus', 'bellula',\n", " 'dignus x lativitta', 'malleti x bellula', 'napoensis',\n", " 'clysonymus', 'sotericus', 'primularis', 'sprucei', 'bassleri',\n", " 'eximius', 'manabiana', 'nigrippus', 'hygiana', 'neildi',\n", " 'clysonomus', 'hierax', 'magdalena', 'calathus', 'corena',\n", " 'zelinde', 'florencia', 'weymeri f. gustavi', 'weymeri f. weymeri',\n", " 'wanningeri', 'cydno', 'cordula', 'linaresi', 'lisethae',\n", " 'hermogenes', 'martinae', 'vicina', 'malleti x vicina',\n", " 'reductimacula', 'sergestus', 'felix', 'aerotome'], dtype=object)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[df[\"Cross_Type\"].isna(), \"subspecies\"].dropna().unique()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "def get_cross_taxa_name(species, cross_type):\n", " # label unspecified hybrids as such\n", " if cross_type in non_specific_cross_hybrids:\n", " return species + \" \" + \"cross hybrid\"\n", " \n", " # separate out hybrids from non-hybrids\n", " subsp_cross_list = cross_type.split(\"(\")\n", " if len(subsp_cross_list) > 1:\n", " subsp_cross = subsp_cross_list[1].split(\")\")[0]\n", " else:\n", " subsp_cross = cross_type\n", " \n", " # Ensure order of hybrid names is consistent so they get placed in same folders (using scripts/download_jiggins.py)\n", " # And so counts by taxonomic name aren't needlessly skewed\n", " if subsp_cross == \"malleti x plesseni\":\n", " subsp_cross = \"plesseni x malleti\"\n", " elif subsp_cross == \"lativitta x notabilis\":\n", " subsp_cross = \"notabilis x lativitta\"\n", " \n", " # Set taxa_name as with non cross types labeled to subspecies\n", " taxa_name = species + \" ssp. \" + subsp_cross\n", " return taxa_name" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "H.sp. ssp. malleti\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. ssp. plesseni\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. ssp. latRo x notabilis\n", "H.sp. ssp. latRo x notabilis\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. ssp. notabilis x lativitta\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. cross hybrid\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. ssp. notabilis x lativitta\n", "H.sp. ssp. notabilis x lativitta\n", "H.sp. cross hybrid\n", "H.sp. ssp. plesseni x malleti\n", "H.sp. cross hybrid\n", "H.sp. ssp. lativitta\n", "H.sp. cross hybrid\n", "H.sp. cross hybrid\n", "H.sp. cross hybrid\n", "H.sp. cross hybrid\n", "H.sp. cross hybrid\n", "H.sp. cross hybrid\n" ] } ], "source": [ "for cross_type in list(df[\"Cross_Type\"].dropna().unique()):\n", " print(get_cross_taxa_name(\"H.sp.\", cross_type))" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['Heliconius melpomene', 'Heliconius erato'], dtype=object)" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[df[\"Cross_Type\"].notna(), \"species\"].unique()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['Heliconius melpomene ssp. malleti',\n", " 'Heliconius melpomene ssp. plesseni x malleti',\n", " 'Heliconius melpomene ssp. plesseni',\n", " 'Heliconius erato ssp. latRo x notabilis',\n", " 'Heliconius erato ssp. notabilis x lativitta',\n", " 'Heliconius erato cross hybrid',\n", " 'Heliconius melpomene cross hybrid',\n", " 'Heliconius erato ssp. lativitta'], dtype=object)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# https://stackoverflow.com/a/52854800\n", "df.loc[df[\"Cross_Type\"].notna(), \"Taxonomic_Name\"] = df.loc[df[\"Cross_Type\"].notna()].apply(lambda x: get_cross_taxa_name(x[\"species\"], x[\"Cross_Type\"]), axis = 1)\n", "df.loc[df[\"Cross_Type\"].notna(), \"Taxonomic_Name\"].unique()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "366" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.Taxonomic_Name.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So we've added 3 more unique values of `Taxonomic_Name`, that checks out: `Heliconius erato ssp. latRo x notabilis`, `Heliconius erato cross hybrid`, and `Heliconius melpomene cross hybrid`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add Hybrid Status Column" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "20" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hybrids = [taxa_name for taxa_name in list(df[\"Taxonomic_Name\"].dropna().unique()) if (\" x \" in taxa_name) or (\"hybrid\" in taxa_name)]\n", "len(hybrids)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Heliconius erato ssp. venus x chestertonii',\n", " 'Heliconius melpomene ssp. vulcanus x melpomene',\n", " 'Heliconius erato ssp. chestertonii x venus',\n", " 'Heliconius melpomene ssp. melpomene x thelxiope',\n", " 'Heliconius melpomene ssp. melpomene x rosina',\n", " 'Heliconius hybrid',\n", " 'Heliconius erato ssp. hydara x petiverana',\n", " 'Heliconius melpomene ssp. amaryllis x aglaope',\n", " 'Anartia fatima x amathea',\n", " 'Heliconius melpomene ssp. plesseni x malleti',\n", " 'Heliconius erato ssp. notabilis x lativitta',\n", " 'Heliconius erato ssp. latRo x notabilis',\n", " 'Heliconius erato cross hybrid',\n", " 'Heliconius melpomene cross hybrid',\n", " 'Heliconius erato ssp. hydara x amalfreda',\n", " 'Heliconius erato ssp. hydara x erato',\n", " 'Heliconius melpomene ssp. meriana x melpomene',\n", " 'Heliconius melpomene ssp. dignus x lativitta',\n", " 'Heliconius melpomene ssp. malleti x bellula',\n", " 'Heliconius melpomene ssp. malleti x vicina']" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hybrids" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Observe that we have one species-level hybrid: `Anartia fatima x amathea`." ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "sp_hybrid_parents = [\"Anartia fatima\", \"Anartia amathea\"]" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "df[\"hybrid_stat\"] = None\n", "df.loc[df[\"subspecies\"].notna(), \"hybrid_stat\"] = \"non-hybrid\"\n", "df.loc[df[\"species\"].isin(sp_hybrid_parents), \"hybrid_stat\"] = \"non-hybrid\"\n", "\n", "df.loc[df[\"Taxonomic_Name\"].isin(hybrids), \"hybrid_stat\"] = \"hybrid\"" ] }, { "cell_type": "code", "execution_count": 23, "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", " \n", " \n", " \n", " \n", " \n", " \n", "
CAMIDXImage_nameViewzenodo_namezenodo_linkSequenceTaxonomic_NameLocalitySample_accession...StageSexUnit_Typefile_typerecord_numberspeciessubspeciesgenusfile_urlhybrid_stat
7326CAM0028908482CAM002890_v.JPGventralCAM.coll.images.batch5.csvhttps://zenodo.org/record/26849062,890Anartia fatimaEl Tirao,NaN...NaNFemalewildjpg2684906Anartia fatimaNaNAnartiahttps://zenodo.org/record/2684906/files/CAM002...non-hybrid
7327CAM00289045376CAM002890_v.JPGventraloccurences_and_multimedia.csvhttps://zenodo.org/record/34778912,890Anartia fatimaEl Tirao,NaN...NaNFemalewildjpg3477891Anartia fatimaNaNAnartiahttps://zenodo.org/record/3477891/files/CAM002...non-hybrid
7328CAM00289045375CAM002890_d.JPGdorsaloccurences_and_multimedia.csvhttps://zenodo.org/record/34778912,890Anartia fatimaEl Tirao,NaN...NaNFemalewildjpg3477891Anartia fatimaNaNAnartiahttps://zenodo.org/record/3477891/files/CAM002...non-hybrid
7329CAM0028908481CAM002890_d.JPGdorsalCAM.coll.images.batch5.csvhttps://zenodo.org/record/26849062,890Anartia fatimaEl Tirao,NaN...NaNFemalewildjpg2684906Anartia fatimaNaNAnartiahttps://zenodo.org/record/2684906/files/CAM002...non-hybrid
\n", "

4 rows × 28 columns

\n", "
" ], "text/plain": [ " CAMID X Image_name View \\\n", "7326 CAM002890 8482 CAM002890_v.JPG ventral \n", "7327 CAM002890 45376 CAM002890_v.JPG ventral \n", "7328 CAM002890 45375 CAM002890_d.JPG dorsal \n", "7329 CAM002890 8481 CAM002890_d.JPG dorsal \n", "\n", " zenodo_name zenodo_link \\\n", "7326 CAM.coll.images.batch5.csv https://zenodo.org/record/2684906 \n", "7327 occurences_and_multimedia.csv https://zenodo.org/record/3477891 \n", "7328 occurences_and_multimedia.csv https://zenodo.org/record/3477891 \n", "7329 CAM.coll.images.batch5.csv https://zenodo.org/record/2684906 \n", "\n", " Sequence Taxonomic_Name Locality Sample_accession ... Stage Sex \\\n", "7326 2,890 Anartia fatima El Tirao, NaN ... NaN Female \n", "7327 2,890 Anartia fatima El Tirao, NaN ... NaN Female \n", "7328 2,890 Anartia fatima El Tirao, NaN ... NaN Female \n", "7329 2,890 Anartia fatima El Tirao, NaN ... NaN Female \n", "\n", " Unit_Type file_type record_number species subspecies genus \\\n", "7326 wild jpg 2684906 Anartia fatima NaN Anartia \n", "7327 wild jpg 3477891 Anartia fatima NaN Anartia \n", "7328 wild jpg 3477891 Anartia fatima NaN Anartia \n", "7329 wild jpg 2684906 Anartia fatima NaN Anartia \n", "\n", " file_url hybrid_stat \n", "7326 https://zenodo.org/record/2684906/files/CAM002... non-hybrid \n", "7327 https://zenodo.org/record/3477891/files/CAM002... non-hybrid \n", "7328 https://zenodo.org/record/3477891/files/CAM002... non-hybrid \n", "7329 https://zenodo.org/record/2684906/files/CAM002... non-hybrid \n", "\n", "[4 rows x 28 columns]" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[df[\"species\"].isin(sp_hybrid_parents)]" ] }, { "cell_type": "code", "execution_count": 24, "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", "
CAMIDXImage_nameViewzenodo_namezenodo_linkSequenceTaxonomic_NameLocalitySample_accession...StageSexUnit_Typefile_typerecord_numberspeciessubspeciesgenusfile_urlhybrid_stat
\n", "

0 rows × 28 columns

\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [CAMID, X, Image_name, View, zenodo_name, zenodo_link, Sequence, Taxonomic_Name, Locality, Sample_accession, Collected_by, Other_ID, Date, Dataset, Store, Brood, Death_Date, Cross_Type, Stage, Sex, Unit_Type, file_type, record_number, species, subspecies, genus, file_url, hybrid_stat]\n", "Index: []\n", "\n", "[0 rows x 28 columns]" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[df[\"species\"].str.lower() == \"amathea\"] #not represented in the dataset" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Taxonomic_Name\n", "Anartia fatima x amathea 60\n", "Anartia fatima 4\n", "Name: count, dtype: int64" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[df[\"genus\"] == \"Anartia\", \"Taxonomic_Name\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 26, "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", " \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", "
CAMIDXImage_nameViewzenodo_namezenodo_linkSequenceTaxonomic_NameLocalitySample_accession...StageSexUnit_Typefile_typerecord_numberspeciessubspeciesgenusfile_urlhybrid_stat
40498CAM04384232098CAM043842_hwv.JPGhindwing ventralbatch2.Peru.image.names.Zenodo.csvhttps://zenodo.org/record/428744443,842Catoblepia berecynthiaB1prim3NaN...NaNNaNNaNjpg4287444Catoblepia berecynthiaNaNCatoblepiahttps://zenodo.org/record/4287444/files/CAM043...None
9192CAM00856746249CAM008567_v.JPGventraloccurences_and_multimedia.csvhttps://zenodo.org/record/34778918,567Heliconius demeterTarapoto-Yurimaguas (Km15), Tunel Cumbre, Fond...NaN...NaNMalewildjpg3477891Heliconius demeterNaNHeliconiushttps://zenodo.org/record/3477891/files/CAM008...None
14127CAM01097127577CAM010971_d.CR2dorsal2001_2.broods.batch.1.csvhttps://zenodo.org/record/254952410,971Heliconius sp.NaNNaN...NaNMalerearedraw2549524Heliconius sp.NaNHeliconiushttps://zenodo.org/record/2549524/files/CAM010...None
5315CAM0005376676CAM000537_d.JPGdorsalCAM.coll.images.batch3.csvhttps://zenodo.org/record/2682458537Heliconius melpomene ssp. rosinaPipeline road 4km,NaN...NaNMalewildjpg2682458Heliconius melpomenerosinaHeliconiushttps://zenodo.org/record/2682458/files/CAM000...non-hybrid
58519N02041955319N0204_d.JPGdorsal0.sheffield.ps.nn.ikiam.batch1.csvhttps://zenodo.org/record/4288311204Heliconius erato ssp. lativittaIkiam MariposarioNaN...NaNMalerearedjpg4288311Heliconius eratolativittaHeliconiushttps://zenodo.org/record/4288311/files/19N020...non-hybrid
38875CAM04336630469CAM043366_v.CR2ventralbatch1.Peru.image.names.Zenodo.csvhttps://zenodo.org/record/356959843,366Eunica pusillaB6rec3NaN...NaNNaNNaNraw3569598Eunica pusillaNaNEunicahttps://zenodo.org/record/3569598/files/CAM043...None
19226CAM01668718917CAM016687_d.CR2dorsalCAM.coll.PS.list.individuals.haplotagging.new....https://zenodo.org/record/415350216,687Heliconius melpomene ssp. plesseniEl Topo, Baños - Puyo road,SRS7540355...NaNMalewildraw4153502Heliconius melpomeneplesseniHeliconiushttps://zenodo.org/record/4153502/files/CAM016...non-hybrid
\n", "

7 rows × 28 columns

\n", "
" ], "text/plain": [ " CAMID X Image_name View \\\n", "40498 CAM043842 32098 CAM043842_hwv.JPG hindwing ventral \n", "9192 CAM008567 46249 CAM008567_v.JPG ventral \n", "14127 CAM010971 27577 CAM010971_d.CR2 dorsal \n", "5315 CAM000537 6676 CAM000537_d.JPG dorsal \n", "585 19N0204 19553 19N0204_d.JPG dorsal \n", "38875 CAM043366 30469 CAM043366_v.CR2 ventral \n", "19226 CAM016687 18917 CAM016687_d.CR2 dorsal \n", "\n", " zenodo_name \\\n", "40498 batch2.Peru.image.names.Zenodo.csv \n", "9192 occurences_and_multimedia.csv \n", "14127 2001_2.broods.batch.1.csv \n", "5315 CAM.coll.images.batch3.csv \n", "585 0.sheffield.ps.nn.ikiam.batch1.csv \n", "38875 batch1.Peru.image.names.Zenodo.csv \n", "19226 CAM.coll.PS.list.individuals.haplotagging.new.... \n", "\n", " zenodo_link Sequence \\\n", "40498 https://zenodo.org/record/4287444 43,842 \n", "9192 https://zenodo.org/record/3477891 8,567 \n", "14127 https://zenodo.org/record/2549524 10,971 \n", "5315 https://zenodo.org/record/2682458 537 \n", "585 https://zenodo.org/record/4288311 204 \n", "38875 https://zenodo.org/record/3569598 43,366 \n", "19226 https://zenodo.org/record/4153502 16,687 \n", "\n", " Taxonomic_Name \\\n", "40498 Catoblepia berecynthia \n", "9192 Heliconius demeter \n", "14127 Heliconius sp. \n", "5315 Heliconius melpomene ssp. rosina \n", "585 Heliconius erato ssp. lativitta \n", "38875 Eunica pusilla \n", "19226 Heliconius melpomene ssp. plesseni \n", "\n", " Locality Sample_accession \\\n", "40498 B1prim3 NaN \n", "9192 Tarapoto-Yurimaguas (Km15), Tunel Cumbre, Fond... NaN \n", "14127 NaN NaN \n", "5315 Pipeline road 4km, NaN \n", "585 Ikiam Mariposario NaN \n", "38875 B6rec3 NaN \n", "19226 El Topo, Baños - Puyo road, SRS7540355 \n", "\n", " ... Stage Sex Unit_Type file_type record_number \\\n", "40498 ... NaN NaN NaN jpg 4287444 \n", "9192 ... NaN Male wild jpg 3477891 \n", "14127 ... NaN Male reared raw 2549524 \n", "5315 ... NaN Male wild jpg 2682458 \n", "585 ... NaN Male reared jpg 4288311 \n", "38875 ... NaN NaN NaN raw 3569598 \n", "19226 ... NaN Male wild raw 4153502 \n", "\n", " species subspecies genus \\\n", "40498 Catoblepia berecynthia NaN Catoblepia \n", "9192 Heliconius demeter NaN Heliconius \n", "14127 Heliconius sp. NaN Heliconius \n", "5315 Heliconius melpomene rosina Heliconius \n", "585 Heliconius erato lativitta Heliconius \n", "38875 Eunica pusilla NaN Eunica \n", "19226 Heliconius melpomene plesseni Heliconius \n", "\n", " file_url hybrid_stat \n", "40498 https://zenodo.org/record/4287444/files/CAM043... None \n", "9192 https://zenodo.org/record/3477891/files/CAM008... None \n", "14127 https://zenodo.org/record/2549524/files/CAM010... None \n", "5315 https://zenodo.org/record/2682458/files/CAM000... non-hybrid \n", "585 https://zenodo.org/record/4288311/files/19N020... non-hybrid \n", "38875 https://zenodo.org/record/3569598/files/CAM043... None \n", "19226 https://zenodo.org/record/4153502/files/CAM016... non-hybrid \n", "\n", "[7 rows x 28 columns]" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.sample(7)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Investigate entries with no Taxonomic Information" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 3886 entries, 0 to 49350\n", "Data columns (total 28 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 CAMID 3886 non-null object\n", " 1 X 3886 non-null int64 \n", " 2 Image_name 3886 non-null object\n", " 3 View 3594 non-null object\n", " 4 zenodo_name 3886 non-null object\n", " 5 zenodo_link 3886 non-null object\n", " 6 Sequence 2951 non-null object\n", " 7 Taxonomic_Name 0 non-null object\n", " 8 Locality 70 non-null object\n", " 9 Sample_accession 24 non-null object\n", " 10 Collected_by 0 non-null object\n", " 11 Other_ID 30 non-null object\n", " 12 Date 70 non-null object\n", " 13 Dataset 461 non-null object\n", " 14 Store 345 non-null object\n", " 15 Brood 5 non-null object\n", " 16 Death_Date 2 non-null object\n", " 17 Cross_Type 0 non-null object\n", " 18 Stage 9 non-null object\n", " 19 Sex 35 non-null object\n", " 20 Unit_Type 47 non-null object\n", " 21 file_type 3886 non-null object\n", " 22 record_number 3886 non-null int64 \n", " 23 species 0 non-null object\n", " 24 subspecies 0 non-null object\n", " 25 genus 0 non-null object\n", " 26 file_url 3886 non-null object\n", " 27 hybrid_stat 0 non-null object\n", "dtypes: int64(2), object(26)\n", "memory usage: 880.4+ KB\n" ] } ], "source": [ "df.loc[df.Taxonomic_Name.isna()].info()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Wow, there are a surprising number of images with no taxonomic information." ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "no_taxa_cams = list(df.loc[df[\"Taxonomic_Name\"].isna(), \"CAMID\"].unique())\n", "no_taxa_entries = list(df.loc[df[\"Taxonomic_Name\"].isna(), \"X\"])\n", "\n", "no_taxa_cam_match = [camid for camid in list(df.loc[~df[\"X\"].isin(no_taxa_entries), \"CAMID\"]) if camid in no_taxa_cams]\n", "len(no_taxa_cam_match)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are no CAMIDs that these can match to for taxonomic info recovery. Last option is to check the records they come from, then we'll remove them." ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "21\n" ] }, { "data": { "text/plain": [ "zenodo_link\n", "https://zenodo.org/record/5526257 1324\n", "https://zenodo.org/record/2554218 492\n", "https://zenodo.org/record/4288311 486\n", "https://zenodo.org/record/2555086 440\n", "https://zenodo.org/record/5731587 388\n", "Name: count, dtype: int64" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print(df.loc[df[\"X\"].isin(no_taxa_entries), \"record_number\"].nunique())\n", "df.loc[df[\"X\"].isin(no_taxa_entries), \"zenodo_link\"].value_counts()[:5]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These are across most of the records. We can check the one with the most, but otherwise they should likely be dropped (can save them in a separate CSV in case they are to be assessed at a later point).\n", "\n", "The first appear to be all _Heliconius erato ssp. cyrbia_, so those could be realigned.\n", "\n", "The second indicates all _Heliconius erato_.\n", "\n", "The third is a mix, so not resolvable without an expert.\n", "\n", "It seems record 2555086 is all bred specimens of _Heliconius erato demophoon_.\n", "\n", "The fifth record is a mix, and not all are labeled in the excel file (in fact, there's a lot of red which is probably why they were excluded)." ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 1324 entries, 45868 to 47191\n", "Series name: Taxonomic_Name\n", "Non-Null Count Dtype \n", "-------------- ----- \n", "0 non-null object\n", "dtypes: object(1)\n", "memory usage: 20.7+ KB\n" ] } ], "source": [ "df.loc[df[\"record_number\"] == 5526257, \"Taxonomic_Name\"].info()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ah, so these are all null, but all are of the same subspecies, so they can be labeled." ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pot_single_taxa_records = []\n", "for record_num in (df.loc[df[\"X\"].isin(no_taxa_entries), \"record_number\"].unique()):\n", " temp = df.loc[df[\"record_number\"] == record_num]\n", " if temp.loc[temp[\"Taxonomic_Name\"].notna()].shape[0] == 0:\n", " pot_single_taxa_records.append(record_num)\n", "\n", "len(pot_single_taxa_records)" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[5731587, 5526257, 2554218, 2555086]" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pot_single_taxa_records" ] }, { "cell_type": "code", "execution_count": 33, "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", " \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", "
CAMIDXImage_nameViewzenodo_namezenodo_linkSequenceTaxonomic_NameLocalitySample_accession...StageSexUnit_Typefile_typerecord_numberspeciessubspeciesgenusfile_urlhybrid_stat
46747CAM04521943439CAM045219_d.JPGdorsalimage.names.cook.island.erato.csvhttps://zenodo.org/record/552625745,219NaNNaNNaN...NaNNaNNaNjpg5526257NaNNaNNaNhttps://zenodo.org/record/5526257/files/CAM045...None
47062CAM04529843756CAM045298_v.CR2ventralimage.names.cook.island.erato.csvhttps://zenodo.org/record/552625745,298NaNNaNNaN...NaNNaNNaNraw5526257NaNNaNNaNhttps://zenodo.org/record/5526257/files/CAM045...None
37255CAM04205043982CAM042050_d.JPGdorsalCollection_August2019.csvhttps://zenodo.org/record/573158742,050NaNNaNNaN...NaNNaNNaNjpg5731587NaNNaNNaNhttps://zenodo.org/record/5731587/files/CAM042...None
46992CAM04528143687CAM045281_d.JPGdorsalimage.names.cook.island.erato.csvhttps://zenodo.org/record/552625745,281NaNNaNNaN...NaNNaNNaNjpg5526257NaNNaNNaNhttps://zenodo.org/record/5526257/files/CAM045...None
49106F90138167F901_d.CR2dorsalAnniina.Mattila.Bred.F.csvhttps://zenodo.org/record/2555086NaNNaNNaNNaN...NaNNaNNaNraw2555086NaNNaNNaNhttps://zenodo.org/record/2555086/files/F901_d...None
\n", "

5 rows × 28 columns

\n", "
" ], "text/plain": [ " CAMID X Image_name View \\\n", "46747 CAM045219 43439 CAM045219_d.JPG dorsal \n", "47062 CAM045298 43756 CAM045298_v.CR2 ventral \n", "37255 CAM042050 43982 CAM042050_d.JPG dorsal \n", "46992 CAM045281 43687 CAM045281_d.JPG dorsal \n", "49106 F901 38167 F901_d.CR2 dorsal \n", "\n", " zenodo_name zenodo_link \\\n", "46747 image.names.cook.island.erato.csv https://zenodo.org/record/5526257 \n", "47062 image.names.cook.island.erato.csv https://zenodo.org/record/5526257 \n", "37255 Collection_August2019.csv https://zenodo.org/record/5731587 \n", "46992 image.names.cook.island.erato.csv https://zenodo.org/record/5526257 \n", "49106 Anniina.Mattila.Bred.F.csv https://zenodo.org/record/2555086 \n", "\n", " Sequence Taxonomic_Name Locality Sample_accession ... Stage Sex \\\n", "46747 45,219 NaN NaN NaN ... NaN NaN \n", "47062 45,298 NaN NaN NaN ... NaN NaN \n", "37255 42,050 NaN NaN NaN ... NaN NaN \n", "46992 45,281 NaN NaN NaN ... NaN NaN \n", "49106 NaN NaN NaN NaN ... NaN NaN \n", "\n", " Unit_Type file_type record_number species subspecies genus \\\n", "46747 NaN jpg 5526257 NaN NaN NaN \n", "47062 NaN raw 5526257 NaN NaN NaN \n", "37255 NaN jpg 5731587 NaN NaN NaN \n", "46992 NaN jpg 5526257 NaN NaN NaN \n", "49106 NaN raw 2555086 NaN NaN NaN \n", "\n", " file_url hybrid_stat \n", "46747 https://zenodo.org/record/5526257/files/CAM045... None \n", "47062 https://zenodo.org/record/5526257/files/CAM045... None \n", "37255 https://zenodo.org/record/5731587/files/CAM042... None \n", "46992 https://zenodo.org/record/5526257/files/CAM045... None \n", "49106 https://zenodo.org/record/2555086/files/F901_d... None \n", "\n", "[5 rows x 28 columns]" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[df.record_number.isin(pot_single_taxa_records)].sample(5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Christopher agrees that the following is sufficient to label images from the following three records:\n", ">3 records seem to have all of just one indicated species/subspecies: https://zenodo.org/record/5526257, https://zenodo.org/record/2554218, and https://zenodo.org/record/2555086. According to their Zenodo pages, the first appear to be all _Heliconius erato ssp. cyrbia_, the second indicates all _Heliconius erato_, and the third it seems is all bred specimens of _Heliconius erato demophoon_. \n", "\n", "`Unit_Type` and some other details could potentially be realigned at a later date, but we'll stick with taxonomic information for now." ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "df.loc[df[\"record_number\"] == 5526257, \"Taxonomic_Name\"] = \"Heliconius erato ssp. cyrbia\"\n", "df.loc[df[\"record_number\"] == 5526257, \"genus\"] = \"Heliconius\"\n", "df.loc[df[\"record_number\"] == 5526257, \"species\"] = \"Heliconius erato\"\n", "df.loc[df[\"record_number\"] == 5526257, \"subspecies\"] = \"cyrbia\"\n", "df.loc[df[\"record_number\"] == 5526257, \"hybrid_stat\"] = \"non-hybrid\"" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "df.loc[df[\"record_number\"] == 2554218, \"Taxonomic_Name\"] = \"Heliconius erato\"\n", "df.loc[df[\"record_number\"] == 2554218, \"genus\"] = \"Heliconius\"\n", "df.loc[df[\"record_number\"] == 2554218, \"species\"] = \"Heliconius erato\"" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "df.loc[df[\"record_number\"] == 2555086, \"Taxonomic_Name\"] = \"Heliconius erato ssp. demophoon\"\n", "df.loc[df[\"record_number\"] == 2555086, \"genus\"] = \"Heliconius\"\n", "df.loc[df[\"record_number\"] == 2555086, \"species\"] = \"Heliconius erato\"\n", "df.loc[df[\"record_number\"] == 2555086, \"subspecies\"] = \"demophoon\"\n", "df.loc[df[\"record_number\"] == 2555086, \"hybrid_stat\"] = \"non-hybrid\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Save record of entries with no Taxonomic Info" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1630, 28)" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "missing_taxa_df = df.loc[df.Taxonomic_Name.isna()]\n", "missing_taxa_df.shape" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "missing_taxa_df.to_csv(\"../metadata/Missing_taxa_Jiggins_Zenodo_Master.csv\", index = False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Drop Entries with no Taxonomic Information" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "master_df = df.loc[df.Taxonomic_Name.notna()]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Final stats for all data in master file summarized here." ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 11991\n", "X 44809\n", "Image_name 36281\n", "View 7\n", "zenodo_name 33\n", "zenodo_link 30\n", "Sequence 10905\n", "Taxonomic_Name 366\n", "Locality 645\n", "Sample_accession 1559\n", "Collected_by 12\n", "Other_ID 3081\n", "Date 807\n", "Dataset 8\n", "Store 137\n", "Brood 224\n", "Death_Date 81\n", "Cross_Type 30\n", "Stage 1\n", "Sex 3\n", "Unit_Type 4\n", "file_type 3\n", "record_number 30\n", "species 246\n", "subspecies 155\n", "genus 94\n", "file_url 44794\n", "hybrid_stat 2\n", "dtype: int64" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master_df.nunique()" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 44809 entries, 6 to 49358\n", "Data columns (total 28 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 CAMID 44809 non-null object\n", " 1 X 44809 non-null int64 \n", " 2 Image_name 44809 non-null object\n", " 3 View 44030 non-null object\n", " 4 zenodo_name 44809 non-null object\n", " 5 zenodo_link 44809 non-null object\n", " 6 Sequence 43877 non-null object\n", " 7 Taxonomic_Name 44809 non-null object\n", " 8 Locality 31708 non-null object\n", " 9 Sample_accession 4572 non-null object\n", " 10 Collected_by 3043 non-null object\n", " 11 Other_ID 14352 non-null object\n", " 12 Date 30730 non-null object\n", " 13 Dataset 37024 non-null object\n", " 14 Store 36220 non-null object\n", " 15 Brood 14258 non-null object\n", " 16 Death_Date 316 non-null object\n", " 17 Cross_Type 4452 non-null object\n", " 18 Stage 6 non-null object\n", " 19 Sex 33312 non-null object\n", " 20 Unit_Type 30923 non-null object\n", " 21 file_type 44809 non-null object\n", " 22 record_number 44809 non-null int64 \n", " 23 species 44809 non-null object\n", " 24 subspecies 24559 non-null object\n", " 25 genus 44809 non-null object\n", " 26 file_url 44809 non-null object\n", " 27 hybrid_stat 25139 non-null object\n", "dtypes: int64(2), object(26)\n", "memory usage: 9.9+ MB\n" ] } ], "source": [ "master_df.info()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Update Master File with Hybrid Status and URL Columns (& unique records)" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "master_df.to_csv(\"../Jiggins_Zenodo_Img_Master.csv\", index = False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Make Heliconius Subset" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 34265 entries, 6 to 49358\n", "Data columns (total 28 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 CAMID 34265 non-null object\n", " 1 X 34265 non-null int64 \n", " 2 Image_name 34265 non-null object\n", " 3 View 33486 non-null object\n", " 4 zenodo_name 34265 non-null object\n", " 5 zenodo_link 34265 non-null object\n", " 6 Sequence 33333 non-null object\n", " 7 Taxonomic_Name 34265 non-null object\n", " 8 Locality 21180 non-null object\n", " 9 Sample_accession 4572 non-null object\n", " 10 Collected_by 3043 non-null object\n", " 11 Other_ID 6404 non-null object\n", " 12 Date 20244 non-null object\n", " 13 Dataset 29926 non-null object\n", " 14 Store 26526 non-null object\n", " 15 Brood 14242 non-null object\n", " 16 Death_Date 316 non-null object\n", " 17 Cross_Type 4452 non-null object\n", " 18 Stage 6 non-null object\n", " 19 Sex 30984 non-null object\n", " 20 Unit_Type 29055 non-null object\n", " 21 file_type 34265 non-null object\n", " 22 record_number 34265 non-null int64 \n", " 23 species 34265 non-null object\n", " 24 subspecies 23801 non-null object\n", " 25 genus 34265 non-null object\n", " 26 file_url 34265 non-null object\n", " 27 hybrid_stat 24317 non-null object\n", "dtypes: int64(2), object(26)\n", "memory usage: 7.6+ MB\n" ] } ], "source": [ "heliconius_subset = master_df.loc[master_df.genus.str.lower() == \"heliconius\"]\n", "\n", "heliconius_subset.info()" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 10109\n", "X 34265\n", "Image_name 29192\n", "View 3\n", "zenodo_name 33\n", "zenodo_link 30\n", "Sequence 9031\n", "Taxonomic_Name 132\n", "Locality 472\n", "Sample_accession 1559\n", "Collected_by 12\n", "Other_ID 1865\n", "Date 776\n", "Dataset 8\n", "Store 121\n", "Brood 224\n", "Death_Date 81\n", "Cross_Type 30\n", "Stage 1\n", "Sex 3\n", "Unit_Type 4\n", "file_type 3\n", "record_number 30\n", "species 37\n", "subspecies 110\n", "genus 1\n", "file_url 34250\n", "hybrid_stat 2\n", "dtype: int64" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "heliconius_subset.nunique()" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "View\n", "dorsal 16882\n", "ventral 16586\n", "dorsal and ventral 18\n", "Name: count, dtype: int64" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "heliconius_subset.View.value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that this subset is distributed across 30 Zenodo records from the [Butterfly Genetics Group](https://zenodo.org/communities/butterfly?q=&l=list&p=1&s=10&sort=newest)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Save the Heliconius Subset to CSV\n" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "heliconius_subset.to_csv(\"../Jiggins_Heliconius_Master.csv\", index = False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Make Dorsal Subset" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 22175 entries, 7 to 49357\n", "Data columns (total 28 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 CAMID 22175 non-null object\n", " 1 X 22175 non-null int64 \n", " 2 Image_name 22175 non-null object\n", " 3 View 22175 non-null object\n", " 4 zenodo_name 22175 non-null object\n", " 5 zenodo_link 22175 non-null object\n", " 6 Sequence 21709 non-null object\n", " 7 Taxonomic_Name 22175 non-null object\n", " 8 Locality 15615 non-null object\n", " 9 Sample_accession 2294 non-null object\n", " 10 Collected_by 1533 non-null object\n", " 11 Other_ID 6916 non-null object\n", " 12 Date 15347 non-null object\n", " 13 Dataset 18250 non-null object\n", " 14 Store 18254 non-null object\n", " 15 Brood 6920 non-null object\n", " 16 Death_Date 106 non-null object\n", " 17 Cross_Type 2230 non-null object\n", " 18 Stage 3 non-null object\n", " 19 Sex 16403 non-null object\n", " 20 Unit_Type 15203 non-null object\n", " 21 file_type 22175 non-null object\n", " 22 record_number 22175 non-null int64 \n", " 23 species 22175 non-null object\n", " 24 subspecies 12040 non-null object\n", " 25 genus 22175 non-null object\n", " 26 file_url 22175 non-null object\n", " 27 hybrid_stat 12330 non-null object\n", "dtypes: int64(2), object(26)\n", "memory usage: 4.9+ MB\n" ] } ], "source": [ "dorsal_views = [view for view in list(master_df.View.dropna().unique()) if \"dorsal\" in view]\n", "\n", "dorsal_subset = master_df.loc[master_df[\"View\"].isin(dorsal_views)]\n", "dorsal_subset.info()" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 11776\n", "X 22175\n", "Image_name 17907\n", "View 4\n", "zenodo_name 33\n", "zenodo_link 30\n", "Sequence 10713\n", "Taxonomic_Name 362\n", "Locality 642\n", "Sample_accession 1552\n", "Collected_by 12\n", "Other_ID 2890\n", "Date 791\n", "Dataset 8\n", "Store 137\n", "Brood 215\n", "Death_Date 63\n", "Cross_Type 30\n", "Stage 1\n", "Sex 3\n", "Unit_Type 4\n", "file_type 3\n", "record_number 30\n", "species 245\n", "subspecies 152\n", "genus 94\n", "file_url 22168\n", "hybrid_stat 2\n", "dtype: int64" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_subset.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Observe that we still have duplicate samples (duplicated `CAMID`), so we'll add a column indicating this (`CAM_Dupe`). We will not leave the first instance as a non-duplicate to have a clear assessment of all duplication (eg., is it just across a couple records).\n", "\n", "Note that they will be duplicated for the images that are of a dorsal forewing or hindwing, so we will label those as `single_wing`." ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/var/folders/nv/f0fq1p1n1_3b11x579py_0q80000gq/T/ipykernel_21745/2272441064.py:1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " dorsal_subset[\"CAM_Dupe\"] = dorsal_subset.duplicated(subset = \"CAMID\", keep = False)\n" ] }, { "data": { "text/plain": [ "CAM_Dupe\n", "True 17213\n", "False 4170\n", "single-wing 792\n", "Name: count, dtype: int64" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_subset[\"CAM_Dupe\"] = dorsal_subset.duplicated(subset = \"CAMID\", keep = False)\n", "dorsal_subset.loc[dorsal_subset[\"View\"].isin([\"forewing dorsal\", \"hindwing dorsal\"]), \"CAM_Dupe\"] = \"single-wing\"\n", "dorsal_subset[\"CAM_Dupe\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "29" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_subset.loc[dorsal_subset[\"CAM_Dupe\"] == True, \"record_number\"].nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Okay, nearly all records have duplication even in the dorsal subset. That does make sense when we have just over half as many unique `CAMID`s as number of images." ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "record_number\n", "4287444 396\n", "4288250 284\n", "3569598 112\n", "Name: count, dtype: int64" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_subset.loc[dorsal_subset[\"CAM_Dupe\"] == \"single-wing\", \"record_number\"].value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Single-wing images are constrained to 3 records." ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "file_type\n", "jpg 11752\n", "raw 5440\n", "tif 21\n", "Name: count, dtype: int64" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_subset.loc[dorsal_subset[\"CAM_Dupe\"] == True, \"file_type\"].value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Some of this duplication is by file type." ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True 8415\n", "False 3337\n", "Name: count, dtype: int64" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_subset.loc[(dorsal_subset[\"CAM_Dupe\"] == True) & (dorsal_subset[\"file_type\"] == \"jpg\")].duplicated(subset = \"CAMID\", keep = False).value_counts()" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False 4106\n", "True 1334\n", "Name: count, dtype: int64" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_subset.loc[(dorsal_subset[\"CAM_Dupe\"] == True) & (dorsal_subset[\"file_type\"] == \"raw\")].duplicated(subset = \"CAMID\", keep = False).value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have multiple jpg images & multiple raw images of the same specimen. Note that this does not necessarily mean these are duplicates of the same images. There are also jpg copies provided alongside raw images." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Save Dorsal Subset to CSV" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "dorsal_subset.to_csv(\"../Jiggins_Zenodo_dorsal_Img_Master.csv\", index = False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "std", "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.11.3" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }