Code Monkey home page Code Monkey logo

api-respone-transform.js's Introduction

Test Coveralls Coverage Status Documentation Version

Welcome to @biothings-explorer/api-response-transform ๐Ÿ‘‹

A NodeJS module to transform the JSON output from API into BioLink-compatible JSON structure

๐Ÿ  Homepage

Install

npm i @biothings-explorer/api-response-transform

Usage

This package is desgined to be used as a downstream consumer of @biothings-explorer/smartapi-kg nodejs package. @biothings-explorer/smartapi-kg provides knowledge graph operation info, and when combined with API JSON response, can be consumed as input of the @biothings-explorer/api-response-transform package.

  • Import and Initialize

    const tf = require("@biothings-explorer/api-response-transform")
    const axios = require("axios");
  • Transform

    • Get API Response

      let res = await axios({
          method: 'post',
          url: 'https://biothings.ncats.io/semmedgene/query',
          data: 'q=C1332823, C1332824, 123&scopes=umls',
          params: {
              fields: 'name,umls,positively_regulates',
              size: '5'
          }
      });
    • Bind with edge info from @biothings-explorer/smartapi-kg

      let input = {
          response: res.data,
          edge: {
              "input": ["C1332824", "C1332823"],
              "query_operation": {
                  "params": {
                      "fields": "positively_regulates"
                  },
                  "request_body": {
                      "body": {
                          "q": "{inputs[0]}",
                          "scopes": "umls"
                      }
                  },
                  "path": "/query",
                  "path_params": [],
                  "method": "post",
                  "server": "https://biothings.ncats.io/semmedgene",
                  "tags": [
                      "disease",
                      "annotation",
                      "query",
                      "translator",
                      "biothings",
                      "semmed"
                  ],
                  "supportBatch": true,
                  "inputSeparator": ","
              },
              "association": {
                  "input_id": "UMLS",
                  "input_type": "Gene",
                  "output_id": "UMLS",
                  "output_type": "Gene",
                  "predicate": "positively_regulates",
                  "source": "SEMMED",
                  "api_name": "SEMMED Gene API",
                  "smartapi": {
                      "id": "81955d376a10505c1c69cd06dbda3047",
                      "meta": {
                          "ETag": "f94053bc78b3c2f0b97f7afd52d7de2fe083b655e56a53090ad73e12be83673b",
                          "github_username": "kevinxin90",
                          "timestamp": "2020-05-27T16:53:40.804575",
                          "uptime_status": "good",
                          "uptime_ts": "2020-06-12T00:04:31.404599",
                          "url": "https://raw.githubusercontent.com/NCATS-Tangerine/translator-api-registry/master/semmed/semmed_gene.yaml"
                      }
                  }
              },
              "response_mapping": {
                  "positively_regulates": {
                      "pmid": "positively_regulates.pmid",
                      "umls": "positively_regulates.umls"
                  }
              },
              "id": "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b"
          }
      }
    • Transform into biolink-compatible format

      let transformer = new tf.default(input);
      let res = transformer.transform();
      
      //returns [
      //{
      //  HGNC: '10956',
      //  pubmed: [ '21685912', '30089514', sequence: true ],
      //  relation: 'contributes to condition',
      //  source: [ 'https://archive.monarchinitiative.org/#gwascatalog' ],
      //  taxid: 'NCBITaxon:9606',
      //  '$reasoner_edge': undefined,
      //  '$association': {
      //    input_id: 'MONDO',
      //    input_type: 'Disease',
      //    output_id: 'HGNC',
      //    output_type: 'Gene',
      //    predicate: 'related_to',
      //    api_name: 'BioLink API',
      //    smartapi: [Object]
      //  },
      //  '$input': 'MONDO:678',
      //  '$output': 'HGNC:10956',
      //  '$original_input': undefined,
      //  '$input_resolved_identifiers': undefined,
      //  publications: [ 'PMID:21685912', 'PMID:30089514' ]
      //  },
      //  ...]

Run tests

npm run test

Author

๐Ÿ‘ค Jiwen Xin

๐Ÿค Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a โญ๏ธ if this project helped you!

๐Ÿ“ License

Copyright ยฉ 2020 Jiwen Xin.
This project is ISC licensed.

api-respone-transform.js's People

Contributors

kevinxin90 avatar newgene avatar ariutta avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.