Merge branch 'main' into pages
merging EudraVigilance into pages branch
This commit is contained in:
@@ -441,16 +441,16 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3e47c62c",
|
||||
"id": "6c302a04",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Symptoms caused by Vaccines\n"
|
||||
"# Symptoms caused by Drugs (EudraVigilance)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "5cd9935f",
|
||||
"id": "fb02ce7c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -460,12 +460,112 @@
|
||||
"from SymptomsCausedByVaccines.PrrSeriesTransformer import PrrSeriesTransformer\n",
|
||||
"from SymptomsCausedByVaccines.ProportionalReportingRatiosPersister import saveProportionalReportingRatios\n",
|
||||
"import os\n",
|
||||
"import pandas as pd"
|
||||
"import pandas as pd\n",
|
||||
"import gc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f38924ec",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def saveProportionalReportingRatios4PrrByVaccineBySymptomWithoutZeroPrrs(prrByVaccineAndSymptom, webAppBaseDir):\n",
|
||||
" prrByVaccineBySymptom = PrrSeriesFactory.getPrrByVaccineBySymptom(prrByVaccineAndSymptom)\n",
|
||||
"\n",
|
||||
" prrByVaccineBySymptomWithoutZeroPrrs = PrrSeriesTransformer.filterByNonZeroPrrs(prrByVaccineBySymptom)\n",
|
||||
" del prrByVaccineBySymptom\n",
|
||||
" gc.collect()\n",
|
||||
"\n",
|
||||
" filenameBySymptom = saveProportionalReportingRatios(\n",
|
||||
" prrByVaccineBySymptomWithoutZeroPrrs,\n",
|
||||
" directory = os.path.normpath(webAppBaseDir + '/data/ProportionalReportingRatios/symptoms'))\n",
|
||||
"\n",
|
||||
" del prrByVaccineBySymptomWithoutZeroPrrs\n",
|
||||
" gc.collect()\n",
|
||||
" return filenameBySymptom"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e1237c0b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def saveProportionalReportingRatios4PrrBySymptomByVaccineWithHighPrrs(prrByVaccineAndSymptom, webAppBaseDir):\n",
|
||||
" prrBySymptomByVaccine = PrrSeriesFactory.getPrrBySymptomByVaccine(prrByVaccineAndSymptom)\n",
|
||||
" prrBySymptomByVaccineWithHighPrrs = PrrSeriesTransformer.filterPrrs(prrBySymptomByVaccine, lambda prr: prr >= 2)\n",
|
||||
" del prrBySymptomByVaccine\n",
|
||||
" gc.collect()\n",
|
||||
"\n",
|
||||
" filenameByDrug = saveProportionalReportingRatios(\n",
|
||||
" prrBySymptomByVaccineWithHighPrrs,\n",
|
||||
" directory = os.path.normpath(webAppBaseDir + '/data/ProportionalReportingRatios/vaccines'))\n",
|
||||
"\n",
|
||||
" del prrBySymptomByVaccineWithHighPrrs\n",
|
||||
" gc.collect()\n",
|
||||
" return filenameByDrug"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "64ccf3c9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def saveProportionalReportingRatiosAndUpdateHtmlFile(prrByVaccineAndSymptom, webAppBaseDir):\n",
|
||||
" prrByVaccineAndSymptom = DataFrameFilter.withoutZeroRowsAndZeroColumns(prrByVaccineAndSymptom)\n",
|
||||
" filenameBySymptom = saveProportionalReportingRatios4PrrByVaccineBySymptomWithoutZeroPrrs(prrByVaccineAndSymptom, webAppBaseDir)\n",
|
||||
" filenameByDrug = saveProportionalReportingRatios4PrrBySymptomByVaccineWithHighPrrs(prrByVaccineAndSymptom, webAppBaseDir)\n",
|
||||
" updateHtmlFile(\n",
|
||||
" symptomsDescr = {\n",
|
||||
" 'symptoms': list(prrByVaccineAndSymptom.columns),\n",
|
||||
" 'filenameBySymptom': filenameBySymptom },\n",
|
||||
" vaccinesDescr = {\n",
|
||||
" 'vaccines': list(prrByVaccineAndSymptom.index),\n",
|
||||
" 'filenameByDrug': filenameByDrug },\n",
|
||||
" htmlFile = os.path.normpath(webAppBaseDir + '/index.html'))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "cc2cf05f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"os.system('cd data; 7z x -y prrByDrugAndSymptom-EudraVigilance.7z')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "3db1a115",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"saveProportionalReportingRatiosAndUpdateHtmlFile(\n",
|
||||
" prrByVaccineAndSymptom = pd.read_csv(\n",
|
||||
" 'data/prrByDrugAndSymptom-EudraVigilance.csv',\n",
|
||||
" index_col = 'DRUG'),\n",
|
||||
" webAppBaseDir = os.getcwd() + '/../docs/SymptomsCausedByDrugs')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3e47c62c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Symptoms caused by Vaccines\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0974c307",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -480,101 +580,13 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "dfa98cd9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prrByVaccineAndSymptom = DataFrameFilter.withoutZeroRowsAndZeroColumns(prrByVaccineAndSymptom)\n",
|
||||
"prrByVaccineAndSymptom"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "640868c7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prrByVaccineBySymptom = PrrSeriesFactory.getPrrByVaccineBySymptom(prrByVaccineAndSymptom)\n",
|
||||
"prrByVaccineBySymptom"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0f247c64",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prrBySymptomByVaccine = PrrSeriesFactory.getPrrBySymptomByVaccine(prrByVaccineAndSymptom)\n",
|
||||
"prrBySymptomByVaccine"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "760ac423",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prrByVaccineBySymptomWithoutZeroPrrs = PrrSeriesTransformer.filterByNonZeroPrrs(prrByVaccineBySymptom)\n",
|
||||
"prrByVaccineBySymptomWithoutZeroPrrs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f07203e4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prrBySymptomByVaccineWithHighPrrs = PrrSeriesTransformer.filterPrrs(prrBySymptomByVaccine, lambda prr: prr >= 2)\n",
|
||||
"prrBySymptomByVaccineWithHighPrrs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"webAppBaseDir = os.getcwd() + '/../docs/SymptomsCausedByVaccines'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0b40071c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"saveProportionalReportingRatios(\n",
|
||||
" prrByVaccineBySymptomWithoutZeroPrrs,\n",
|
||||
" directory = os.path.normpath(webAppBaseDir + '/data/ProportionalReportingRatios/symptoms'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "fac4b34f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"saveProportionalReportingRatios(\n",
|
||||
" prrBySymptomByVaccineWithHighPrrs,\n",
|
||||
" directory = os.path.normpath(webAppBaseDir + '/data/ProportionalReportingRatios/vaccines'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "803dfbef",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"updateHtmlFile(\n",
|
||||
" symptoms = list(prrByVaccineAndSymptom.columns),\n",
|
||||
" vaccines = list(prrByVaccineAndSymptom.index),\n",
|
||||
" htmlFile = os.path.normpath(webAppBaseDir + '/index.html'))"
|
||||
"saveProportionalReportingRatiosAndUpdateHtmlFile(\n",
|
||||
" prrByVaccineAndSymptom = prrByVaccineAndSymptom,\n",
|
||||
" webAppBaseDir = os.getcwd() + '/../docs/SymptomsCausedByVaccines')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -5,14 +5,19 @@ from SymptomsCausedByVaccines.HtmlUtils import getSymptomOptions, getVaccineOpti
|
||||
from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
|
||||
|
||||
|
||||
def updateHtmlFile(symptoms, vaccines, htmlFile, defaultSelectVaccineOptionText = 'Select Vaccine'):
|
||||
def updateHtmlFile(symptomsDescr, vaccinesDescr, htmlFile, defaultSelectVaccineOptionText = 'Select Vaccine'):
|
||||
_saveOptions(
|
||||
options = getSymptomOptions(symptoms),
|
||||
options = getSymptomOptions(
|
||||
symptoms = symptomsDescr['symptoms'],
|
||||
filenameBySymptom = symptomsDescr['filenameBySymptom']),
|
||||
htmlFile = htmlFile,
|
||||
selectElementId = 'symptomSelect')
|
||||
|
||||
_saveOptions(
|
||||
options = getVaccineOptions(vaccines, defaultSelectVaccineOptionText),
|
||||
options = getVaccineOptions(
|
||||
vaccines = vaccinesDescr['vaccines'],
|
||||
filenameByDrug = vaccinesDescr['filenameByDrug'],
|
||||
defaultOptionText = defaultSelectVaccineOptionText),
|
||||
htmlFile = htmlFile,
|
||||
selectElementId = 'vaccineSelect')
|
||||
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
def getVaccineOptions(vaccines, defaultOptionText):
|
||||
return _getOptionsWithDefaultOption(defaultOptionText = defaultOptionText, values = vaccines)
|
||||
import html
|
||||
|
||||
def getVaccineOptions(vaccines, filenameByDrug, defaultOptionText):
|
||||
return _getOptionsWithDefaultOption(
|
||||
defaultOptionText = defaultOptionText,
|
||||
values = vaccines,
|
||||
filenameByValue = filenameByDrug)
|
||||
|
||||
|
||||
def getSymptomOptions(symptoms):
|
||||
return _getOptionsWithDefaultOption(defaultOptionText = 'Select Symptom', values = symptoms)
|
||||
def getSymptomOptions(symptoms, filenameBySymptom):
|
||||
return _getOptionsWithDefaultOption(
|
||||
defaultOptionText = 'Select Symptom',
|
||||
values = symptoms,
|
||||
filenameByValue = filenameBySymptom)
|
||||
|
||||
|
||||
def _getOptionsWithDefaultOption(defaultOptionText, values):
|
||||
return ['<option hidden disabled selected value>{defaultOptionText}</option>'.format(defaultOptionText = defaultOptionText)] + _getOptions(values)
|
||||
def _getOptionsWithDefaultOption(defaultOptionText, values, filenameByValue):
|
||||
return ['<option hidden disabled selected value>{defaultOptionText}</option>'.format(defaultOptionText = defaultOptionText)] + _getOptions(values, filenameByValue)
|
||||
|
||||
|
||||
def _getOptions(values):
|
||||
return [_getOption(value) for value in values]
|
||||
def _getOptions(values, filenameByValue):
|
||||
return [_getOption(filename = filenameByValue[value], displayValue = value) for value in values]
|
||||
|
||||
|
||||
def _getOption(value):
|
||||
return '<option value="{value}">{value}</option>'.format(value=value)
|
||||
def _getOption(filename, displayValue):
|
||||
return '<option value="{value}">{displayValue}</option>'.format(
|
||||
value = filename,
|
||||
displayValue = html.escape(str(displayValue)))
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import shutil
|
||||
from IOUtils import IOUtils
|
||||
|
||||
def saveProportionalReportingRatios(prrByVaccineBySymptom, directory):
|
||||
def saveProportionalReportingRatios(prrBySymptomByDrug, directory):
|
||||
shutil.rmtree(directory, ignore_errors = True)
|
||||
for symptom, prrByVaccine in prrByVaccineBySymptom.items():
|
||||
IOUtils.saveDictAsJson(prrByVaccine, f'{directory}/{symptom}.json')
|
||||
filenameByDrug = {}
|
||||
i = 0
|
||||
for drug, prrBySymptom in prrBySymptomByDrug.items():
|
||||
i += 1
|
||||
filenameByDrug[drug] = f'{i}'
|
||||
IOUtils.saveDictAsJson(prrBySymptom, f'{directory}/{i}.json')
|
||||
return filenameByDrug
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import unittest
|
||||
from pandas.testing import assert_series_equal
|
||||
from TestHelper import TestHelper
|
||||
import pandas as pd
|
||||
import simplejson as json
|
||||
from SymptomsCausedByVaccines.ProportionalReportingRatiosPersister import saveProportionalReportingRatios
|
||||
|
||||
|
||||
class ProportionalReportingRatiosPersisterTest(unittest.TestCase):
|
||||
|
||||
def test_saveProportionalReportingRatios(self):
|
||||
# Given
|
||||
drug = '"GENERIC COLD ACID" '
|
||||
prrBySymptom = { 'Sepsis ': 366.3084378480811 }
|
||||
prrBySymptomByDrug = TestHelper.createSeries(
|
||||
indexName = 'DRUG',
|
||||
data = { drug: prrBySymptom })
|
||||
directory = 'src/tmp/vaccines'
|
||||
|
||||
# When
|
||||
filenameByDrug = saveProportionalReportingRatios(prrBySymptomByDrug, directory)
|
||||
|
||||
# Then
|
||||
drugFilename = '1'
|
||||
self.assertDictEqual(
|
||||
ProportionalReportingRatiosPersisterTest.readJsonFile(f'{directory}/{drugFilename}.json'),
|
||||
prrBySymptom)
|
||||
self.assertDictEqual(filenameByDrug, { drug: drugFilename })
|
||||
|
||||
@staticmethod
|
||||
def readJsonFile(file):
|
||||
with open(file) as fp:
|
||||
return json.load(fp)
|
||||
BIN
src/data/prrByDrugAndSymptom-EudraVigilance.7z
Normal file
BIN
src/data/prrByDrugAndSymptom-EudraVigilance.7z
Normal file
Binary file not shown.
Reference in New Issue
Block a user