{"cells":[{"metadata":{"trusted":true,"_uuid":"31e5d30bd25b51d0b12f94d7e95bbab5a8537fcc"},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport math\nimport seaborn as sns\nimport os\nimport matplotlib.image as mpimg","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"6ec713436638137295a3cdda5231727e0c50aff5"},"cell_type":"markdown","source":"Information from the competition:\n- the protein of interest (green) \n- nucleus (blue)\n- microtubules (red)\n- endoplasmic reticulum (yellow)\n\nLabels are:\n0.  Nucleoplasm  \n1.  Nuclear membrane   \n2.  Nucleoli   \n3.  Nucleoli fibrillar center   \n4.  Nuclear speckles   \n5.  Nuclear bodies   \n6.  Endoplasmic reticulum   \n7.  Golgi apparatus   \n8.  Peroxisomes   \n9.  Endosomes   \n10.  Lysosomes   \n11.  Intermediate filaments   \n12.  Actin filaments   \n13.  Focal adhesion sites   \n14.  Microtubules   \n15.  Microtubule ends   \n16.  Cytokinetic bridge   \n17.  Mitotic spindle   \n18.  Microtubule organizing center   \n19.  Centrosome   \n20.  Lipid droplets   \n21.  Plasma membrane   \n22.  Cell junctions   \n23.  Mitochondria   \n24.  Aggresome   \n25.  Cytosol   \n26.  Cytoplasmic bodies   \n27.  Rods & rings  "},{"metadata":{"trusted":true,"_uuid":"eb3c8a9e08d3f77f65b94362a326a9ce3b35b68f"},"cell_type":"code","source":"df_train = pd.read_csv(\"../input/train.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d66950723bad6ae90d31f3d5bbae45722ed15631"},"cell_type":"code","source":"columns = [\"00_Nucleoplasm\" ,\"01_Nuclear membrane\", \"02_Nucleoli\", \"03_Nucleoli fibrillar center\" ,\"04_Nuclear speckles\" ,\"05_Nuclear bodies\",\n\"06_Endoplasmic reticulum\",\"07_Golgi apparatus\",\"08_Peroxisomes\",\"09_Endosomes\",\"10_Lysosomes\",\"11_Intermediate filaments\" ,\"12_Actin filaments\" ,\n\"13_Focal adhesion sites\" ,\"14_Microtubules\" ,\"15_Microtubule ends\" ,\"16_Cytokinetic bridge\" ,\"17_Mitotic spindle\" ,\"18_Microtubule organizing center\" ,\n\"19_Centrosome\" ,\"20_Lipid droplets\" ,\"21_Plasma membrane\" ,\"22_Cell junctions\" ,\"23_Mitochondria\" ,\"24_Aggresome\" ,\"25_Cytosol\" ,\n\"26_Cytoplasmic bodies\" ,\"27_Rods & rings\" ]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"90c1fa6a378b8a6935d32c17efc23413af9c93b7"},"cell_type":"code","source":"for column in columns:\n    df_train[column] = np.zeros(len(df_train)) ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8a642c81f22ebb74a195ec75e43e5c1510bad58a"},"cell_type":"code","source":"for row in range(0,len(df_train.Target)):\n    for number in df_train.Target[row].split():\n        df_train.iloc[row,int(number)+2]=1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"30b34ffd9535d79b438b6b39b7032e43bbfe262a"},"cell_type":"code","source":"df_train[\"amount\"] = [len(row.split()) for row in df_train.Target]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8351b9b6ce2acbff1bfa4245f6e1bf745a7d3613"},"cell_type":"code","source":"df_train.amount.hist()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8da714b9725ac1d299bd93addefca1769eae406e"},"cell_type":"code","source":"df_analysis = pd.DataFrame([(sum(df_train.loc[:,column])) for column in columns])\ndf_analysis.columns = [\"count\"]\ndf_analysis[\"log10_count\"] = [math.log((sum(df_train.loc[:,column])),10) for column in columns]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4bb0bbb96f0d7abe40785a896231702de0157066"},"cell_type":"code","source":"df_analysis.sort_values(by=\"count\", ascending=False).plot(kind=\"bar\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ba9f35b94001d28b54c8657a0a49a55713732769"},"cell_type":"code","source":"sum((df_train.loc[:,\"06_Endoplasmic reticulum\"] ==1) & (df_train.loc[:,\"16_Cytokinetic bridge\"] ==1))","execution_count":null,"outputs":[]},{"metadata":{"scrolled":false,"trusted":true,"_uuid":"36366ae95e21c008543b4cf1f01159165789651d"},"cell_type":"code","source":"sns.heatmap(df_train.loc[:,columns].corr(),cmap = \"Paired\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"23087d67c15638ed17ae23c91eba6e0caa8bd819"},"cell_type":"markdown","source":"### Image visualization"},{"metadata":{"trusted":true,"_uuid":"3d6c4e851d2c577fc4c0b7ddc0b582fc3f8e35eb"},"cell_type":"code","source":"image_folder = \"../input/train\"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8963bde74358896aa89c202cd7800e11c61fa999"},"cell_type":"code","source":"images = os.listdir(image_folder)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b28786d434621a8c12c867108af22355b589e0de"},"cell_type":"code","source":"images[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7f6622b8d27d97e769cfc9b08dbd2f292eca1286"},"cell_type":"code","source":"picture = mpimg.imread(image_folder+\"/\"+images[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0f44833241203f647d25487c109bd5d79453bbc3"},"cell_type":"code","source":"print(picture.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c6677f6673187d9bbde86ee6c8f55d5243e1203a"},"cell_type":"code","source":"colormaps = {1:\"Blues\", 2:\"Greens\",3:\"Reds\",4:\"Oranges\"}","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"25fd3ebdef574c6b9c6c31241d505bfef760e771"},"cell_type":"code","source":"fig = plt.figure(figsize=(10,10))\ncolumns = 2\nrows = 2\n\nfor i in range(1, 5):\n    img = mpimg.imread(image_folder+\"/\"+images[i-1])\n    a = fig.add_subplot(columns, rows, i)\n    a.set_title(images[i-1][-8:-4])\n    plt.imshow(img, cmap=colormaps[i])\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4ac90df75aa8fd88d50513b7b0a6337a83c0bb2d"},"cell_type":"code","source":"df_train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4d289e444156095fbfe3fc2d2d13cf77f3990184"},"cell_type":"code","source":"for row in df_train.Id:\n    df_train.loc[\"blue\"] = mpimg.imread(image_folder+\"/\"+row+\"_blue.png\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"dfbed60317d0388a36c9e64aa452d22c8350b0a9"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"6736f28505f241822f1e989177bbfe0b7ec05f00"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"6b1892d6312b606bc967d6e233a6c3c765b0e6f0"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"83674d856ac2275dfa58dd1650848083470b13e1"},"cell_type":"markdown","source":"## Tensorflow from here on"},{"metadata":{"trusted":false,"_uuid":"2b6528f49ce6dcd7db8fe1e4ecb939415c8a5cc4"},"cell_type":"code","source":"import tensorflow as tf","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"6b4305afbb5e810dff59b55c32a695acd6420a46"},"cell_type":"code","source":"sess = tf.InteractiveSession()","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"c2ba270be7c15a6a91546b2f0ad9195800a18f0e"},"cell_type":"code","source":"image = tf.image.decode_png(tf.read_file(image_folder+\"/\"+images[0]), channels=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"c83f227b82792d5ee52c012d52e77ae4388ed25a"},"cell_type":"code","source":"print(sess.run(image))","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"b91b56c2fa37492f0cec6cc47958de78c01df405"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}