Skip to content

Commit 29cf08b

Browse files
committed
feat: add TGA zone to zones migration and extract migrations to separate file
1 parent f204335 commit 29cf08b

4 files changed

Lines changed: 75 additions & 100 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
.DS_Store
44
build
55
.eslintcache
6+
.claude

eln/Sample.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { createVar } from './jpaths';
1212
import convertToJcamp from './libs/convertToJcamp';
1313
import elnPlugin from './libs/elnPlugin';
1414
import { splitJcamp } from './sample/splitJcamp';
15+
import { updateSample } from './sampleMigrations';
1516

1617
const DataObject = Datas.DataObject;
1718

@@ -916,35 +917,4 @@ async function copyAnalysis(sample, original) {
916917
UI.showNotification('Analysis copied to clipboard', 'success');
917918
}
918919

919-
function updateSample(sample) {
920-
if (!sample.$content.general) {
921-
sample.$content.general = {};
922-
}
923-
924-
/** This is the old place we used to put the sequence.
925-
* By default we expect it is a peptidic sequence
926-
*/
927-
if (sample.$content.general.sequence) {
928-
// eslint-disable-next-line no-console
929-
console.log('Migrating sequence', sample.$content.general.sequence);
930-
if (!sample.$content.biology) sample.$content.biology = {};
931-
if (!sample.$content.biology.peptidic) {
932-
sample.$content.biology.peptidic = [];
933-
}
934-
if (!sample.$content.biology.peptidic.length > 0) {
935-
sample.$content.biology.peptidic[0] = {};
936-
}
937-
if (!sample.$content.biology.peptidic[0].seq) {
938-
sample.$content.biology.peptidic[0].seq = [];
939-
}
940-
if (!sample.$content.biology.peptidic[0].seq.length > 0) {
941-
sample.$content.biology.peptidic[0].seq[0] = {};
942-
}
943-
sample.setChildSync(
944-
['$content', 'biology', 'peptidic', 0, 'seq', 0, 'sequence'],
945-
sample.$content.general.sequence,
946-
);
947-
sample.$content.general.sequence = undefined;
948-
}
949-
}
950920
module.exports = Sample;

eln/sampleMigrations.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Migrations for sample data structure changes
3+
*/
4+
5+
/**
6+
* Migrates sequence data from the old location to the new biology structure.
7+
* Old location: $content.general.sequence
8+
* New location: $content.biology.peptidic[0].seq[0].sequence
9+
* By default we expect it is a peptidic sequence.
10+
*
11+
* @param {object} sample - The sample object to migrate
12+
*/
13+
function migrateSequence(sample) {
14+
if (!sample.$content.general) {
15+
sample.$content.general = {};
16+
}
17+
18+
if (sample.$content.general.sequence) {
19+
// eslint-disable-next-line no-console
20+
console.log('Migrating sequence', sample.$content.general.sequence);
21+
if (!sample.$content.biology) sample.$content.biology = {};
22+
if (!sample.$content.biology.peptidic) {
23+
sample.$content.biology.peptidic = [];
24+
}
25+
if (!sample.$content.biology.peptidic.length > 0) {
26+
sample.$content.biology.peptidic[0] = {};
27+
}
28+
if (!sample.$content.biology.peptidic[0].seq) {
29+
sample.$content.biology.peptidic[0].seq = [];
30+
}
31+
if (!sample.$content.biology.peptidic[0].seq.length > 0) {
32+
sample.$content.biology.peptidic[0].seq[0] = {};
33+
}
34+
sample.setChildSync(
35+
['$content', 'biology', 'peptidic', 0, 'seq', 0, 'sequence'],
36+
sample.$content.general.sequence,
37+
);
38+
sample.$content.general.sequence = undefined;
39+
}
40+
}
41+
42+
/**
43+
* Migrates thermogravimetric analysis metadata from "zone" to "zones".
44+
* Old location: $content.spectra.thermogravimetricAnalysis[].meta.zone
45+
* New location: $content.spectra.thermogravimetricAnalysis[].meta.zones
46+
*
47+
* @param {object} sample - The sample object to migrate
48+
*/
49+
function migrateTGAZones(sample) {
50+
const tgaEntries = sample.$content?.spectra?.thermogravimetricAnalysis;
51+
if (!Array.isArray(tgaEntries)) return;
52+
53+
for (const entry of tgaEntries) {
54+
if (entry.zone && !entry.zones) {
55+
// eslint-disable-next-line no-console
56+
console.log('Migrating TGA zone to zones');
57+
entry.zones = entry.zone;
58+
delete entry.zone;
59+
}
60+
}
61+
}
62+
63+
/**
64+
* Run all migrations on a sample
65+
*
66+
* @param {object} sample - The sample object to migrate
67+
*/
68+
function updateSample(sample) {
69+
migrateSequence(sample);
70+
migrateTGAZones(sample);
71+
}
72+
73+
module.exports = { updateSample };

eln/setSpecdtrumClasses.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)