{"cells":[{"metadata":{},"cell_type":"markdown","source":"![](https://labblog.uofmhealth.org/sites/lab/files/2018-05/Michigan-med-l-ipf-01.jpg)\n<h1><center>👨🏻‍⚕️OSIC Pulmonary Fibrosis Progression:EDA</center></h1>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"# Pulmonary Fibrosis\nPulmonary fibrosis is a condition that causes lung scarring and stiffness. This makes it difficult to breathe. It can prevent your body from getting enough oxygen and may eventually lead to respiratory failure, heart failure, or other complications.\n\nResearchers currently believe that a combination of exposure to lung irritants like certain chemicals, smoking, and infections, along with genetics and immune system activity, play key roles in pulmonary fibrosis.\n\nIt was once thought that the condition was caused by inflammation. Now scientists believe that there is an abnormal healing process in the lungs that leads to scarring. The formation of significant lung scarring eventually becomes pulmonary fibrosis.\n\n\n## What are the symptoms of pulmonary fibrosis?\nYou may have pulmonary fibrosis for some time without any symptoms. Shortness of breath is typically the first symptom that develops.\n\n## Other symptoms can include:\n\n- dry, hacking cough that’s chronic (long term)\n- weakness\n- fatigue\n- curving of the fingernails, which is called clubbing\n- weight loss\n- chest discomfort\nSince the condition generally affects older adults, early symptoms are often misattributed to age or a lack of exercise.\n\nYour symptoms may seem minor at first and progress over time. The symptoms can vary from one person to another. Some people with pulmonary fibrosis become ill very quickly.\n\n## What causes pulmonary fibrosis?\nThe causes of pulmonary fibrosis can be divided into several categories:\n\n- autoimmune diseases\n- infections\n- environmental exposure\n- medications\n- idiopathic (unknown)\n-genetics\nAutoimmune diseases\nAutoimmune diseases cause your body’s immune system to attack itself. Autoimmune conditions that can lead to pulmonary fibrosis include:\n\n- rheumatoid arthritis\n- lupus erythematosus, which is commonly known as lupus\n- scleroderma\n- polymyositis\n- dermatomyositis\n- vasculitis\n- Infections\n\n### The following types of infections may cause pulmonary fibrosis:\n\n- bacterial infections\n- virual infections, resulting from hepatitis C, adenovirus, herpes virus, and other viruses\n- Environmental exposure\n- Exposure to things in the environment or workplace can also contribute to pulmonary fibrosis. For example, cigarette smoke contains many chemicals that can damage your lungs and lead to this condition.\n\n### Other things that can damage your lungs include:\n\n- asbestos fibers\n- grain dust\n- silica dust\n- certain gases\n- radiation\n- Medications\nSome medications may also raise your risk of developing pulmonary fibrosis. If you take one of these medications on a regular basis, you may require close monitoring by your doctor.\n\nchemotherapy drugs, such as cyclophosphamide\nantibiotics, such as nitrofurantoin (Macrobid) and sulfasalazine (Azulfidine)\ncardiac drugs, such as amiodarone (Nexterone)\nbiologic medications such as adalimumab (Humira) or etanercept (Enbrel)\nIdiopathic\nIn many cases, the exact cause of pulmonary fibrosis in unknown. When this is the case, the condition is called idiopathic pulmonary fibrosis (IPF).\n\nAccording to the American Lung Association, most people with pulmonary fibrosis have IPF.\n\nGenetics\nAccording to the Pulmonary Fibrosis Foundation, about 3 to 20 percent of people with IPF have another family member with pulmonary fibrosis. In these cases, it’s known as familial pulmonary fibrosis or familial interstitial pneumonia.\n\nResearchers have linked some genes to the condition, and research about what role genetics plays is ongoing.\n\n## Who is at risk of pulmonary fibrosis?\nYou’re more likely to be diagnosed with pulmonary fibrosis if you:\n\n- are male\n- are between the ages of 40 and 70\n- have a history of smoking\n- have a family history of the condition\n- have an autoimmune disorder associated with the condition\n- have taken certain medications associated with the disease\n- have undergone cancer treatments, particularly chest radiation\n- work in an occupation associated with increased risk, such as mining, farming, or construction\n\n## How is pulmonary fibrosis diagnosed?\nPulmonary fibrosis is one of more than 200 types of lung diseases that exist. Because there are so many different types of lung diseases, your doctor may have difficulty identifying that pulmonary fibrosis is the cause of your symptoms.\n\nIn a survey by the Pulmonary Fibrosis Foundation, 55 percent of respondents reported being misdiagnosed at some point. The most common misdiagnoses were asthma, pneumonia, and bronchitis.\n\nUsing the most current guidelines, it’s estimated that 2 in 3 patients with pulmonary fibrosis can now be properly diagnosed without a biopsy.\n\nBy combining your clinical information and the results of a specific kind of CT scan of the chest, your doctor will be more likely to accurately diagnose you.\n\nIn cases when the diagnosis is unclear, a tissue sample, or biopsy, may be necessary.\n\nThere are several methods for performing a surgical lung biopsy, so your doctor will recommend which procedure is best for you.\n\nYour doctor may also use a variety of other tools to diagnose pulmonary fibrosis or rule out other conditions. These may include:\n\npulse oximetry, a noninvasive test of your blood oxygen levels\nblood tests to look for autoimmune diseases, infections, and anemia\nan arterial blood gas test to more accurately assess the oxygen levels in your blood\na sputum sample to check for signs of infection\na pulmonary function test to measure your lung capacity\nan echocardiogram or cardiac stress test to see if a heart problem is causing your symptoms\n\n## How is pulmonary fibrosis treated?\nYour doctor can’t reverse the lung scarring, but they can prescribe treatments to help improve your breathing and to slow the progression of the disease.\n\nThe treatments below are some examples of current options used for managing pulmonary fibrosis:\n\nsupplemental oxygen\nprednisone to suppress your immune system and reduce inflammation\nazathioprine (Imuran) or mycophenolate (CellCept) to suppress your immune system\npirfenidone (Esbriet) or nintedanib (Ofev), antifibrotic drugs that block the scarring process in the lungs\nYour doctor may also recommend pulmonary rehabilitation. This treatment involves a program of exercise, education, and support to help you learn how to breathe more easily.\n\nYour doctor may also encourage you to make changes to your lifestyle. These changes may include the following:\n\nYou should avoid secondhand smoke and take steps to quit if you smoke. This can help slow the disease’s progression and ease your breathing.\nEat a well-balanced diet.\nFollow an exercise plan developed with your doctor’s guidance.\nGet adequate rest and avoid excess stress.\nA lung transplant may be recommended for those under the age of 65 with severe disease.\n\n## What is the outlook for people with pulmonary fibrosis?\nThe rate at which pulmonary fibrosis scars people’s lungs varies. The scarring isn’t reversible, but your doctor can recommend treatments to reduce the rate at which your condition progresses.\n\nThe condition can cause a number of complications, including respiratory failure. This happens when your lungs no longer work properly and they can’t get enough oxygen to your blood.\n\nPulmonary fibrosis also raises your risk of lung cancer.\n\n## Tips for prevention\nSome cases of pulmonary fibrosis may not be preventable. Other cases are linked to environmental and behavioral risk factors that can be controlled. Follow these tips to lower your risk of getting the disease:\n\n- Avoid smoking.\n- Avoid secondhand smoke.\n- Wear a face mask or other breathing device if you work in an environment with harmful chemicals.\n- If you’re having trouble breathing, make an appointment with your doctor. - Early diagnosis and treatment can improve the long-term outlook for people with many lung diseases, including pulmonary fibrosis.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<iframe width=\"813\" height=\"457\" src=\"https://www.youtube.com/embed/QdwuHKwOLRU\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport os\nimport plotly.express as px\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport pandas_profiling \nfrom pandas_profiling import ProfileReport ","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"# Loading the train.csv data file","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train=pd.read_csv(\"../input/osic-pulmonary-fibrosis-progression/train.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ProfileReport(df_train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#df_train['Age'].hist()\n#import seaborn as sns\nage=df_train['Age']\nage=pd.Series(age,name=\"Age\")\nax=sns.distplot(age)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train['Sex'].hist()\n#A big percentage of people in this df are males as males are at higher risks as compared to women","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train['SmokingStatus'].hist()\n#A big percentage of people in this df are ex smoker and never smoked are also at risk","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.isnull().sum()\n#Train is complete with all details","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Let's see what we have here in test csv ","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"df_test=pd.read_csv(\"../input/osic-pulmonary-fibrosis-progression/test.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ProfileReport(df_test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_test.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_test.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_test.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_test.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"age=df_test['Age']\nage=pd.Series(age,name=\"Age\")\nax=sns.distplot(age)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_test['Sex'].hist()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_test['SmokingStatus'].hist()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Let's see what we have here in samplesubmission.csv","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"#Let's see what sample submission looks like \nsub=pd.read_csv(\"../input/osic-pulmonary-fibrosis-progression/sample_submission.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ProfileReport(sub)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.info","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.describe","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# What is DICOM?\nDICOM stands for Digital Imaging and COmmunications in Medicine:\n    it is an international standard related to the exchange,\n    storage and communication of digital medical images and\n    other related digital data.\n\nThe DICOM standard covers both the formats to be used for storage\nof digital medical images and related digital data, and the protocols\nto be adopted to implement several communication services which are \nuseful in the medical imaging workflow.\n\nDICOM was born back in year 1993 by initiative of the American College\nof Radiology (ACR) and of the National Electrical Manufacturers Association\n(NEMA). It is often referred to as “DICOM 3.0”, as it is an evolution of the\nprevious ACR-NEMA 2.0 standard.\n\nThe main purpose of the DICOM standard is to allow cross-vendor interoperability among devices and information systems dealing with digital medical images, as long as all the involved actors comply with the DICOM standard: thanks to DICOM, a CT equipment of vendor “A” shall be able to send an exam to a digital archive of vendor “B”, or a diagnostic workstation of vendor “C” shall be able to query and retrieve information from a server of vendor “D”, etc.\n\n\nDICOM has become the de-facto standard in medical imaging: today, the vast majority of digital medical imaging systems of all major vendors (including acquisition devices, diagnostic workstations, archives, servers, medical printers, etc.) support and comply with portions of the DICOM standard, depending on the services they implement. Also, DICOM has been widely accepted and adopted by medical institutions, including public and private hospitals, diagnostic centers and analysis laboratories of different sizes.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"#Import pydicom\n#Pydicom is a python package specifically for parsing .dcm files\nimport pydicom\nfrom pydicom.data import get_testdata_files\npreview=\"../input/osic-pulmonary-fibrosis-progression/train/ID00007637202177411956430/10.dcm\"\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"metadata=pydicom.dcmread(preview)\nmetadata","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PixelDims = (int(metadata.Rows), int(metadata.Columns), len(preview))\nprint(PixelDims)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"Patient id....................:\", metadata.PatientID)\nprint(\"Modality......................:\", metadata.Modality)\nprint(\"BodyPartExamined..............:\", metadata.BodyPartExamined)  \nprint(\"Image Position    (Patient)...:\", metadata.ImagePositionPatient)\nprint(\"Image Orientation (Patient)...:\", metadata.ImageOrientationPatient)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.imshow(metadata.pixel_array, cmap=plt.cm.bone)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"patient = df_train[df_train.Patient == 'ID00007637202177411956430']\npatient","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Let's see how fvc change over weeks\npatient.plot(kind='line',x='Weeks',y='FVC',color='red')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"patient.plot(kind='line',x='Weeks',y='Percent', color='c')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Credits:\n- I took the definition from here:[Healthline Website](http://www.healthline.com/health/pulmonary-fibrosis)","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}