{"size": 4551, "ext": "js", "max_stars_repo_path": "src/__tests__/spectraComparison.test.js", "max_stars_repo_name": "jobo322/chromatography", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/__tests__/spectraComparison.test.js", "max_issues_repo_name": "jobo322/chromatography", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/__tests__/spectraComparison.test.js", "max_forks_repo_name": "jobo322/chromatography", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.9526315789, "max_line_length": 78, "alphanum_fraction": 0.5368050978}
import { Chromatogram, spectraComparison } from '..';
import { lorentzian } from '../../testFiles/examples';

test('Simple case', () => {
  const size = 70;
  const peakX = 10;
  let times = new Array(size);
  let tic1 = new Array(size);
  let tic2 = new Array(size);
  let ms1 = new Array(size);
  let ms2 = new Array(size);
  for (let i = 0; i < size; ++i) {
    times[i] = i;
    tic1[i] =
      lorentzian(i, peakX) +
      2 * lorentzian(i, 2 * peakX) +
      3 * lorentzian(i, 3 * peakX) +
      lorentzian(i, 4 * peakX) +
      2 * lorentzian(i, 5 * peakX);
    tic2[i] =
      lorentzian(i, 2 * peakX) +
      2 * lorentzian(i, 3 * peakX) +
      lorentzian(i, 4 * peakX) +
      2 * lorentzian(i, 5 * peakX) +
      lorentzian(i, 6 * peakX);
    ms1[i] = [
      [i + 10, 2 * (i + 10), 3 * (i + 10)],
      [1, 1, 1],
    ];
    ms2[i] = [
      [i, 2 * i, 3 * i],
      [1, 1, 1],
    ];
  }

  const options = {
    heightFilter: 0,
  };

  let chrom1 = new Chromatogram(times);
  chrom1.addSeries('tic', tic1);
  chrom1.addSeries('ms', ms1);

  let chrom2 = new Chromatogram(times);
  chrom2.addSeries('tic', tic2);
  chrom2.addSeries('ms', ms2);

  let compared = spectraComparison(chrom1, chrom2, options);
  expect(compared.peaksSimilarity).toStrictEqual([1, 1, 1, 1, 1]);
  expect(compared.peaksFirst.map((val) => val.retentionTime)).toStrictEqual([
    10,
    20,
    30,
    40,
    50,
  ]);
  expect(compared.peaksSecond.map((val) => val.retentionTime)).toStrictEqual([
    20,
    30,
    40,
    50,
    60,
  ]);
});

test('Shifted peaks', () => {
  const size = 70;
  const peakX = 10;
  let times = new Array(size);
  let tic1 = new Array(size);
  let tic2 = new Array(size);
  let ms1 = new Array(size);
  let ms2 = new Array(size);
  for (let i = 0; i < size; ++i) {
    times[i] = i;
    tic1[i] =
      lorentzian(i, peakX) +
      2 * lorentzian(i, 2 * peakX) +
      3 * lorentzian(i, 3 * peakX) +
      lorentzian(i, 4 * peakX) +
      2 * lorentzian(i, 5 * peakX);
    tic2[i] =
      lorentzian(i, 2 * peakX) +
      2 * lorentzian(i, 3 * peakX) +
      lorentzian(i, 4 * peakX) +
      2 * lorentzian(i, 5 * peakX) +
      lorentzian(i, 6 * peakX);
    ms1[i] = [
      [i, 2 * i, 3 * i],
      [1, 1, 1],
    ];
    ms2[i] = [
      [i, 2 * i, 3 * i],
      [1, 1, 1],
    ];
  }

  const options = {
    heightFilter: 0,
  };

  let chrom1 = new Chromatogram(times);
  chrom1.addSeries('tic', tic1);
  chrom1.addSeries('ms', ms1);

  let chrom2 = new Chromatogram(times);
  chrom2.addSeries('tic', tic2);
  chrom2.addSeries('ms', ms2);

  let compared = spectraComparison(chrom1, chrom2, options);
  expect(compared.peaksSimilarity).toStrictEqual([1, 1, 1, 1]);
  expect(compared.peaksFirst.map((val) => val.retentionTime)).toStrictEqual([
    20,
    30,
    40,
    50,
  ]);
  expect(compared.peaksSecond.map((val) => val.retentionTime)).toStrictEqual([
    20,
    30,
    40,
    50,
  ]);
});

test('Remove similar peaks in the similarity matrix column', () => {
  const size = 70;
  const peakX = 10;
  let times = new Array(size);
  let tic1 = new Array(size);
  let tic2 = new Array(size);
  let ms1 = new Array(size);
  let ms2 = new Array(size);
  for (let i = 0; i < size; ++i) {
    times[i] = i;
    tic1[i] =
      lorentzian(i, peakX) +
      2 * lorentzian(i, 2 * peakX) +
      3 * lorentzian(i, 3 * peakX) +
      lorentzian(i, 4 * peakX) +
      2 * lorentzian(i, 5 * peakX);
    tic2[i] =
      lorentzian(i, 2 * peakX) +
      2 * lorentzian(i, 3 * peakX) +
      lorentzian(i, 4 * peakX) +
      2 * lorentzian(i, 5 * peakX) +
      lorentzian(i, 6 * peakX);

    ms1[i] = [
      [i + 10, 2 * (i + 10), 3 * (i + 10)],
      [1, 1, 1],
    ];
    if (i < 45) {
      ms2[i] = [
        [28, 29, 30, 31, 32, 56, 58, 60, 62, 64, 84, 87, 90, 93, 96],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      ];
    } else {
      ms2[i] = [
        [i, 2 * i, 3 * i],
        [1, 1, 1],
      ];
    }
  }

  const options = {
    heightFilter: 0,
  };

  let chrom1 = new Chromatogram(times);
  chrom1.addSeries('tic', tic1);
  chrom1.addSeries('ms', ms1);

  let chrom2 = new Chromatogram(times);
  chrom2.addSeries('tic', tic2);
  chrom2.addSeries('ms', ms2);

  let compared = spectraComparison(chrom1, chrom2, options);

  expect(compared.peaksSimilarity).toStrictEqual([1, 1]);
  expect(compared.peaksFirst.map((val) => val.retentionTime)).toStrictEqual([
    40,
    50,
  ]);
  expect(compared.peaksSecond.map((val) => val.retentionTime)).toStrictEqual([
    50,
    60,
  ]);
});
