Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mf-utilities): types returned by preprocessIonizations #258

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/mf-parser/src/util/flatten.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @param parsed
* @param options
* @return {string[]}
*/
export function flatten(parsed, options = {}) {
const { groupIdentical = false, limit = 100000 } = options;
if (parsed.length === 0) return [''];
Expand Down Expand Up @@ -114,6 +119,8 @@ function createMFs(parts, comment, limit) {
for (let i = 0; i < currents.length; i++) {
currents[i] = parts[i].min;
}

/** @type {string[]} */
const mfs = [];
let position = 0;
while (position < currents.length) {
Expand Down
File renamed without changes.
25 changes: 0 additions & 25 deletions packages/mf-utilities/src/preprocessIonizations.js

This file was deleted.

35 changes: 35 additions & 0 deletions packages/mf-utilities/src/preprocessIonizations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { MF } from 'mf-parser';
import type { AtomsMap } from 'mf-parser';

export interface Ionization {
mf: string;
em: number;
charge: number;
atoms: AtomsMap;
}

export function preprocessIonizations(
ionizationsString: string | Ionization[] = '',
): Ionization[] {
if (Array.isArray(ionizationsString)) return ionizationsString;
const ionizations = ionizationsString.split(/ *[\t\n\r,.;]+ */);
tpoisseau marked this conversation as resolved.
Show resolved Hide resolved

// it is allowed to have ranges in Ionizations. We need to explode them.

const results: Ionization[] = [];

for (const ionization of ionizations) {
const parts = new MF(ionization).flatten();
for (const part of parts) {
const info = new MF(part).getInfo();
results.push({
mf: part,
em: info.monoisotopicMass,
charge: info.charge,
atoms: info.atoms,
});
}
}

return results;
}
Loading