Skip to content

Commit 8b331c8

Browse files
committed
step7 insertat tax_id
1 parent f47d17f commit 8b331c8

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

curation-pipeline/src/components/steps/Step2GenomeTF.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ async function computeTaxonomyForAcc(acc) {
123123
return payload;
124124
}
125125

126+
computeTaxonomyForAcc(accession).then((payload) => {
127+
console.log("TAXONOMY payload", accession, payload);
128+
});
129+
130+
126131
export default function Step2GenomeTF() {
127132
const {
128133
tf,

curation-pipeline/src/components/steps/Step7CurationInfo.jsx

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,55 @@ WHERE NOT EXISTS (
360360
}
361361

362362
// Taxonomia + link a genome
363+
// Inserta la cadena completa (ancestros + hoja)
364+
// Pero la BD "indexa" hasta species: si el leaf es strain/subspecies, enlazamos el genoma a la species.
363365
const taxByAcc = taxonomyData?.byAccession || {};
364366

367+
const rankScore = (r) => {
368+
const x = String(r || "no rank").toLowerCase();
369+
const order = {
370+
"no rank": 0,
371+
superkingdom: 1,
372+
kingdom: 2,
373+
phylum: 3,
374+
class: 4,
375+
order: 5,
376+
family: 6,
377+
genus: 7,
378+
species: 8,
379+
subspecies: 9,
380+
strain: 10,
381+
};
382+
return order[x] ?? 0;
383+
};
384+
365385
for (const acc of accessions) {
366386
const tInfo = taxByAcc?.[acc];
367-
const chain = Array.isArray(tInfo?.chain) ? tInfo.chain : [];
368-
if (!chain.length) continue;
387+
const chainRaw = Array.isArray(tInfo?.chain) ? tInfo.chain : [];
388+
if (!chainRaw.length) continue;
389+
390+
// Aseguramos orden de general -> específico.
391+
// Si viene al revés, invertimos (p.ej. empieza en strain y termina en phylum).
392+
const chainOrdered = [...chainRaw];
393+
if (chainOrdered.length >= 2) {
394+
const first = rankScore(chainOrdered[0]?.rank);
395+
const last = rankScore(chainOrdered[chainOrdered.length - 1]?.rank);
396+
if (first > last) chainOrdered.reverse();
397+
}
398+
399+
// Si NCBI devuelve strain/subspecies, recortamos la cadena para enlazar el genoma a species.
400+
let chain = chainOrdered;
401+
const idxSpecies = chainOrdered.findIndex((n) => String(n?.rank || "").toLowerCase() === "species");
402+
if (idxSpecies >= 0) chain = chainOrdered.slice(0, idxSpecies + 1);
369403

404+
// Insert/Update de cada nodo y su parent_id (FK a core_taxonomy.id)
370405
for (let i = 0; i < chain.length; i++) {
371406
const node = chain[i];
372407
const taxid = String(node.taxonomy_id || "").trim();
408+
if (!taxid) continue;
409+
373410
const name = String(node.name || "").trim();
374411
const rank = String(node.rank || "no rank").trim();
375-
if (!taxid) continue;
376412

377413
const parentTaxid = i > 0 ? String(chain[i - 1].taxonomy_id || "").trim() : "";
378414
const parentIdExpr = parentTaxid
@@ -401,6 +437,7 @@ WHERE taxonomy_id='${esc(taxid)}';
401437
`.trim());
402438
}
403439

440+
// Enlazamos el genoma al leaf elegido (species si existe; si no, el último del chain)
404441
const leafTaxid = String(chain[chain.length - 1]?.taxonomy_id || "").trim();
405442
if (leafTaxid) {
406443
sql.push(`

0 commit comments

Comments
 (0)