@datagrok/sequence-translator 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
 
2
- import {map, SYNTHESIZERS, TECHNOLOGIES, MODIFICATIONS, delimiter} from './map';
2
+ import {map, SYNTHESIZERS, TECHNOLOGIES, MODIFICATIONS, delimiter, gcrsCodesWithoutSmiles} from './map';
3
3
  import {asoGapmersNucleotidesToBioSpring, asoGapmersNucleotidesToGcrs,
4
4
  asoGapmersBioSpringToNucleotides, asoGapmersBioSpringToGcrs, asoGapmersGcrsToNucleotides,
5
5
  asoGapmersGcrsToBioSpring, gcrsToMermade12, siRnaNucleotideToBioSpringSenseStrand,
@@ -88,6 +88,10 @@ export function getFormat(sequence: string): string | null {
88
88
  return possibleSynthesizers[0];
89
89
  }
90
90
 
91
+ function sortByStringLengthInDescendingOrder(array: string[]): string[] {
92
+ return array.sort(function(a: string, b: string) {return b.length - a.length;});
93
+ }
94
+
91
95
  export function isValidSequence(sequence: string, format: string | null): {
92
96
  indexOfFirstNotValidChar: number,
93
97
  synthesizer: string[] | null,
@@ -118,7 +122,7 @@ export function isValidSequence(sequence: string, format: string | null): {
118
122
  const nucleotides = ['A', 'U', 'T', 'C', 'G'];
119
123
 
120
124
  possibleSynthesizers.forEach((synthesizer) => {
121
- const codes = getAllCodesOfSynthesizer(synthesizer);
125
+ const codes = sortByStringLengthInDescendingOrder(getAllCodesOfSynthesizer(synthesizer));
122
126
  while (outputIndex < sequence.length) {
123
127
  const matchedCode = codes.find((c) => c == sequence.slice(outputIndex, outputIndex + c.length));
124
128
 
@@ -166,8 +170,8 @@ export function isValidSequence(sequence: string, format: string | null): {
166
170
  // })
167
171
  // .show();
168
172
  // } else if (possibleTechnologies.length == 0)
169
- if (possibleTechnologies.length == 0)
170
- return {indexOfFirstNotValidChar: 0, synthesizer: [possibleSynthesizers[3]], technology: null};
173
+ // if (possibleTechnologies.length == 0)
174
+ // return {indexOfFirstNotValidChar: 0, synthesizer: [possibleSynthesizers[3]], technology: null};
171
175
 
172
176
  outputIndex = 0;
173
177
 
@@ -212,9 +216,11 @@ export function getAllCodesOfSynthesizer(synthesizer: string): string[] {
212
216
  }
213
217
 
214
218
  function getListOfPossibleSynthesizersByFirstMatchedCode(sequence: string): string[] {
215
- const synthesizers: string[] = [];
219
+ let synthesizers: string[] = [];
216
220
  Object.keys(map).forEach((synthesizer: string) => {
217
- const codes = getAllCodesOfSynthesizer(synthesizer);
221
+ let codes = sortByStringLengthInDescendingOrder(getAllCodesOfSynthesizer(synthesizer));
222
+ if (synthesizer == 'Janssen GCRS Codes')
223
+ codes = codes.concat(gcrsCodesWithoutSmiles);
218
224
  //TODO: get first non-dropdown code when there are two modifications
219
225
  let start = 0;
220
226
  for (let i = 0; i < sequence.length; i++) {
@@ -223,6 +229,8 @@ function getListOfPossibleSynthesizersByFirstMatchedCode(sequence: string): stri
223
229
  break;
224
230
  }
225
231
  }
232
+ if (gcrsCodesWithoutSmiles.some((s: string) => s == sequence.slice(start, start + s.length)))
233
+ synthesizers = ['Janssen GCRS Codes'];
226
234
  if (codes.some((s: string) => s == sequence.slice(start, start + s.length)))
227
235
  synthesizers.push(synthesizer);
228
236
  });