# Import modules that contain functions we need
import pandas as pd
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt

# Our data is the dichotomous key table and is defined as the word 'key'.
# key is set equal to the .csv file that is read by pandas.
# The .csv file must be in the same directory as the program.

#If the data is being pulled locally use the code that is commented out below
#key = pd.read_csv("Classification of Organisms- Jupyter Data.csv")
#key2 = pd.read_csv("Classification of Organisms- Jupyter Data KEY 2.csv")

key = pd.read_csv("https://gist.githubusercontent.com/GoodmanSciences/f4d51945a169ef3125234c57b878e058/raw/bebeaae8038f0b418ed37c2a98b82aa9d3cc38d1/Classification%2520of%2520Organisms-Jupyter%2520Data.csv")

key2 = pd.read_csv("https://gist.githubusercontent.com/GoodmanSciences/4060d993635e90cdcc46fe637c92ee37/raw/d9031747855b9762b239dea07a60254eaa6051f7/Classification%2520of%2520Organisms-%2520Jupyter%2520Data%2520KEY%25202.csv")

# This sets Organism as the index instead of numbers
#key = data.set_index("organism")

"""
Explanation: Classification of Organisms
Using a Digital Dichotomous Key
Step 1 - Creating a Checkpoint

Create a checkpoint by clicking <b>File</b> ==> <b>Save and Checkpoint</b>. If you make a major mistake, you can click <u>File</u> ==> <u>Revert to Checkpoint</u> to reset the Jupyter Notebook online on Binder.org.

Importing the Data

The next 2 blocks of code imports the data that we will need to examine the caracteristics of many different organisms. You can begin to execute the cells using <b> Shift + Enter </b> to import the data set and continue.
End of explanation
"""


# Here is a helpful image of a sample Dichotomous Key!
from IPython.display import Image
from IPython.core.display import HTML 
Image(url= 'http://biology-igcse.weebly.com/uploads/1/5/0/7/15070316/8196495_orig.gif')

"""
Explanation: Pre-Questions

A Dichotomous Key is....
a tool that allows scienctists to identify and classify organisms in the natural world.  Based on their characterists, scienctists can narrow down species into groups such as trees, flowers, mammals, reptiles, rocks, and fish. A Dichotomous Key can help to understand how scientists have classified organisms using Bionomial Nomenclature.
<b><span style="color:green">You can find out more about Dichotomous Keys by watching this video.</span></b> Dichotomous Key Video 

Pre-Questions
1.After watching the video and reading, what is a dichotomous key and why is it useful for scientists who study organisms.
2.Why do scientists classify organisms? How does this help with research?
End of explanation
"""


# Animal options in Dichotomous Key
# Displays all row titles as an array
key.organism

# Conditions/Questions for finding the correct animal
# Displays all column titles as an array
key.columns

"""
Explanation: PART 1: Sorting Organisms by One Characteristic

We will be looking at the characterists of 75 unique organisms in our Dichotomous Key.  The imput below will provide us with a some of the possible organisms you may discover and the different Organism Characteristics/Conditions in our data set.
End of explanation
"""


key[(key['fur'] == 'yes')]

"""
Explanation: Use and modify the section of code below to answer questions 3-5.
End of explanation
"""


# This conditional allows us to query a column and if the data within that cell matches it will display the animal(s).
#if you are unsure of what to put try making that column a comment by adding # in front of it.

key[
#physical characteristics
    (key['fur'] == 'yes') & \
    (key['feathers'] == 'no') & \
    (key['poisonous'] == 'no') & \
    (key['scales'] == 'no') & \
    (key['multicellular'] == 'yes') & \
    (key['fins'] == 'no') & \
    (key['wings'] == 'no') & \
    (key['vertebrate'] == 'yes') & \
    
#environmental characteristics
    (key['marine'] == 'no') & \
    (key['terrestrial'] == 'yes') & \
    
#feeding characteristics
    
    #decomposers get their food by breaking down decaying organisms
    (key['decomposer'] == 'no') & \
    
    #carnivores get their food by eating animals
    (key['carnivore'] == 'no') & \
    
    #herbivores get their food by eating plants
    (key['herbivore'] == 'yes') & \
    
    #omnivores get their food by eating both plants and animals
    (key['omnivore'] == 'no') & \
    
    #photosynthesis is the process of making food using energy from sunlight
    (key['photosynthesis'] == 'no') & \
    
    #autotrophs are organisms that generate their own food inside themselves
    (key['autotroph'] == 'no') & \
    
#possible kingdoms include: animalia, plantae, fungi
    (key['kingdom'] == 'animalia') & \
   
#cell type     
    (key['eukaryotic'] == 'yes') & \
    (key['prokaryotic'] == 'no')
    ]

"""
Explanation: PART 1: Sorting Organisms by One Characteristic
3.Organisms are classified by shared characteristics.  Is it possible for something to be eukaryotic and prokaryotic at the same time?  Why might this kind of trait be helpful for scientists?
4.How many different organisms in our list of 75 have wings?  Are they all similar?  Are “wings” a good characteristic to use for classification?
5.Which characteristic gave you the largest category?  Which gave you the smallest?  Why might this be the case?
PART 2: Sorting Organisms by Many Characteristics

These are the conditions or the characteristics in which ceratin answers are categorized for certain organisms. Each characteristic/condition has a yes/no except for the Kingdoms. Change the conditionals in the code below to change what organism(s) are displayed. For most, the only change needs to be the 'yes' or 'no'.

<span style="color:red">Capitalization matters so be careful. You also must put in only allowed answers in every condition or the code will break!</span>

Use and modify the section of code below to answer questions 6-8 in your coding booklet.
End of explanation
"""


#sort your organisms by their taxonomical classification

# This conditional allows us to query a column and if the data within that cell matches,
# it will display the corresponding animal(s)
key2[(key2['kingdom'] == 'animalia')]


"""
Explanation: PART 2: Sorting Organisms by Many Characteristics
6.Set the list to the characteristics of a cow.  What are some other organisms that are sorted this way?  What new traits would make the cow the only result?
7.How would the list of characteristics differ between a whale and dolphin?  
8.A zoologist is exploring the jungle when she spots a small, hairy animal.  As she follows the animal she sees it eat nuts from a tree and some insects off the ground.  She also observes that even though it appears to have wings, it seems to prefer to move along the ground.  According to your key, what organism is it most similar to, how do the observed characteristics differ from what you know about this animal?
Part 3 & 4: Scientific Classification of Organisms & Unstructured Coding

Use and modify the section of code below to answer questions 9-13 in your coding booklet.
End of explanation
"""


#Done?? Insert a image for one of the organisms you found using the dichotomous key.
from IPython.display import Image
from IPython.core.display import HTML 
Image(url= 'https://lms.mrc.ac.uk/wp-content/uploads/insert-pretty-picture-here1.jpg')

"""
Explanation: PART 3: Scientific Classification of Organisms
9.Are all organisms in the same kingdom classified in the same phylum?
10.If organisms are in the same order (like rodentia), describe how their kingdom, phylum, and classes compare.  Explain. 
PART 4: Unstructured Coding
11.What are two examples of organisms in kingdom plantae?
12.What are two examples of organisms in kingdom fungi?
13.Find a few poisonous animals by changing the conditional statements.
End of explanation
"""


