fillInteractDB.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {getInteractionsFromEntry, readOffset} from '.'
  2. import fs from 'fs'
  3. import readline from 'readline'
  4. const { Database, aql } = require("arangojs");
  5. import { XMLParser } from 'fast-xml-parser'
  6. const db = new Database({
  7. url: "http://localhost:8529",
  8. databaseName: "test",
  9. auth: { username: "root", password: "test123" },
  10. });
  11. const line$ = (path: string) => readline.createInterface({
  12. input: fs.createReadStream(path),
  13. crlfDelay: Infinity
  14. })
  15. const parser = new XMLParser({
  16. ignoreAttributes: false,
  17. alwaysCreateTextNode: false,
  18. attributeNamePrefix: "",
  19. textNodeName: "value",
  20. allowBooleanAttributes: true,
  21. })
  22. ;(async()=>{
  23. const uniprotDB = '/home/thomas/NGS/ref/UNIPROT/uniprot_sprot_human.xml'
  24. for await (const line of line$(uniprotDB + '.jsi')) {
  25. const acc = /;/.test(line) ? line.split(';')[0] : line.split(/\t/)[0]
  26. const [from, to] = [line.split(/\t/)[1], line.split(/\t/)[2]]
  27. const tmp = parser.parse(await readOffset(uniprotDB, Number(from), Number(to)))
  28. if(Object.keys(tmp).length === 0) {
  29. break
  30. } else {
  31. try {
  32. const inter = await getInteractionsFromEntry(tmp)
  33. } catch (error) {
  34. console.log(error)
  35. console.log(acc)
  36. console.log(tmp.entry.gene)
  37. console.log(tmp)
  38. break
  39. }
  40. }
  41. }
  42. })()