ebinocle-ng-rsclient
EBI Search Angular REST client
Documentation
The documentation can be found at: http://ebi-wp.gitdocs.ebi.ac.uk/ebinocle-ng-rsclient
Install
npm i @ebi-wp/ebinocle-ng-rsclient
Usage example
The following example, creates a SearchRequest
object, sets the domain and query.
Then it gets the search results using that object.
import { Component } from '@angular/core';
import { Configuration, SearchRequest, SearchService } from '@ebi-wp/ebinocle-ng-rsclient';
@Component({
selector: 'app-search',
templateUrl: './search.component.html'
})
export class SearchComponent {
constructor(private readonly searchService: SearchService) {}
public search() {
const searchRequest = new SearchRequest(new Configuration());
searchRequest.setDB('embl');
searchRequest.query = 'mouse';
return this.searchService.getSearchResults(searchRequest);
}
}
Simple search
In the following example we use the SearchService
to submit a search to the embl
domain with the query "mouse"
.
import { Component, OnInit } from '@angular/core';
import { Configuration, SearchRequest, SearchResults, SearchService } from '@ebi-wp/ebinocle-ng-rsclient';
import { Observable } from 'rxjs';
@Component({
selector: 'app-search',
templateUrl: './search.component.html'
})
export class SearchComponent implements OnInit {
public searchResults: SearchResults;
constructor(private readonly searchService: SearchService) {}
public ngOnInit(): void {
this.search().subscribe((searchResults) => {
this.searchResults = searchResults;
});
}
public search(): Observable<SearchResults> {
const searchRequest = new SearchRequest(new Configuration());
searchRequest.setDB('embl');
searchRequest.query = 'mouse';
return this.searchService.getSearchResults(searchRequest);
}
}
Then in the HTML template:
<ng-container *ngIf="searchResults && searchResults.hitCount > 0">
<div *ngFor="let entry of searchResults.entries">
<p>{{ entry.id }}</p>
<p>{{ entry.fields.description[0] }}</p>
</div>
</ng-container>
Faceted search
To get facets along with a search result, the query and facetcount parameters are needed:
// ...
public search(): Observable<SearchResults> {
const searchRequest = new SearchRequest(new Configuration());
searchRequest.setDB('embl');
searchRequest.query = 'mouse';
searchRequest.facetcount = 10;
return this.searchService.getSearchResults(searchRequest);
}
// ...
To extract the facets use:
// ...
this.search().subscribe((searchResults) => {
this.facets = searchResults.facets;
});
// ...
To filter out by a list of selected facet values, the facets
parameter can help. The value format for the parameter is a comma separated list of facet id:facet value:
// ...
public search(): Observable<SearchResults> {
const searchRequest = new SearchRequest(new Configuration());
searchRequest.setDB('embl');
searchRequest.query = 'plantae';
searchRequest.facetcount = 10;
searchRequest.facets = 'taxonomy:1842';
return this.searchService.getSearchResults(searchRequest);
}
// ...
Cross reference searching
Finding domains referred by an entry
Given a source domain and an entry we want to retrieve the referenced (target) domains:
// ...
public search(): Observable<SearchResults> {
return this.searchService.getReferencedDomains('uniprot', 'Q9BYF1');
}
// ...
To extract the results:
// ...
this.search().subscribe((searchResults) => {
for (const domain of searchResults.domains) {
console.log(`Referenced domain ${domain.id} with ${domain.referenceEntryCount} entries`);
}
});
// ...
Cross reference searching
To find entries in a target domain (europepmc
in this case) referred to by a source domain (uniprot
) and entry (Q9BYF1
) use the following:
// ...
public search(): Observable<SearchResults> {
return this.searchService.getReferencedEntries(
'uniprot',
'Q9BYF1',
'europepmc',
1
);
}
// ...
To extract the results:
// ...
this.search().subscribe((searchResults) => {
const reference = this.searchResults.entries[0];
this.referencesResult = {
hitCount: reference?.referenceCount,
entries: reference?.references
};
});
// ...