File

src/app/services/sheet.service.ts

Index

Methods

Constructor

constructor(http: HttpClient)
Parameters :
Name Type Optional
http HttpClient No

Methods

fetchBottomSheetData
fetchBottomSheetData(id: string, name: string)

Service to get the data about an entity for an exteral API by passing the UBERON, CL, or HNGC id. It determins which API to call and maps the response to a normalized BottomSheetInfo format.

Parameters :
Name Type Optional Description
id string No

ontologyid

name string No

: structure name

Returns : Observable<SheetInfo>
fetchDataFromAssets
fetchDataFromAssets(dataVersion: string, currentSheet: Sheet)

Service to get data of a particular version

Note: Currently depricated

Parameters :
Name Type Optional Description
dataVersion string No

version of the data

currentSheet Sheet No

current sheet

Returns : any
fetchPlaygroundData
fetchPlaygroundData(_data?: string)

Fetching initial playground data

Parameters :
Name Type Optional
_data string Yes
Returns : any
fetchSheetData
fetchSheetData(sheetId: string, gid: string, csvFileUrl?: string, formData?: FormData, output?: string, cache)

Service to fetch the data for a sheet from CSV file or Google sheet using the api

Parameters :
Name Type Optional Default value Description
sheetId string No

id of the sheet

gid string No

gid of the sheet

csvFileUrl string Yes

is the optional parameter that contains the value to the csv file url of the sheet

formData FormData Yes
output string Yes
cache No false
Returns : any
formURL
formURL(sheetID: string, gID: string)

Translate the sheet ID and GID to the google sheet URL

Parameters :
Name Type Optional Description
sheetID string No

id of the sheet

gID string No

of the sheet

Returns : string
getDataWithBody
getDataWithBody(data: Row[], organName: string)

Service to add body for each AS to the data

Parameters :
Name Type Optional Description
data Row[] No

is the parsed ASCTB data from the csv file of the sheet

organName string No
Returns : {}
testCallback
testCallback(data: JSON)
Parameters :
Name Type Optional
data JSON No
Returns : JSON
updatePlaygroundData
updatePlaygroundData(data: string[][])

Send updated data to render on the playground after editing on the table

Parameters :
Name Type Optional Description
data string[][] No

updated tabular data

Returns : any
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, throwError } from 'rxjs';
import { map } from 'rxjs/operators';
import { Row, Sheet, SheetInfo, Structure } from '../models/sheet.model';
import { URL, getAssetsURL } from './../static/url';

@Injectable({
  providedIn: 'root',
})
export class SheetService {
  constructor(private readonly http: HttpClient) {}

  /**
   * Service to fetch the data for a sheet from CSV file or Google sheet using the api
   * @param sheetId id of the sheet
   * @param gid gid of the sheet
   * @param csvFileUrl is the optional parameter that contains the value to the csv file url of the sheet
   */
  fetchSheetData(
    sheetId: string,
    gid: string,
    csvFileUrl?: string,
    formData?: FormData,
    output?: string,
    cache = false,
  ) {
    if (csvFileUrl) {
      return this.http.get(`${URL}/v2/csv`, {
        responseType: output === 'owl' ? 'text' : (undefined as unknown as 'text'),
        params: {
          csvUrl: csvFileUrl,
          output: output ? output : 'json',
        },
      });
    } else if (formData) {
      return this.http.post(`${URL}/v2/csv`, formData);
    } else {
      if (output === 'graph') {
        return this.http.get(`${URL}/v2/${sheetId}/${gid}/graph`);
      } else if (output === 'jsonld') {
        return this.http.get(`${URL}/v2/csv`, {
          params: {
            csvUrl: `https://docs.google.com/spreadsheets/d/${sheetId}/export?format=csv&gid=${gid}`,
            output: output ? output : 'jsonld',
          },
        });
      }
      return this.http.get(`${URL}/v2/${sheetId}/${gid}`, {
        params: {
          cache,
        },
      });
    }
  }

  /**
   * Service to get data of a particular version
   *
   * Note: Currently depricated
   * @param dataVersion version of the data
   * @param currentSheet current sheet
   */
  fetchDataFromAssets(dataVersion: string, currentSheet: Sheet) {
    return this.http.get(getAssetsURL(dataVersion, currentSheet), {
      responseType: 'text',
    });
  }

  testCallback(data: JSON) {
    console.log(data);
    return data;
  }

  /**
   * Service to get the data about an entity for an exteral API
   * by passing the UBERON, CL, or HNGC id. It determins which API to call and maps the
   * response to a normalized BottomSheetInfo format.
   * @param id ontologyid
   * @param name: structure name
   */
  fetchBottomSheetData(id: string, name: string): Observable<SheetInfo> {
    // Normalize FMA ids. Takes care of the formats: fma12345, FMA:12456, FMAID:12345
    if (id.toLowerCase().startsWith('fma')) {
      id = id.substring(3);
      if (id.includes(':')) {
        id = id.split(':')[1];
      }
      id = 'FMA:' + id;
    }

    const ontologyCode = id.split(':')[0] ?? '';
    const termId = id.split(':')[1] ?? '';

    if (ontologyCode === '' || termId === '') {
      return throwError('Invalid ID format');
    }

    return this.http.get(`${URL}/lookup/${ontologyCode}/${termId}`).pipe(
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      map((res: any) => {
        return {
          name,
          ontologyId: id,
          ontologyCode,
          desc: res.description,
          iri: res.link,
          extraLinks: res.extraLinks,
          label: res.label,
          hasError: false,
          msg: '',
          status: 0,
        } as SheetInfo;
      }),
    );
  }

  /**
   * Fetching initial playground data
   */
  fetchPlaygroundData(_data?: string) {
    return this.http.get(`${URL}/v2/playground`);
  }

  /**
   * Send updated data to render on the playground
   * after editing on the table
   *
   * @param data updated tabular data
   */
  updatePlaygroundData(data: string[][]) {
    return this.http.post(`${URL}/v2/playground`, { data });
  }

  /**
   * Service to add body for each AS to the data
   * @param data is the parsed ASCTB data from the csv file of the sheet
   */
  getDataWithBody(data: Row[], organName: string) {
    const organ: Structure = {
      name: 'Body',
      id: 'UBERON:0013702',
      rdfs_label: 'body proper',
    };
    data.forEach((row) => {
      row.anatomical_structures.unshift(organ);
      row.organName = organName;
    });
    return data;
  }

  /**
   * Translate the sheet ID and GID to the google sheet URL
   *
   * @param sheetID id of the sheet
   * @param gID of the sheet
   */
  formURL(sheetID: string, gID: string) {
    return `https://docs.google.com/spreadsheets/d/${sheetID}/export?format=csv&gid=${gID}`;
  }
}

results matching ""

    No results matching ""