@genobank/biofs 2.6.2 → 3.0.0
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.
- package/CHANGELOG.md +57 -0
- package/dist/commands/alias.d.ts +9 -0
- package/dist/commands/alias.d.ts.map +1 -0
- package/dist/commands/alias.js +56 -0
- package/dist/commands/alias.js.map +1 -0
- package/dist/commands/ancestry/compare.d.ts +9 -0
- package/dist/commands/ancestry/compare.d.ts.map +1 -0
- package/dist/commands/ancestry/compare.js +139 -0
- package/dist/commands/ancestry/compare.js.map +1 -0
- package/dist/commands/ancestry/results.d.ts +13 -0
- package/dist/commands/ancestry/results.d.ts.map +1 -0
- package/dist/commands/ancestry/results.js +123 -0
- package/dist/commands/ancestry/results.js.map +1 -0
- package/dist/commands/ancestry/run.d.ts +18 -0
- package/dist/commands/ancestry/run.d.ts.map +1 -0
- package/dist/commands/ancestry/run.js +171 -0
- package/dist/commands/ancestry/run.js.map +1 -0
- package/dist/commands/ancestry/status.d.ts +8 -0
- package/dist/commands/ancestry/status.d.ts.map +1 -0
- package/dist/commands/ancestry/status.js +59 -0
- package/dist/commands/ancestry/status.js.map +1 -0
- package/dist/commands/htsget.d.ts +8 -0
- package/dist/commands/htsget.d.ts.map +1 -0
- package/dist/commands/htsget.js +43 -0
- package/dist/commands/htsget.js.map +1 -0
- package/dist/commands/pipe.d.ts +8 -0
- package/dist/commands/pipe.d.ts.map +1 -0
- package/dist/commands/pipe.js +76 -0
- package/dist/commands/pipe.js.map +1 -0
- package/dist/commands/stream.d.ts +9 -0
- package/dist/commands/stream.d.ts.map +1 -0
- package/dist/commands/stream.js +58 -0
- package/dist/commands/stream.js.map +1 -0
- package/dist/index.js +170 -6
- package/dist/index.js.map +1 -1
- package/dist/lib/aliases/store.d.ts +7 -0
- package/dist/lib/aliases/store.d.ts.map +1 -0
- package/dist/lib/aliases/store.js +83 -0
- package/dist/lib/aliases/store.js.map +1 -0
- package/dist/lib/ancestry/somos-client.d.ts +64 -0
- package/dist/lib/ancestry/somos-client.d.ts.map +1 -0
- package/dist/lib/ancestry/somos-client.js +121 -0
- package/dist/lib/ancestry/somos-client.js.map +1 -0
- package/dist/lib/htsget/client.d.ts +54 -0
- package/dist/lib/htsget/client.d.ts.map +1 -0
- package/dist/lib/htsget/client.js +76 -0
- package/dist/lib/htsget/client.js.map +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
+
# v2.7.0 - htsget + smart streaming + aliases
|
|
2
|
+
|
|
3
|
+
**Published**: April 17, 2026
|
|
4
|
+
|
|
5
|
+
## What you get
|
|
6
|
+
|
|
7
|
+
Three new commands that make BioNFT-gated genomic data feel native to the
|
|
8
|
+
bioinformatics toolchain (bcftools, samtools, pysam, IGV) — zero FUSE, zero
|
|
9
|
+
kext, zero install friction on macOS.
|
|
10
|
+
|
|
11
|
+
- `biofs stream <id>` — stream a BioNFT-gated VCF/BAM to stdout via htsget.
|
|
12
|
+
Pipes cleanly into any bioinformatics CLI:
|
|
13
|
+
|
|
14
|
+
biofs stream my-wes | bcftools stats -
|
|
15
|
+
biofs stream my-wes | bcftools view -H -
|
|
16
|
+
|
|
17
|
+
- `biofs pipe <id> -- [tool-args]` — auto-pipe into bcftools (VCF) or
|
|
18
|
+
samtools (BAM). Format detected from registered filename:
|
|
19
|
+
|
|
20
|
+
biofs pipe my-wes -- -H -r chr17:1M-2M # bcftools view
|
|
21
|
+
biofs pipe my-bam -- -b # samtools view
|
|
22
|
+
|
|
23
|
+
- `biofs alias <name> <target>` — local shortcuts for ip_ids. Stored at
|
|
24
|
+
~/.biofs/aliases.json. Works across every command (stream, pipe, info,
|
|
25
|
+
download, mount).
|
|
26
|
+
|
|
27
|
+
biofs alias my-wes 0xCCe14315eE3D6a41596EeB4a2839eE50A8ec59f7
|
|
28
|
+
biofs stream my-wes | bcftools view -H -
|
|
29
|
+
|
|
30
|
+
## Low-level htsget (for debugging)
|
|
31
|
+
|
|
32
|
+
- `biofs htsget service-info` — GA4GH service-info JSON
|
|
33
|
+
- `biofs htsget ticket variants|reads <id>` — raw ticket
|
|
34
|
+
|
|
35
|
+
## Endpoints
|
|
36
|
+
|
|
37
|
+
- Dedicated subdomain: `https://htsget.genobank.app`
|
|
38
|
+
- Legacy path still works: `https://bioip.genobank.app/api_bioip/htsget/*`
|
|
39
|
+
- Override with `BIOFS_HTSGET_URL` env var.
|
|
40
|
+
|
|
41
|
+
## Auth
|
|
42
|
+
|
|
43
|
+
Uses the same `~/.biofs/credentials.json` from `biofs login`. Bearer-token
|
|
44
|
+
auth against the htsget endpoint; server verifies the EIP-191 signature of
|
|
45
|
+
"I want to proceed" on every request.
|
|
46
|
+
|
|
47
|
+
## Compatibility
|
|
48
|
+
|
|
49
|
+
- All existing commands unchanged
|
|
50
|
+
- `view` command retained (prints file content); `pipe` is the new
|
|
51
|
+
bioinformatics-tool wrapper
|
|
52
|
+
- No breaking changes to config files or credentials
|
|
53
|
+
|
|
54
|
+
## Dependencies
|
|
55
|
+
|
|
56
|
+
No new npm dependencies. Uses Node 18+ built-in `fetch` for htsget calls.
|
|
57
|
+
|
|
1
58
|
# v2.6.2 - GCS Migration
|
|
2
59
|
|
|
3
60
|
**Published**: April 16, 2026
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alias.d.ts","sourceRoot":"","sources":["../../src/commands/alias.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,YAAY,CAAC,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6CzE"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.aliasCommand = aliasCommand;
|
|
4
|
+
/**
|
|
5
|
+
* `biofs alias` — manage local aliases for ip_ids / BioCIDs.
|
|
6
|
+
*
|
|
7
|
+
* biofs alias # list (default)
|
|
8
|
+
* biofs alias my-wes 0xCCe14315…
|
|
9
|
+
* biofs alias --remove my-wes
|
|
10
|
+
*/
|
|
11
|
+
const logger_1 = require("../lib/utils/logger");
|
|
12
|
+
const store_1 = require("../lib/aliases/store");
|
|
13
|
+
async function aliasCommand(opts = {}) {
|
|
14
|
+
const aliases = (0, store_1.loadAliases)();
|
|
15
|
+
// List mode — default when no args OR --list
|
|
16
|
+
if (opts.list || (!opts.name && !opts.remove)) {
|
|
17
|
+
if (opts.json) {
|
|
18
|
+
process.stdout.write(JSON.stringify(aliases, null, 2) + '\n');
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (Object.keys(aliases).length === 0) {
|
|
22
|
+
logger_1.Logger.info(`no aliases defined (${(0, store_1.aliasFilePath)()})`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const maxName = Math.max(...Object.keys(aliases).map((k) => k.length), 5);
|
|
26
|
+
console.log(`${'ALIAS'.padEnd(maxName)} TARGET`);
|
|
27
|
+
for (const k of Object.keys(aliases).sort()) {
|
|
28
|
+
console.log(`${k.padEnd(maxName)} ${aliases[k]}`);
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// Remove mode
|
|
33
|
+
if (opts.remove) {
|
|
34
|
+
if (!(opts.remove in aliases)) {
|
|
35
|
+
logger_1.Logger.error(`no such alias: ${opts.remove}`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
delete aliases[opts.remove];
|
|
39
|
+
(0, store_1.saveAliases)(aliases);
|
|
40
|
+
logger_1.Logger.info(`removed alias '${opts.remove}'`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// Add mode — require both name and target
|
|
44
|
+
if (!opts.target) {
|
|
45
|
+
logger_1.Logger.error('usage: biofs alias <name> <ip_id_or_biocid>');
|
|
46
|
+
process.exit(2);
|
|
47
|
+
}
|
|
48
|
+
if (opts.name.startsWith('0x') || opts.name.startsWith('biocid://')) {
|
|
49
|
+
logger_1.Logger.error(`alias name '${opts.name}' looks like an id — pick something human-friendly`);
|
|
50
|
+
process.exit(2);
|
|
51
|
+
}
|
|
52
|
+
aliases[opts.name] = opts.target;
|
|
53
|
+
(0, store_1.saveAliases)(aliases);
|
|
54
|
+
logger_1.Logger.info(`alias '${opts.name}' → ${opts.target} (${(0, store_1.aliasFilePath)()})`);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=alias.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alias.js","sourceRoot":"","sources":["../../src/commands/alias.ts"],"names":[],"mappings":";;AAkBA,oCA6CC;AA/DD;;;;;;GAMG;AACH,gDAA6C;AAC7C,gDAA+E;AAUxE,KAAK,UAAU,YAAY,CAAC,OAAqB,EAAE;IACxD,MAAM,OAAO,GAAG,IAAA,mBAAW,GAAE,CAAC;IAE9B,6CAA6C;IAC7C,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;YAC9D,OAAO;QACT,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtC,eAAM,CAAC,IAAI,CAAC,uBAAuB,IAAA,qBAAa,GAAE,GAAG,CAAC,CAAC;YACvD,OAAO;QACT,CAAC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CAAC,IAAK,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QACtE,eAAM,CAAC,KAAK,CAAC,eAAe,IAAI,CAAC,IAAI,oDAAoD,CAAC,CAAC;QAC3F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,IAAK,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IAClC,IAAA,mBAAW,EAAC,OAAO,CAAC,CAAC;IACrB,eAAM,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,MAAM,MAAM,IAAA,qBAAa,GAAE,GAAG,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* biofs ancestry compare <task_id> <reference_csv>
|
|
3
|
+
*
|
|
4
|
+
* Compare a Somos K=24 result against a baseline CSV (e.g., LANGEBIO K=36
|
|
5
|
+
* report regrouped to the 5 super-regions). Prints a side-by-side table
|
|
6
|
+
* with per-region deltas.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ancestryCompareCommand(taskId: string, referenceCsv: string): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/commands/ancestry/compare.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CA6Ff"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* biofs ancestry compare <task_id> <reference_csv>
|
|
4
|
+
*
|
|
5
|
+
* Compare a Somos K=24 result against a baseline CSV (e.g., LANGEBIO K=36
|
|
6
|
+
* report regrouped to the 5 super-regions). Prints a side-by-side table
|
|
7
|
+
* with per-region deltas.
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.ancestryCompareCommand = ancestryCompareCommand;
|
|
47
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
48
|
+
const fs = __importStar(require("fs-extra"));
|
|
49
|
+
const axios_1 = __importDefault(require("axios"));
|
|
50
|
+
const logger_1 = require("../../lib/utils/logger");
|
|
51
|
+
const somos_client_1 = require("../../lib/ancestry/somos-client");
|
|
52
|
+
async function ancestryCompareCommand(taskId, referenceCsv) {
|
|
53
|
+
try {
|
|
54
|
+
// Fetch live results
|
|
55
|
+
const client = new somos_client_1.SomosClient();
|
|
56
|
+
const r = await client.results(taskId);
|
|
57
|
+
if (!r.success) {
|
|
58
|
+
logger_1.Logger.error(r.error || 'results not ready');
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
const csvUrl = r.results_signed?.csv || r.results?.csv;
|
|
62
|
+
if (!csvUrl) {
|
|
63
|
+
logger_1.Logger.error('No CSV result available');
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
const { data: csvText } = await axios_1.default.get(csvUrl, {
|
|
67
|
+
timeout: 20000,
|
|
68
|
+
transformResponse: x => x,
|
|
69
|
+
});
|
|
70
|
+
const liveRow = {};
|
|
71
|
+
const lines = String(csvText).trim().split(/\r?\n/);
|
|
72
|
+
const values = lines[1].split(',').map(x => parseFloat(x));
|
|
73
|
+
somos_client_1.ANCESTRY_HEADER_24.forEach((col, i) => (liveRow[col] = values[i]));
|
|
74
|
+
const liveGrouped = (0, somos_client_1.groupTo5Regions)(liveRow);
|
|
75
|
+
// Load reference CSV.
|
|
76
|
+
// Expected format (header + one row OR key,value pairs):
|
|
77
|
+
// Indigenous American,0.373
|
|
78
|
+
// European,0.371
|
|
79
|
+
// African,0.060
|
|
80
|
+
// ...
|
|
81
|
+
if (!(await fs.pathExists(referenceCsv))) {
|
|
82
|
+
logger_1.Logger.error(`reference not found: ${referenceCsv}`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
const refText = await fs.readFile(referenceCsv, 'utf-8');
|
|
86
|
+
const refGrouped = {};
|
|
87
|
+
for (const line of refText.trim().split(/\r?\n/)) {
|
|
88
|
+
const parts = line.split(',').map(s => s.trim());
|
|
89
|
+
if (parts.length < 2)
|
|
90
|
+
continue;
|
|
91
|
+
const key = parts[0];
|
|
92
|
+
const v = parseFloat(parts[1]);
|
|
93
|
+
if (!Number.isNaN(v))
|
|
94
|
+
refGrouped[key] = v;
|
|
95
|
+
}
|
|
96
|
+
// Side-by-side
|
|
97
|
+
console.log('');
|
|
98
|
+
console.log(chalk_1.default.bold(`Comparison — ${taskId} vs ${referenceCsv}`));
|
|
99
|
+
console.log('');
|
|
100
|
+
console.log(' ' +
|
|
101
|
+
'Region'.padEnd(42) +
|
|
102
|
+
'Somos K=24'.padStart(12) +
|
|
103
|
+
'Reference'.padStart(12) +
|
|
104
|
+
'Δ'.padStart(10));
|
|
105
|
+
console.log(' ' + '─'.repeat(76));
|
|
106
|
+
const allKeys = new Set([...Object.keys(liveGrouped), ...Object.keys(refGrouped)]);
|
|
107
|
+
let maxDelta = 0;
|
|
108
|
+
for (const k of allKeys) {
|
|
109
|
+
const live = liveGrouped[k] ?? 0;
|
|
110
|
+
const ref = refGrouped[k] ?? 0;
|
|
111
|
+
const delta = live - ref;
|
|
112
|
+
if (Math.abs(delta) > Math.abs(maxDelta))
|
|
113
|
+
maxDelta = delta;
|
|
114
|
+
const deltaStr = (delta * 100).toFixed(2).padStart(8) + '%';
|
|
115
|
+
const color = Math.abs(delta) < 0.01
|
|
116
|
+
? chalk_1.default.green
|
|
117
|
+
: Math.abs(delta) < 0.03
|
|
118
|
+
? chalk_1.default.yellow
|
|
119
|
+
: chalk_1.default.red;
|
|
120
|
+
console.log(' ' +
|
|
121
|
+
k.padEnd(42) +
|
|
122
|
+
`${(live * 100).toFixed(2)}%`.padStart(12) +
|
|
123
|
+
`${(ref * 100).toFixed(2)}%`.padStart(12) +
|
|
124
|
+
color(deltaStr.padStart(10)));
|
|
125
|
+
}
|
|
126
|
+
console.log('');
|
|
127
|
+
const verdict = Math.abs(maxDelta) < 0.01
|
|
128
|
+
? chalk_1.default.green('✓ Excellent match (max Δ < 1%)')
|
|
129
|
+
: Math.abs(maxDelta) < 0.03
|
|
130
|
+
? chalk_1.default.yellow('✓ Acceptable match (max Δ < 3%)')
|
|
131
|
+
: chalk_1.default.red('✗ Significant divergence — verify reference panel');
|
|
132
|
+
console.log(` Verdict: ${verdict} (max Δ = ${(maxDelta * 100).toFixed(2)}%)`);
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
logger_1.Logger.error(`compare failed: ${e.response?.data?.error || e.message}`);
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../src/commands/ancestry/compare.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYH,wDAgGC;AA1GD,kDAA0B;AAC1B,6CAA+B;AAC/B,kDAA0B;AAC1B,mDAAgD;AAChD,kEAIyC;AAElC,KAAK,UAAU,sBAAsB,CAC1C,MAAc,EACd,YAAoB;IAEpB,IAAI,CAAC;QACH,qBAAqB;QACrB,MAAM,MAAM,GAAG,IAAI,0BAAW,EAAE,CAAC;QACjC,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;YACf,eAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,mBAAmB,CAAC,CAAC;YAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,MAAM,MAAM,GAAG,CAAC,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,CAAC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E,CAAC,CAAC;QAChB,MAAM,OAAO,GACX,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI;YACvB,CAAC,CAAC,eAAK,CAAC,KAAK,CAAC,gCAAgC,CAAC;YAC/C,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI;gBAC3B,CAAC,CAAC,eAAK,CAAC,MAAM,CAAC,iCAAiC,CAAC;gBACjD,CAAC,CAAC,eAAK,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;QACrE,OAAO,CAAC,GAAG,CAAC,cAAc,OAAO,eAAe,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACnF,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,eAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* biofs ancestry results <task_id>
|
|
3
|
+
*
|
|
4
|
+
* Fetch the signed CSV result and pretty-print, or download all artifacts
|
|
5
|
+
* locally with --download.
|
|
6
|
+
*/
|
|
7
|
+
export interface AncestryResultsOptions {
|
|
8
|
+
json?: boolean;
|
|
9
|
+
download?: string;
|
|
10
|
+
summary?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function ancestryResultsCommand(taskId: string, options?: AncestryResultsOptions): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=results.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../../../src/commands/ancestry/results.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,IAAI,CAAC,CAkFf"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* biofs ancestry results <task_id>
|
|
4
|
+
*
|
|
5
|
+
* Fetch the signed CSV result and pretty-print, or download all artifacts
|
|
6
|
+
* locally with --download.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.ancestryResultsCommand = ancestryResultsCommand;
|
|
46
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
47
|
+
const ora_1 = __importDefault(require("ora"));
|
|
48
|
+
const fs = __importStar(require("fs-extra"));
|
|
49
|
+
const path = __importStar(require("path"));
|
|
50
|
+
const axios_1 = __importDefault(require("axios"));
|
|
51
|
+
const logger_1 = require("../../lib/utils/logger");
|
|
52
|
+
const somos_client_1 = require("../../lib/ancestry/somos-client");
|
|
53
|
+
async function ancestryResultsCommand(taskId, options = {}) {
|
|
54
|
+
const client = new somos_client_1.SomosClient();
|
|
55
|
+
const spinner = (0, ora_1.default)('Fetching results...').start();
|
|
56
|
+
try {
|
|
57
|
+
const r = await client.results(taskId);
|
|
58
|
+
if (!r.success) {
|
|
59
|
+
spinner.fail(r.error || 'results not ready');
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
const signed = r.results_signed || {};
|
|
63
|
+
const uris = r.results || {};
|
|
64
|
+
spinner.succeed('Results retrieved');
|
|
65
|
+
if (options.download) {
|
|
66
|
+
await fs.ensureDir(options.download);
|
|
67
|
+
for (const [key, url] of Object.entries(signed)) {
|
|
68
|
+
const ext = key === 'summary' ? '.txt' : `.${key}`;
|
|
69
|
+
const out = path.join(options.download, `${taskId}${ext}`);
|
|
70
|
+
const { data } = await axios_1.default.get(url, { responseType: 'stream', timeout: 60000 });
|
|
71
|
+
await new Promise((resolve, reject) => {
|
|
72
|
+
const w = fs.createWriteStream(out);
|
|
73
|
+
data.pipe(w);
|
|
74
|
+
w.on('finish', () => resolve());
|
|
75
|
+
w.on('error', reject);
|
|
76
|
+
});
|
|
77
|
+
console.log(` ↓ ${chalk_1.default.green(out)}`);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const csvUrl = signed.csv || uris.csv;
|
|
82
|
+
if (!csvUrl) {
|
|
83
|
+
logger_1.Logger.error('No CSV result available yet');
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
const { data: csvText } = await axios_1.default.get(csvUrl, {
|
|
87
|
+
timeout: 20000,
|
|
88
|
+
transformResponse: x => x,
|
|
89
|
+
});
|
|
90
|
+
const lines = String(csvText).trim().split(/\r?\n/);
|
|
91
|
+
const values = lines[1].split(',').map(x => parseFloat(x));
|
|
92
|
+
const row = {};
|
|
93
|
+
somos_client_1.ANCESTRY_HEADER_24.forEach((col, i) => (row[col] = values[i]));
|
|
94
|
+
if (options.json) {
|
|
95
|
+
console.log(JSON.stringify({ task_id: taskId, ancestry: row, grouped: (0, somos_client_1.groupTo5Regions)(row) }, null, 2));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (!options.summary) {
|
|
99
|
+
console.log('');
|
|
100
|
+
console.log(chalk_1.default.bold(`24-population ancestry — ${taskId}`));
|
|
101
|
+
const sorted = Object.entries(row).sort((a, b) => b[1] - a[1]);
|
|
102
|
+
for (const [pop, v] of sorted) {
|
|
103
|
+
const pct = (v * 100).toFixed(2);
|
|
104
|
+
const bar = '█'.repeat(Math.max(0, Math.min(40, Math.round(v * 80))));
|
|
105
|
+
const color = v >= 0.1 ? chalk_1.default.green : v >= 0.02 ? chalk_1.default.cyan : chalk_1.default.gray;
|
|
106
|
+
console.log(` ${pop.padEnd(14)} ${pct.padStart(5)}% ${color(bar)}`);
|
|
107
|
+
}
|
|
108
|
+
console.log('');
|
|
109
|
+
}
|
|
110
|
+
console.log(chalk_1.default.bold('Grouped into 5 super-regions'));
|
|
111
|
+
const grouped = (0, somos_client_1.groupTo5Regions)(row);
|
|
112
|
+
for (const [region, v] of Object.entries(grouped).sort((a, b) => b[1] - a[1])) {
|
|
113
|
+
const pct = (v * 100).toFixed(2);
|
|
114
|
+
const bar = '█'.repeat(Math.max(0, Math.min(40, Math.round(v * 80))));
|
|
115
|
+
console.log(` ${region.padEnd(40)} ${pct.padStart(5)}% ${chalk_1.default.cyan(bar)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
spinner.fail(`results failed: ${e.response?.data?.error || e.message}`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=results.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../../../src/commands/ancestry/results.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBH,wDAqFC;AAvGD,kDAA0B;AAC1B,8CAAsB;AACtB,6CAA+B;AAC/B,2CAA6B;AAC7B,kDAA0B;AAC1B,mDAAgD;AAChD,kEAIyC;AAQlC,KAAK,UAAU,sBAAsB,CAC1C,MAAc,EACd,UAAkC,EAAE;IAEpC,MAAM,MAAM,GAAG,IAAI,0BAAW,EAAE,CAAC;IACjC,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC,qBAAqB,CAAC,CAAC,KAAK,EAAE,CAAC;IAEnD,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,mBAAmB,CAAC,CAAC;Y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EAAC,GAAU,CAAC,CAAC;QAC5C,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9E,MAAM,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACjC,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACtE,OAAO,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* biofs ancestry run <dtc_file>
|
|
3
|
+
*
|
|
4
|
+
* Upload a DTC genotype file to the GenoBank GCS bucket and kick off a
|
|
5
|
+
* Somos v3.0 ancestry analysis (PLINK + ADMIXTURE K=24 supervised against the
|
|
6
|
+
* 781-individual, 24-population reference panel).
|
|
7
|
+
*
|
|
8
|
+
* Use --wait to poll status until completion and print the results inline.
|
|
9
|
+
*/
|
|
10
|
+
export interface AncestryRunOptions {
|
|
11
|
+
userId?: string;
|
|
12
|
+
wait?: boolean;
|
|
13
|
+
pollSeconds?: string;
|
|
14
|
+
callbackUrl?: string;
|
|
15
|
+
json?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function ancestryRunCommand(dtcFile: string, options?: AncestryRunOptions): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/commands/ancestry/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CA8Ff"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* biofs ancestry run <dtc_file>
|
|
4
|
+
*
|
|
5
|
+
* Upload a DTC genotype file to the GenoBank GCS bucket and kick off a
|
|
6
|
+
* Somos v3.0 ancestry analysis (PLINK + ADMIXTURE K=24 supervised against the
|
|
7
|
+
* 781-individual, 24-population reference panel).
|
|
8
|
+
*
|
|
9
|
+
* Use --wait to poll status until completion and print the results inline.
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.ancestryRunCommand = ancestryRunCommand;
|
|
49
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
50
|
+
const ora_1 = __importDefault(require("ora"));
|
|
51
|
+
const fs = __importStar(require("fs-extra"));
|
|
52
|
+
const credentials_1 = require("../../lib/auth/credentials");
|
|
53
|
+
const logger_1 = require("../../lib/utils/logger");
|
|
54
|
+
const somos_client_1 = require("../../lib/ancestry/somos-client");
|
|
55
|
+
async function ancestryRunCommand(dtcFile, options = {}) {
|
|
56
|
+
if (!(await fs.pathExists(dtcFile))) {
|
|
57
|
+
logger_1.Logger.error(`File not found: ${dtcFile}`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
const creds = await credentials_1.CredentialsManager.getInstance().loadCredentials();
|
|
61
|
+
if (!creds && !options.userId) {
|
|
62
|
+
logger_1.Logger.error('Not authenticated. Run `biofs login` or pass --user-id.');
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
const userId = options.userId || creds.wallet_address;
|
|
66
|
+
const client = new somos_client_1.SomosClient();
|
|
67
|
+
const spinner = (0, ora_1.default)('Uploading DTC file to GCS...').start();
|
|
68
|
+
// Step 1: allocate a task_id + upload input ----------------------
|
|
69
|
+
// We ask the server to allocate; we accept the task_id it returns via trigger.
|
|
70
|
+
// But we need to upload BEFORE trigger so the worker can read it. Strategy:
|
|
71
|
+
// 1. Generate a client-side task_id.
|
|
72
|
+
// 2. Upload to raw-data/{user}/{task}/{file}.
|
|
73
|
+
// 3. Call /trigger with that task_id.
|
|
74
|
+
// If the server already allocated a different task_id during trigger, we still
|
|
75
|
+
// work because /trigger accepts input_gcs_path (copies into canonical location).
|
|
76
|
+
const filename = require('path').basename(dtcFile);
|
|
77
|
+
const provisionalTaskId = `biofs-${Date.now().toString(36)}`;
|
|
78
|
+
try {
|
|
79
|
+
const uploaded = await client.uploadRaw(dtcFile, userId, provisionalTaskId);
|
|
80
|
+
spinner.succeed(`Uploaded → ${chalk_1.default.gray(uploaded.uri)}`);
|
|
81
|
+
spinner.start('Triggering Somos v3.0 pipeline (ADMIXTURE K=24 supervised)...');
|
|
82
|
+
const trig = await client.trigger({
|
|
83
|
+
filename,
|
|
84
|
+
user_id: userId,
|
|
85
|
+
input_gcs_path: uploaded.uri,
|
|
86
|
+
callback_url: options.callbackUrl,
|
|
87
|
+
});
|
|
88
|
+
spinner.succeed(`Task started: ${chalk_1.default.cyan(trig.task_id)}`);
|
|
89
|
+
console.log('');
|
|
90
|
+
console.log(chalk_1.default.bold('Somos Ancestry v3.0 — job submitted'));
|
|
91
|
+
console.log(` task_id: ${chalk_1.default.cyan(trig.task_id)}`);
|
|
92
|
+
console.log(` user_id: ${userId}`);
|
|
93
|
+
console.log(` filename: ${filename}`);
|
|
94
|
+
console.log(` input_uri: ${chalk_1.default.gray(trig.input_uri)}`);
|
|
95
|
+
console.log(` status: ${chalk_1.default.yellow(trig.status)}`);
|
|
96
|
+
console.log(` estimated: ${trig.estimated_time}`);
|
|
97
|
+
console.log('');
|
|
98
|
+
if (!options.wait) {
|
|
99
|
+
console.log(`Next: ${chalk_1.default.cyan(`biofs ancestry status ${trig.task_id}`)} to check progress`);
|
|
100
|
+
console.log(` ${chalk_1.default.cyan(`biofs ancestry results ${trig.task_id}`)} when finished`);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// --wait path --------------------------------------------------
|
|
104
|
+
const pollMs = Math.max(10, parseInt(options.pollSeconds || '30', 10)) * 1000;
|
|
105
|
+
const waitSpinner = (0, ora_1.default)('Waiting for ADMIXTURE to finish (30-60 minutes typical)...').start();
|
|
106
|
+
const start = Date.now();
|
|
107
|
+
while (true) {
|
|
108
|
+
await new Promise(r => setTimeout(r, pollMs));
|
|
109
|
+
const s = await client.status(trig.task_id);
|
|
110
|
+
const elapsed = Math.floor((Date.now() - start) / 1000);
|
|
111
|
+
waitSpinner.text = `[${elapsed}s] status=${s.status}`;
|
|
112
|
+
if (s.status === 'STOPPED') {
|
|
113
|
+
if (s.exit_code === 0) {
|
|
114
|
+
waitSpinner.succeed(`Completed in ${elapsed}s`);
|
|
115
|
+
await printResults(trig.task_id, client, options.json === true);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
waitSpinner.fail(`Pipeline failed (exit=${s.exit_code}): ${s.error || 'unknown'}`);
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
spinner.fail(`Ancestry run failed: ${e.response?.data?.error || e.message}`);
|
|
125
|
+
if (e.response?.data) {
|
|
126
|
+
logger_1.Logger.debug(JSON.stringify(e.response.data, null, 2));
|
|
127
|
+
}
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function printResults(taskId, client, asJson) {
|
|
132
|
+
const r = await client.results(taskId);
|
|
133
|
+
if (!r.success) {
|
|
134
|
+
logger_1.Logger.error(`results not ready: ${r.error}`);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const csvUrl = r.results_signed?.csv || r.results?.csv;
|
|
138
|
+
if (!csvUrl) {
|
|
139
|
+
console.log(chalk_1.default.yellow('(no CSV result yet)'));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const axios = (await Promise.resolve().then(() => __importStar(require('axios')))).default;
|
|
143
|
+
const { data: csvText } = await axios.get(csvUrl, {
|
|
144
|
+
timeout: 20000,
|
|
145
|
+
transformResponse: x => x,
|
|
146
|
+
});
|
|
147
|
+
const lines = String(csvText).trim().split(/\r?\n/);
|
|
148
|
+
const values = lines[1].split(',').map(x => parseFloat(x));
|
|
149
|
+
const row = {};
|
|
150
|
+
somos_client_1.ANCESTRY_HEADER_24.forEach((col, i) => (row[col] = values[i]));
|
|
151
|
+
if (asJson) {
|
|
152
|
+
console.log(JSON.stringify({ task_id: taskId, ancestry: row }, null, 2));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
console.log('');
|
|
156
|
+
console.log(chalk_1.default.bold('24-population ancestry (Somos K=24 supervised)'));
|
|
157
|
+
const sorted = Object.entries(row).sort((a, b) => b[1] - a[1]);
|
|
158
|
+
for (const [pop, v] of sorted) {
|
|
159
|
+
const pct = (v * 100).toFixed(2);
|
|
160
|
+
const bar = '█'.repeat(Math.max(0, Math.min(40, Math.round(v * 80))));
|
|
161
|
+
const color = v >= 0.1 ? chalk_1.default.green : v >= 0.02 ? chalk_1.default.cyan : chalk_1.default.gray;
|
|
162
|
+
console.log(` ${pop.padEnd(14)} ${pct.padStart(5)}% ${color(bar)}`);
|
|
163
|
+
}
|
|
164
|
+
console.log('');
|
|
165
|
+
console.log(chalk_1.default.bold('Grouped into 5 super-regions'));
|
|
166
|
+
const grouped = (0, somos_client_1.groupTo5Regions)(row);
|
|
167
|
+
for (const [region, v] of Object.entries(grouped).sort((a, b) => b[1] - a[1])) {
|
|
168
|
+
console.log(` ${region.padEnd(40)} ${(v * 100).toFixed(2)}%`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=run.js.map
|