Skip to content

Commit 0157944

Browse files
committed
feat(data): Add organism group processing
- Implemented logic to process organism_groups.csv. - Organisms can now be assigned to multiple groups via a semicolon-separated list in organisms.csv. - The system now resolves synonyms for organism groups, mapping them to all associated organism IDs.
1 parent 09efc6e commit 0157944

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/data/index.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export function getSharedData(
7979
sources: string;
8080
abxClasses: string;
8181
orgClasses: string;
82+
orgGroups: string;
8283
},
8384
) {
8485
if (!sharedDataPromise) {
@@ -88,7 +89,8 @@ export function getSharedData(
8889
loadCsv(dir, files.sources),
8990
loadCsv(dir, files.abxClasses),
9091
loadCsv(dir, files.orgClasses),
91-
]).then(([abx, org, rawSources, abxClasses, orgClasses]) => {
92+
loadCsv(dir, files.orgGroups),
93+
]).then(([abx, org, rawSources, abxClasses, orgClasses, orgGroups]) => {
9294
const sources = rawSources.map((s: any) => ({
9395
...s,
9496
url: s.source_url,
@@ -182,6 +184,34 @@ export function getSharedData(
182184
}
183185
// --- End Organism Class Synonym Integration ---
184186

187+
// --- Organism Group Synonym Integration ---
188+
const groupIdToOrgIds = new Map<string, string[]>();
189+
for (const organism of org) {
190+
const groupIdsStr = organism.groups;
191+
if (groupIdsStr) {
192+
const groupIds = groupIdsStr.split(';').map(id => id.trim()).filter(Boolean);
193+
for (const groupId of groupIds) {
194+
if (!groupIdToOrgIds.has(groupId)) {
195+
groupIdToOrgIds.set(groupId, []);
196+
}
197+
groupIdToOrgIds.get(groupId)!.push(organism.amr_code);
198+
}
199+
}
200+
}
201+
202+
for (const group of orgGroups) {
203+
const members = groupIdToOrgIds.get(group.id);
204+
if (members && members.length > 0) {
205+
const synonyms = collectSynonyms(group);
206+
for (const syn of synonyms) {
207+
const existingIds = orgSyn2Id.has(syn) ? orgSyn2Id.get(syn)!.split(',') : [];
208+
const allIds = [...new Set([...existingIds, ...members])];
209+
orgSyn2Id.set(syn, allIds.join(','));
210+
}
211+
}
212+
}
213+
// --- End Organism Group Synonym Integration ---
214+
185215
const allAbxIds = abx
186216
.filter((r: any) => r.class)
187217
.map((r: any) => r.amr_code);

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function docusaurusPluginResistogram(
2828
sources: opts.files?.sources ?? "data_sources.csv",
2929
abxClasses: opts.files?.abxClasses ?? "antibiotic_classes.csv",
3030
orgClasses: opts.files?.orgClasses ?? "organism_classes.csv",
31+
orgGroups: opts.files?.orgGroups ?? "organism_groups.csv",
3132
};
3233
const dataPath = join(siteDir, dataDir);
3334
const pluginId = opts.id ?? "default";

src/remark/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default function remarkResistogram(options: { dataDir?: string, files?: a
9292
sources: files.sources ?? "data_sources.csv",
9393
abxClasses: files.abxClasses ?? "antibiotic_classes.csv",
9494
orgClasses: files.orgClasses ?? "organism_classes.csv",
95+
orgGroups: files.orgGroups ?? "organism_groups.csv",
9596
});
9697

9798
let importAdded = false;

0 commit comments

Comments
 (0)