gene.ts 2.46 KB
Newer Older
Andrey Azov's avatar
Andrey Azov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/**
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

17 18 19 20 21
import faker from 'faker';
import times from 'lodash/times';
import { scaleLinear } from 'd3';

import { createSlice } from './slice';
22
import { createTranscript, ProteinCodingTranscript } from './transcript';
23

24
import { FullGene } from 'src/shared/types/thoas/gene';
25 26
import { TicksAndScale } from 'src/content/app/entity-viewer/gene-view/components/base-pairs-ruler/BasePairsRuler';

27 28 29 30 31 32 33
type GeneFixture = Omit<FullGene, 'transcripts'> & {
  transcripts: ProteinCodingTranscript[];
};

export const createGene = (
  fragment: Partial<GeneFixture> = {}
): GeneFixture => {
34
  const geneSlice = createSlice();
35
  const transcripts = fragment.transcripts || [createTranscript()];
36

Andrey Azov's avatar
Andrey Azov committed
37
  const unversionedStableId = faker.datatype.uuid();
38 39 40
  const version = 1;
  const stableId = `${unversionedStableId}.${version}`;

41
  return {
42
    type: 'Gene',
43 44 45
    stable_id: stableId,
    unversioned_stable_id: unversionedStableId,
    version,
46
    symbol: faker.lorem.word(),
47
    name: faker.lorem.words(),
48
    slice: geneSlice,
49
    transcripts,
50 51
    alternative_symbols: [],
    external_references: [],
52 53 54 55 56
    metadata: {
      biotype: {
        label: faker.lorem.words(),
        value: faker.lorem.word(),
        definition: faker.lorem.sentence()
57 58 59 60
      },
      name: {
        accession_id: faker.lorem.word(),
        url: faker.internet.url()
61 62
      }
    },
63
    ...fragment
64 65 66 67
  };
};

const getScale = () => {
Andrey Azov's avatar
Andrey Azov committed
68 69
  const domain = [1000, faker.datatype.number({ min: 2000, max: 100000 })];
  const range = [100, faker.datatype.number({ min: 200, max: 600 })];
Ridwan Amode's avatar
Ridwan Amode committed
70
  const scale = scaleLinear().domain(domain).rangeRound(range);
71 72 73 74 75

  return scale;
};

export const createRulerTicks = (): TicksAndScale => ({
Andrey Azov's avatar
Andrey Azov committed
76 77
  labelledTicks: times(faker.datatype.number({ min: 1, max: 10 }), Number),
  ticks: times(faker.datatype.number({ min: 1, max: 5 }), Number),
78 79
  scale: getScale()
});