Skip to content

Commit

Permalink
#52 repalce expected area by concentration
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Jul 23, 2024
1 parent 4639207 commit b3e7198
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
12 changes: 6 additions & 6 deletions components/DaughterTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: MIT
-->
<!--
This component display in light version the table of metabolites of a calibration curve
of each daughter solution. It provide a input to indicate the expected area.
of each daughter solution. It provide a input to indicate the concentration.
It is used in ManageCalibCurve.async.vue
-->

Expand All @@ -27,12 +27,12 @@ const model = defineModel<{
nameFile:string,
nameMeta:string,
area:number,
expectedArea:number}[]>({ required: true });
concentration:number}[]>({ required: true });
// -- headers of the table
const headers = ref([
{ title: t('header.nameMeta'), sortable:true, key: 'nameMeta' },
{ title: t('header.area'), sortable:true, key: 'area' },
{ title: t('header.expectedArea'), sortable:true, key: 'expectedArea' },
{ title: t('header.concentration'), sortable:true, key: 'concentration' },
]);
// -- group by daughter solution
const groupBy = ref([{ sortable:true, key: 'idFile' }]);
Expand Down Expand Up @@ -89,10 +89,10 @@ function delDaughterFile(idFile: string) {
</td>
</tr>
</template>
<!-- input for expected area -->
<template #[`item.expectedArea`]="{index}">
<!-- input for concentration -->
<template #[`item.concentration`]="{index}">
<v-text-field
v-model="model[index].expectedArea"
v-model="model[index].concentration"
type="number"
variant="plain"
:rules="[(v) => v >= 0 || t('message.positiveNumber')]"
Expand Down
12 changes: 6 additions & 6 deletions components/ManageCalibCurve.async.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const rDaughterTable = ref<{
nameFile: string;
nameMeta: string;
area: number;
expectedArea: number}[]>([]);
concentration: number}[]>([]);
const rDaughterLoading = ref<boolean>(false);
/**
Expand Down Expand Up @@ -94,7 +94,7 @@ async function sendFile() {
nameFile: daughterFile.value?.name || "error",
nameMeta: r[0],
area: r[1],
expectedArea: 0,
concentration: 0,
})));
// reset file input
Expand All @@ -108,15 +108,15 @@ function createDaughterGroup() {
idFile: string;
nameMeta: string;
area: number;
expectedArea: number;
concentration: number;
}) => {
if (!acc[cur.idFile]) {
acc[cur.idFile] = [];
}
acc[cur.idFile].push({
nameMeta:cur.nameMeta,
area:cur.area,
expectedArea:cur.expectedArea
concentration:cur.concentration
});
return acc;
}, {});
Expand Down Expand Up @@ -177,7 +177,7 @@ function openCalibCurve(item: {id: string, name: string}) {
nameFile: row.name,
nameMeta: row.mol,
area: row.area,
expectedArea: row.expected,
concentration: row.concentration,
}));
// End loading
rDaughterLoading.value = false;
Expand Down Expand Up @@ -404,7 +404,7 @@ function archiveCalibCurve(item: {id: string, name: string}){
prepend-icon="mdi-water-plus"
hide-input
/>
<!-- show metabolite of daughter solution and enter area expected
<!-- show metabolite of daughter solution and enter concentration
-->
<daughter-table
v-model="rDaughterTable"
Expand Down
4 changes: 2 additions & 2 deletions db/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ CREATE TABLE daughter
id_file SERIAL REFERENCES file (id) ON DELETE CASCADE,
id_mol VARCHAR(52),
area FLOAT NOT NULL,
expected FLOAT NOT NULL,
concentration FLOAT NOT NULL,
PRIMARY KEY (id_calib_curves, id_file, id_mol)
);

Expand Down Expand Up @@ -185,7 +185,7 @@ GROUP BY calib_curves.id;

CREATE VIEW view_daughter_file AS
SELECT file.id AS id, file.name AS name,
daughter.id_mol AS mol, area, expected, id_calib_curves
daughter.id_mol AS mol, area, concentration, id_calib_curves
FROM daughter, file
WHERE daughter.id_file = file.id;

Expand Down
4 changes: 2 additions & 2 deletions server/api/AddCalibCurve.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export default defineEventHandler(async (event) => {
lPromises.push(
client.query(`
INSERT INTO daughter(
id_calib_curves, id_file, id_mol, area, expected)
id_calib_curves, id_file, id_mol, area, concentration)
VALUES (
'${idCalibCurve}',
'${idFile}',
'${metabo.nameMeta}',
'${metabo.area}',
'${metabo.expectedArea}')`
'${metabo.concentration}')`
)
);
}
Expand Down
6 changes: 3 additions & 3 deletions server/api/UpdateCalibCurve.post.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2024 Marcellino Palerme <[email protected]>
//
// SPDX-License-Identifier: MIT
// this file is used to update the expected concentration of the daughters
// this file is used to update the concentration of the daughters
// of a calibration curve

import pg from "pg";
Expand All @@ -16,10 +16,10 @@ export default defineEventHandler(async (event) => {
for(const idFile in body.daughters){
// for each metabolite of the daughter solution
for(const daughter of body.daughters[idFile]){
// update expected concentration
// update concentration
lQueryPromises.push(client.query(`
UPDATE daughter
SET expected = ${daughter.expectedArea}
SET concentration = ${daughter.concentration}
WHERE id_file = ${idFile}
AND id_mol = '${daughter.nameMeta}'
AND id_calib_curves = ${body.idCalibCurve}`
Expand Down
18 changes: 9 additions & 9 deletions server/api/extract.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ async function exportFile(addressFile: {
}

/**
* Calculate area of metabolite about calibration curves
* Calculate concentration of metabolite about calibration curves
*
* @param sample one sample
* @param lMolRatio list of ratio of metabolite associate to project
* @param indexMeta index of name of metabolite in sample
* @param indexArea index of area in sample
*/
function CalculateArea(sample: string[], lMolRatio: { [key: string]: number }, indexMeta:number, indexArea:number): string[] {
function CalculateConcentration(sample: string[], lMolRatio: { [key: string]: number }, indexMeta:number, indexArea:number): string[] {
const tempSample = sample;
// no metabolites in calibration curves associate of project
if(lMolRatio[tempSample[indexMeta]] === undefined){
return [...tempSample, "0"];
}
// calculate area
// calculate Concentration
tempSample.push((parseFloat(tempSample[indexArea]) * lMolRatio[tempSample[indexMeta]]).toString());

return tempSample;
Expand Down Expand Up @@ -105,21 +105,21 @@ export default defineEventHandler(async (event) => {
})
.then((resp: any[]) => Promise.all(resp.map((x: { json: () => any; }) => x.json())))
.then(async (resps: any) => {
// function to calculate area do nothing
// function to calculate concentration do nothing
let funcCalcul = (x: any) => x;
let temp = [resps[0].header];
const lMolRatio = await GetRatio(client, idProject);
// verify if we have calibration curves
if (Object.keys(lMolRatio).length != 0) {
// affect function to calculate area
funcCalcul = (x: any) => CalculateArea(x,
// affect function to calculate concentration
funcCalcul = (x: any) => CalculateConcentration(x,
lMolRatio,
resps[0].header.indexOf("metabolite"),
resps[0].header.indexOf("area"));
// add header for calculated area
temp = [[...resps[0].header, "CalculatedArea"]];
// add header for calculated Concentration
temp = [[...resps[0].header, "Concentration"]];
}
// calculate area for all samples
// calculate concentration for all samples
for(const sample of resps[0].samples){

temp.push(funcCalcul(sample));
Expand Down
18 changes: 9 additions & 9 deletions server/api/function/RegCalibCurve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ export async function calculateRatioCalibCurve(idCalibCurve:string):Promise<numb

return client.connect()
.then(() => {
// Get the area and expected area of the metabolite of the calibration curve
// Get the area and concentration of the metabolite of the calibration curve
return client.query(`
SELECT id_mol,area, expected FROM daughter
SELECT id_mol,area, concentration FROM daughter
WHERE id_calib_curves='${idCalibCurve}'
`)
})
.then((res:{rows:any[]}) => {
// create array area/expected for each metabolite
const metaAreaExpected: {[key:string]:[number,number][]} = {}
// create array area/concentration for each metabolite
const metaConcentration: {[key:string]:[number,number][]} = {}

for(const row of res.rows){
// if the metabolite is not in the array, create it
if(metaAreaExpected[row.id_mol]===undefined){
if(metaConcentration[row.id_mol]===undefined){
// initialize first element to position 0,0
// if no metabolits, machine return noting
metaAreaExpected[row.id_mol] = [[0,0]]
metaConcentration[row.id_mol] = [[0,0]]
}
metaAreaExpected[row.id_mol].push([row.area,row.expected]);
metaConcentration[row.id_mol].push([row.area,row.concentration]);
}

// caclulate director coefficient of each metabolite
const metaRatio: {[key:string]:number}= {}
for(const key in metaAreaExpected){
for(const key in metaConcentration){
// calculate the linear regression
const {m} = linearRegression(metaAreaExpected[key]);
const {m} = linearRegression(metaConcentration[key]);
metaRatio[key] = m;
}
return metaRatio
Expand Down

0 comments on commit b3e7198

Please sign in to comment.