adicion de mbiota a cobertura por protocolo y resultados

aunque no se recolentan mediante la info de visitas, se agregaron los resultados
disponibles de mbiota a éstas para poder mostrarlas en la misma gráfica, ya que
así tiene mucho más sentido que mostrarlas por separado (la muestra para la
mbiota se recolecta en las visitas, de hecho)
parent 0fc31d16
...@@ -28,9 +28,16 @@ def get_secuenciaciones_data(visitnumber=1): ...@@ -28,9 +28,16 @@ def get_secuenciaciones_data(visitnumber=1):
numero_de = secuenciaciones["patient_id"].unique().size numero_de = secuenciaciones["patient_id"].unique().size
return numero_de return numero_de
def get_secuenciaciones_data_v2(visitnumber=1):
secuenciaciones = pd.read_json(f'{url}/microbiota/1/organisms-quantification/{visitnumber}')
presentes = secuenciaciones["patient_id"].unique().astype(int)
resultados = pd.DataFrame(index = presentes , data = [1] * presentes.size, columns = ["mbiota"])
return resultados.sort_index()
server = flask.Flask(__name__) server = flask.Flask(__name__)
# algunos parámetros globales # algunos parámetros globales
url = 'https://nutricion.c3.unam.mx/nd/' url = 'https://nutricion.c3.unam.mx/nd/'
...@@ -331,6 +338,12 @@ def update_por_protocolo(visita): ...@@ -331,6 +338,12 @@ def update_por_protocolo(visita):
if lcol > 3: if lcol > 3:
lcol = 1 lcol = 1
lrow = lrow + 1 lrow = lrow + 1
mbiota = get_secuenciaciones_data_v2(visita)
mbiota_pct = math.floor( 100 * len(mbiota) / len(df1))
figura.add_trace(
go.Bar(x=["mbiota"], y=[mbiota_pct], textposition='auto', text= mbiota_pct),
col = lcol, row = lrow,
)
figura.update_layout(showlegend=False) figura.update_layout(showlegend=False)
figura.update_traces(texttemplate='%{text:.2s}', textposition='auto') figura.update_traces(texttemplate='%{text:.2s}', textposition='auto')
return figura return figura
...@@ -343,6 +356,7 @@ def update_por_prueba(visita): ...@@ -343,6 +356,7 @@ def update_por_prueba(visita):
lcol = 1 lcol = 1
lrow = 1 lrow = 1
df1 = visitas_datos[visita-1] df1 = visitas_datos[visita-1]
microbiota = get_secuenciaciones_data_v2(1)
protocolos = { protocolos = {
"pyhsiological" : ["pas", "pad", "ipaq", "stress", "hadsa", "hadsd"], "pyhsiological" : ["pas", "pad", "ipaq", "stress", "hadsa", "hadsd"],
"tolerance_curves" : ["Pan", "Gelatina", "Glucosa"], "tolerance_curves" : ["Pan", "Gelatina", "Glucosa"],
...@@ -351,11 +365,15 @@ def update_por_prueba(visita): ...@@ -351,11 +365,15 @@ def update_por_prueba(visita):
"antropometric" : ["imc", "weight", "waist_circumference"] "antropometric" : ["imc", "weight", "waist_circumference"]
} }
heatmap = df1.set_index("id").notna().astype(int) heatmap = df1.set_index("id").notna().astype(int)
microbiota = microbiota.loc[list(set(heatmap.index).intersection(microbiota.index))]
heatmap = pd.concat([heatmap, microbiota], axis=1)
heatmap.fillna(0, inplace=True)
colorscale = [[0, 'gold'], [1,'mediumturquoise']] colorscale = [[0, 'gold'], [1,'mediumturquoise']]
columnas = [] columnas = []
for protocolo in protocolos.keys(): for protocolo in protocolos.keys():
prot_columns = list(set(df1.columns).intersection(set(protocolos[protocolo]))) prot_columns = list(set(df1.columns).intersection(set(protocolos[protocolo])))
columnas.extend(prot_columns) columnas.extend(prot_columns)
columnas.append("mbiota")
figura = px.imshow(heatmap[columnas], color_continuous_scale=colorscale) figura = px.imshow(heatmap[columnas], color_continuous_scale=colorscale)
return figura return figura
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment