Skip to content

Commit

Permalink
uniprot storage as ts object
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilpert committed Apr 20, 2021
1 parent 26427ad commit 43c9c70
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/components/XmlLoader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ import InputFile from '@/components/InputFile.vue'
import XLSX from 'xlsx';
import { useStore } from 'vuex'
import { UniprotDatabase } from '../utilities/uniprot-database';
import { UniprotStorage } from '../utilities/uniprot-storage';
const UniprotDatabase = new UniprotStorage()
import { range } from '../utilities/basic_functions'
export default defineComponent({
Expand Down Expand Up @@ -166,7 +167,6 @@ export default defineComponent({
uniprotDBFilled.value = true;
};
const cell = (x: number, y: number)=>{
Expand Down Expand Up @@ -221,8 +221,8 @@ export default defineComponent({
store.dispatch('selectColByKeyword', 'Abundance Ratio');
loaded.value = true;
xlsDropped.value = false;
console.log("delete uniprot database")
await UniprotDatabase.clear();
//console.log("delete uniprot database")
//await UniprotDatabase.clear();
console.log("fill up uniprot database")
await storeInUniprotDatabase();
console.log("uniprot database filled");
Expand Down
3 changes: 1 addition & 2 deletions src/utilities/uniprot-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export namespace UniprotDatabase {
const dbName = "uniprotDB";
let maxItem: number;
let DBOpenRequest: IDBOpenDBRequest;
const V_NUM = 3;
const V_NUM = 6;
let DB: IDBDatabase;
const handshake = async (url?: string) => {
try {
Expand All @@ -47,7 +47,6 @@ export namespace UniprotDatabase {

const fetchFrom = async (uniprotIDs: string[]): Promise<UniprotFetch> => {
//console.log(`ff Loading ${uniprotIDs.length} items ff`);
//console.log(providerURL);
const response = await fetch(`${providerURL ? providerURL : ''}/api/uniprot/many`, {
method: 'POST',
headers: {
Expand Down
68 changes: 68 additions & 0 deletions src/utilities/uniprot-storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@


interface UniprotDatum {
name?: string;
GO?: Map<string, string>[];
id: string;
geneName?: string;
fullName?: string;
taxid?: string;
}

type UniprotFetch = { [index: string]: UniprotDatum|null };

export class UniprotStorage {
data: UniprotFetch;
providerURL: string|undefined

constructor(url?: string){
this.data = {"pouet" : {GO : [], fullName: "Pouet", geneName : "pouet", id: "A5A613", name: "pouet", taxid: "pouet"}}
this.providerURL = url
}

private fetchFrom = async (uniprotIDs: string[]): Promise<UniprotFetch> => {
//console.log(`ff Loading ${uniprotIDs.length} items ff`);
const response = await fetch(`${this.providerURL ? this.providerURL : ''}/api/uniprot/many`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({'uniprotIDs' : uniprotIDs})
});

const uniprotData: UniprotFetch = await response.json();
if (!uniprotData)
throw("No data loaded");

return uniprotData;
}
public add = async (uniprotIDs : string[]): Promise<number> => {
console.log("add");
const uniprotData: UniprotFetch = await this.fetchFrom(uniprotIDs)
console.log("fetched");
return new Promise((res, rej) => {
try{
this.data = {...this.data, ...uniprotData}
res(Object.keys(this.data).length)
}
catch (err) {
rej(err)
}
})
}

public get = async(id : string): Promise<any> => {
return new Promise((res, rej) => {
try{
const result = this.data[id]
res(result)
}
catch(err){
rej(err)

}
})
}

}

0 comments on commit 43c9c70

Please sign in to comment.