gosling.js 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"file":"exported-utils-26226ee9.js","sources":["../src/data-fetchers/utils.ts"],"sourcesContent":["import { bisector } from 'd3-array';\nimport { RemoteFile as _RemoteFile } from 'generic-filehandle';\n\nimport type * as HiGlass from '@higlass/types';\nimport type { Assembly, ChromSizes, Datum } from '@gosling-lang/gosling-schema';\n\nexport type CommonDataConfig = {\n assembly: Assembly;\n x?: string;\n xe?: string;\n x1?: string;\n x1e?: string;\n urlFetchOptions?: RequestInit;\n};\n\nexport class DataSource<File, Options> {\n chromInfo: ExtendedChromInfo;\n tilesetInfo: ReturnType<typeof tilesetInfoFromChromInfo>;\n\n constructor(public file: File, chromSizes: ChromSizes, public options: Options) {\n this.chromInfo = sizesToChromInfo(chromSizes);\n this.tilesetInfo = tilesetInfoFromChromInfo(this.chromInfo);\n }\n}\n\n/**\n * Filter data before sending to a track considering the visible genomic area in the track.\n * TODO(2022-Jul-13): Consider genomic `y` channels as well.\n */\nexport function filterUsingGenoPos(\n data: Datum[],\n [minX, maxX]: [number, number],\n config: Omit<CommonDataConfig, 'assembly'>\n) {\n const { x, xe, x1, x1e } = config;\n const definedXFields = [x, xe, x1, x1e].filter(f => f) as string[];\n return data.filter((d: Datum) => {\n if (definedXFields.length === 0) {\n // no filter applies\n return true;\n } else if (definedXFields.length === 1) {\n // filter based on one genomic position\n const value = +d[definedXFields[0]];\n return typeof value === 'number' && minX < value && value <= maxX;\n } else {\n // filter based on two genomic positions, i.e., check overlaps\n const values = definedXFields.map(f => +d[f]).filter(v => !isNaN(v));\n const minValue = Math.min(...values);\n const maxValue = Math.max(...values);\n return minX <= maxValue && minValue <= maxX;\n }\n });\n}\n\nconst chromInfoBisector = bisector((d: { pos: number }) => d.pos).left;\n\nconst chrToAbs = (chrom: string, chromPos: number, chromInfo: HiGlass.ChromInfo) =>\n chromInfo.chrPositions[chrom].pos + chromPos;\n\nconst absToChr = (absPosition: number, chromInfo: HiGlass.ChromInfo) => {\n if (!chromInfo || !chromInfo.cumPositions || !chromInfo.cumPositions.length) {\n return null;\n }\n\n let insertPoint = chromInfoBisector(chromInfo.cumPositions, absPosition);\n const lastChr = chromInfo.cumPositions[chromInfo.cumPositions.length - 1].chr;\n const lastLength = chromInfo.chromLengths[lastChr];\n\n // @ts-expect-error\n insertPoint -= insertPoint > 0 && 1;\n\n let chrPosition = Math.floor(absPosition - chromInfo.cumPositions[insertPoint].pos);\n let offset = 0;\n\n if (chrPosition < 0) {\n // before the start of the genome\n offset = chrPosition - 1;\n chrPosition = 1;\n }\n\n if (insertPoint === chromInfo.cumPositions.length - 1 && chrPosition > lastLength) {\n // beyond the last chromosome\n offset = chrPosition - lastLength;\n chrPosition = lastLength;\n }\n\n return [chromInfo.cumPositions[insertPoint].chr, chrPosition, offset, insertPoint] as const;\n};\n\n/**\n * Get a chromosome name for the consistentcy, e.g., `1` --> `chr1`.\n * @param chrName A chromosome name to be sanitized\n * @param assembly A genome assembly of the data\n * @param chromosomePrefix A prefix string that can be replaced to 'chr'\n * @returns\n */\nexport function sanitizeChrName(chrName: string, assembly: Assembly, chromosomePrefix?: string) {\n if (Array.isArray(assembly)) {\n // this is a custom assembly, so use this as is\n return chrName;\n }\n\n // For assemblies in Gosling, we use the `chr` prefix consistently\n if (chromosomePrefix) {\n // `hs1` --> `chr1`\n chrName = chrName.replace(chromosomePrefix, 'chr');\n } else if (!chrName.includes('chr')) {\n // `1` --> `chr1`\n chrName = `chr${chrName}`;\n }\n return chrName;\n}\n\nexport type ExtendedChromInfo = HiGlass.ChromInfo & {\n absToChr(absPos: number): ReturnType<typeof absToChr> | null;\n chrToAbs(chr: [name: string, pos: number]): number | null;\n};\n\nexport function tilesetInfoFromChromInfo(chromInfo: ExtendedChromInfo, tileSize = 1024) {\n return {\n tile_size: tileSize,\n bins_per_dimension: tileSize,\n max_zoom: Math.ceil(Math.log(chromInfo.totalLength / tileSize) / Math.log(2)),\n max_width: chromInfo.totalLength,\n min_pos: [0],\n max_pos: [chromInfo.totalLength]\n };\n}\n\nexport function sizesToChromInfo(sizes: [string, number][]): ExtendedChromInfo {\n const info: HiGlass.ChromInfo = {\n cumPositions: [],\n chromLengths: {},\n chrPositions: {},\n totalLength: 0\n };\n\n sizes.forEach(([chr, length], i) => {\n const chrPosition = { id: i, chr, pos: info.totalLength };\n info.chrPositions[chr] = chrPosition;\n info.chromLengths[chr] = length;\n info.cumPositions.push(chrPosition);\n info.totalLength += length;\n });\n\n return {\n ...info,\n absToChr: absPos => (info.chrPositions ? absToChr(absPos, info) : null),\n chrToAbs: ([chrName, chrPos]) => (info.chrPositions ? chrToAbs(chrName, chrPos, info) : null)\n };\n}\n\nexport class RemoteFile extends _RemoteFile {\n // Overrides `read` to eagerly read 200 or 206 response\n // from https://github.com/GMOD/generic-filehandle/blob/0e8209be25e3097307bd15e964edd8c017e808d7/src/remoteFile.ts#L100-L162\n public read: _RemoteFile['read'] = async (\n buffer,\n offset = 0,\n length,\n position = 0,\n opts = {}\n ): Promise<{ bytesRead: number; buffer: Buffer }> => {\n const { headers = {}, signal, overrides = {} } = opts;\n\n if (length < Infinity) {\n headers.range = `bytes=${position}-${position + length}`;\n } else if (length === Infinity && position !== 0) {\n headers.range = `bytes=${position}-`;\n }\n const args = {\n // @ts-expect-error private property\n ...this.baseOverrides,\n ...overrides,\n headers: {\n ...headers,\n ...overrides.headers,\n // @ts-expect-error private property\n ...this.baseOverrides.headers\n },\n method: 'GET',\n redirect: 'follow',\n mode: 'cors',\n signal\n };\n const response = await this.fetch(this.url, args);\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status} ${response.statusText} ${this.url}`);\n }\n\n // Just read the response if it was successful.\n if (response.status === 200 || response.status === 206) {\n // @ts-expect-error private method\n const responseData = await this.getBufferFromResponse(response);\n const bytesCopied = responseData.copy(buffer, offset, 0, Math.min(length, responseData.length));\n\n // try to parse out the size of the remote file\n const res = response.headers.get('content-range');\n const sizeMatch = /\\/(\\d+)$/.exec(res || '');\n if (sizeMatch && sizeMatch[1]) {\n // @ts-expect-error private property\n this._stat = { size: parseInt(sizeMatch[1], 10) };\n }\n\n return { bytesRead: bytesCopied, buffer };\n }\n\n // TODO: try harder here to gather more information about what the problem is\n throw new Error(`HTTP ${response.status} fetching ${this.url}`);\n };\n}\n\nexport interface TabularDataFetcher<Tile> {\n getTabularData(tileIds: string[]): Promise<Tile[]>;\n MAX_TILE_WIDTH?: number;\n}\n"],"names":["_RemoteFile"],"mappings":";;;;;;;;;AA6BO,SAAS,mBACZ,MACA,CAAC,MAAM,IAAI,GACX,QACF;AACE,QAAM,EAAE,GAAG,IAAI,IAAI,QAAQ;AACrB,QAAA,iBAAiB,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,OAAO,CAAA,MAAK,CAAC;AAC9C,SAAA,KAAK,OAAO,CAAC,MAAa;AACzB,QAAA,eAAe,WAAW,GAAG;AAEtB,aAAA;AAAA,IAAA,WACA,eAAe,WAAW,GAAG;AAEpC,YAAM,QAAQ,CAAC,EAAE,eAAe,CAAC,CAAC;AAClC,aAAO,OAAO,UAAU,YAAY,OAAO,SAAS,SAAS;AAAA,IAAA,OAC1D;AAEH,YAAM,SAAS,eAAe,IAAI,CAAA,MAAK,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAA,MAAK,CAAC,MAAM,CAAC,CAAC;AACnE,YAAM,WAAW,KAAK,IAAI,GAAG,MAAM;AACnC,YAAM,WAAW,KAAK,IAAI,GAAG,MAAM;AAC5B,aAAA,QAAQ,YAAY,YAAY;AAAA,IAC3C;AAAA,EAAA,CACH;AACL;AAE0B,SAAS,CAAC,MAAuB,EAAE,GAAG,EAAE;AA0ClD,SAAA,gBAAgB,SAAiB,UAAoB,kBAA2B;AACxF,MAAA,MAAM,QAAQ,QAAQ,GAAG;AAElB,WAAA;AAAA,EACX;AAGA,MAAI,kBAAkB;AA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tB,eAAA,QAAQ,EAAE,MAAM,SAAS,UAAU,CAAC,GAAG,EAAE;QAClD;AAEO,eAAA,EAAE,WAAW,aAAa;MACrC;AAGM,YAAA,IAAI,MAAM,QAAQ,SAAS,MAAM,aAAa,KAAK,GAAG,EAAE;AAAA,IAAA;AAAA;AAEtE;"}
@@ -1,2 +0,0 @@
1
- export { Buffer } from "buffer/";
2
- //# sourceMappingURL=buffer-shim.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buffer-shim.d.ts","sourceRoot":"","sources":["../../../src/alias/buffer-shim.js"],"names":[],"mappings":""}