hyphy-scope
Version:
Reusable Svelte components for HyPhy analysis visualization
234 lines (233 loc) • 6.52 kB
TypeScript
/**
* ABSREL (Adaptive Branch-Site Random Effects Likelihood) utility functions
*
* ABSREL tests whether a gene has experienced positive selection,
* without requiring a priori specification of lineages.
*/
export interface AbsrelSiteData {
site: number;
partition: number;
[branchName: string]: number;
}
export interface AbsrelBranchData {
name: string;
'Rate classes': number;
'Uncorrected P-value': number;
'Corrected P-value': number;
'Bayes Factor': number;
'ω distribution': Array<{
'rate class': number;
omega: number;
weight: number;
}>;
}
export interface AbsrelResults {
sequences: number;
sites: number;
'branches tested': number;
'branches with selection': number;
'p-value threshold': number;
'test results': {
[branchName: string]: {
'Rate classes': number;
'Uncorrected P-value': number;
'Corrected P-value': number;
'Bayes Factor': number;
};
};
'Site Log Likelihood': {
tested: {
[branchName: string]: number[][];
};
};
'branch attributes': {
[branchName: string]: {
[attribute: string]: any;
};
};
fits: {
'Baseline model': {
'log-likelihood': number;
AIC: number;
parameters: number;
};
'Full adaptive model': {
'log-likelihood': number;
AIC: number;
parameters: number;
};
};
'Synonymous site-posteriors'?: {
[branchName: string]: number[][];
};
}
/**
* Extract summary statistics from ABSREL results
*/
export declare function getAbsrelSummary(data: AbsrelResults | any): {
sequences: any;
sites: any;
branchesTested: any;
branchesWithSelection: any;
pValueThreshold: any;
baselineLogLikelihood: any;
fullModelLogLikelihood: any;
lrt: number;
baselineAIC: any;
fullModelAIC: any;
};
/**
* Get tested branches with their selection results
*/
export declare function getTestedBranches(data: AbsrelResults | any): AbsrelBranchData[];
/**
* Get site-level log likelihood data for visualization
*/
export declare function getAbsrelSiteData(data: AbsrelResults | any): AbsrelSiteData[];
/**
* Filter branches by significance
*/
export declare function getSignificantBranches(branches: AbsrelBranchData[], pValueThreshold?: number): AbsrelBranchData[];
/**
* Get table headers for ABSREL results
*/
export declare function getAbsrelTableHeaders(): Array<{
key: string;
label: string;
sortable: boolean;
}>;
/**
* Format numeric values for display
*/
export declare function formatAbsrelValue(value: any, key: string): string;
/**
* Get color for p-value significance
*/
export declare function getPValueColor(pValue: number, threshold?: number): string;
/**
* Extract synonymous site posteriors if available
*/
export declare function getSynonymousSitePosteriors(data: AbsrelResults): {
[branchName: string]: number[][];
};
/**
* Calculate evidence ratio for branches
*/
export declare function calculateEvidenceRatio(bayesFactor: number): number;
/**
* Extract comprehensive attributes from aBSREL results for visualization
*/
export interface AbsrelAttributes {
positiveResults: number;
pvalueThreshold: number;
profilableBranches: Set<string>;
testedBranchCount: number;
srvRateClasses: number;
srvDistribution: Array<{
value: number;
weight: number;
}> | null;
omegaRateClasses: number[];
mhRates: {
DH: number;
TH: number;
};
profileBranchSites: AbsrelProfileSite[];
numberOfSequences: number;
numberOfSites: number;
numberOfPartitions: number;
partitionSizes: number[];
}
export interface AbsrelProfileSite {
Key: string;
branch: string;
site: number;
ER: number;
subs: number;
from: string;
to: string;
syn_subs: number;
nonsyn_subs: number;
}
export interface AbsrelBranchSiteData {
Key: string;
Posterior: number;
ER: number;
subs: number;
from: string;
to: string;
syn_subs: number;
nonsyn_subs: number;
}
export interface AbsrelDistributionTableRow {
branch: string;
tested: string;
'p-value': number | null;
sites: number | null;
rates: number;
dist: [string, Array<{
value: number;
weight: number;
}>, string];
plot: [string, Array<{
value: number;
weight: number;
}>];
}
/**
* Extract comprehensive attributes from ABSREL results
*/
export declare function getAbsrelAttributes(resultsJson: any): AbsrelAttributes;
/**
* Profile branch sites by calculating metrics based on log likelihoods
*/
export declare function getAbsrelProfileBranchSites(resultsJson: any): AbsrelProfileSite[];
/**
* Create table specs for tile display
*/
export declare function getAbsrelTileSpecs(resultsJson: any, evThreshold: number, distributionTable: AbsrelDistributionTableRow[]): any[];
/**
* Get rate distribution for a branch
*/
export declare function getAbsrelTestOmega(resultsJson: any, branch: string): Array<{
value: number;
weight: number;
}>;
/**
* Get site index to partition and codon mapping
*/
export declare function getAbsrelSiteIndexPartitionCodon(resultsJson: any): Array<[number, number]>;
/**
* Get branch color options for tree visualization
*/
export declare function getAbsrelTreeColorOptions(resultsJson: any, evThreshold: number): string[];
/**
* Tree configuration options for ABSREL visualization
*/
export interface AbsrelTreeOptions {
branchLabels?: boolean;
neighbors?: boolean;
height?: number;
width?: number;
alignTips?: boolean;
showScale?: boolean;
isRadial?: boolean;
showInternal?: boolean;
colorBranches?: string;
branchLength?: string;
evThreshold?: number;
}
/**
* Create tree configuration for ABSREL visualization
*/
export declare function createAbsrelTreeConfig(resultsJson: any, partitionIndex?: number, options?: AbsrelTreeOptions): any;
/**
* Get distribution table for branches
*/
export declare function getAbsrelDistributionTable(resultsJson: any, evThreshold: number): AbsrelDistributionTableRow[];
/**
* Generate site table data for detailed analysis
*/
export declare function getAbsrelSiteTableData(resultsJson: any, evThreshold: number, profileBranchSites?: AbsrelProfileSite[]): [any[], {
[key: string]: any;
}];