Skip to content

Instantly share code, notes, and snippets.

@cafuneandchill
Created September 24, 2018 19:26
Show Gist options
  • Save cafuneandchill/58003234ec29cde5447995aa90159939 to your computer and use it in GitHub Desktop.
Save cafuneandchill/58003234ec29cde5447995aa90159939 to your computer and use it in GitHub Desktop.
Myeloid Cell Recogniser
# Myeloid Lineage Immune Cell Recogniser v1.0
# Python version: Python v3.7.0
# Author: cafuneandchill
class Cell:
def __init__(self, name, markers):
self.name = name
self.markers = markers
neuph = Cell("neutrophile", {"CD13", "CD14"})
eosph = Cell("eosinophile", {"CD9", "CD35"})
basph = Cell("basophile", {"CD23", "CD11"})
mastc = Cell("mast cell", {"CD13", "CD29", "CD45", "CD117", "CD123"})
dendc = Cell("dendritic cell", {"CD80", "CD86"})
monoc = Cell("monocyte", {"CD14", "CD13", "CD86"})
macrf = Cell("macrophage", {"CD14", "CD4", "CD80", "CD86"})
print("""
▓▒░Myeloid Lineage Immune Cell Recogniser v1.0░▒▓
This program uses only CD cell surface molecules as the recognition key!
Input CD markers in the following format: CD[molecule number]
To stop the recognition at any moment, enter "quit".
________________________________________________________________________________
""")
def recognise():
"""
A main program function
which filters out cell types
by checking for whether a CD marker string is present or not
in "markers" attributes of each Cell object
"""
cellList = [ # the initial cell list
neuph,
eosph,
basph,
mastc,
dendc,
monoc,
macrf
]
n = 1 # a counter of CD markers which are being input
while True:
if len(cellList) > 1:
mark = input("Please enter a CD marker #" + str(n) + ": ")
if mark == "quit": break # a recognition stop prompt
cellListF = cellList.copy()
for cell in cellListF:
if mark in cell.markers: # this statement checks if a CD marker is present in "markers" attributes of each cell object
continue
else:
cellList.remove(cell) # if a CD marker is not present in the "markers" attribute then the cell is removed from the list
if len(cellList) == 0: # this if statement checks if an actual CD marker was given to a program
print("Sorry, this is either not a CD marker or it is not used in this program :(")
cellList = cellListF
continue
print("""Possible cell types:
""")
a = 0
while a < len(cellList): # this while cycle prints out all possible cell types at the moment (will probably turn it in a for loop)
print(" - " + cellList[a].name)
a += 1
print("\r")
n += 1
else:
print("It's a " + cellList[0].name + "!") # this prints out the final result
break
while True: # main program cycle with exit prompt
recognise()
if input("Do you want to perform another check? (y/n) ") == "y":
continue
else:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment