-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mf-utilities): types returned by preprocessIonizations (#258)
migrate to ts Closes: #243
- Loading branch information
Showing
4 changed files
with
42 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,.;]+ */); | ||
|
||
// 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; | ||
} |