gwas

package
v0.0.0-...-db52ea4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2024 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CPMatMult0

func CPMatMult0(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense) crypto.CipherMatrix

Cheat to compute ground truth

func CPMatMult1

func CPMatMult1(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense) crypto.CipherMatrix

All-pairwise inner product version

func CPMatMult2

func CPMatMult2(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense) crypto.CipherMatrix

Duplicate individual elements in A

func CPMatMult2F

func CPMatMult2F(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense) crypto.CipherMatrix

Duplicate individual elements in A

func CPMatMult3

func CPMatMult3(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense) crypto.CipherMatrix

Pre-rotate A, all shifts, mult with diagonals from B

func CPMatMult4

func CPMatMult4(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense, maxLevel int) crypto.CipherMatrix

Pre-rotate A, baby step giant step version, mult with diagonals from B

func CPMatMult4CachedB

func CPMatMult4CachedB(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, CachedB PlainMatrixDiagCache) crypto.CipherMatrix

func CPMatMult4V2CachedB

func CPMatMult4V2CachedB(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, maxLevel int, CachedB PlainMatrixDiagCache) crypto.CipherMatrix

Generalized to levels >= 2

func CPMultAccWithoutMRedV1

func CPMultAccWithoutMRedV1(cryptoParams *crypto.CryptoParams, X crypto.CipherVector, Y crypto.PlainVector, Acc CipherVectorAccV1)

Multiply X and Y to add to Acc without modular reduction

func CPMultAccWithoutMRedV2

func CPMultAccWithoutMRedV2(X crypto.CipherVector, Y crypto.PlainVector, Acc CipherVectorAccV2)

func DCMatMulAAtB

func DCMatMulAAtB(cryptoParams *crypto.CryptoParams, mpcObj *mpc.MPC, A crypto.CipherMatrix, B crypto.CipherMatrix,
	nrows []int, ncol_out int, innerFn matmulInnerFn) crypto.CipherMatrix

func DCMatMulAAtBPlain

func DCMatMulAAtBPlain(cryptoParams *crypto.CryptoParams, mpcObj *mpc.MPC, A crypto.CipherMatrix, B crypto.PlainMatrix,
	nrows []int, ncol_out int, innerFn matmulPlainInnerFn) crypto.CipherMatrix

func EncodeDiag

func EncodeDiag(cryptoParams *crypto.CryptoParams, X BlockVector, index int, nrot int, level int) (crypto.PlainVector, bool)

index specifies which diagonal to extract applies right-rotation by nrot positions before encoding

func EncodeDiagBool

func EncodeDiagBool(X BlockVector, index int, slots int) bool

Return if a diagonal vector exists without extracting/encoding the vectors

func EncodeDiagWithEncoder

func EncodeDiagWithEncoder(cryptoParams *crypto.CryptoParams, X BlockVector, index int, nrot int, level int, enc ckks.Encoder) (crypto.PlainVector, bool)

func FilterMat

func FilterMat(X *mat.Dense, colkeep, rowkeep []bool) *mat.Dense

func FilterMatrixFile

func FilterMatrixFile(inputFile string, nrows, ncols int, rowFilt, colFilt []bool, outputFile string)

func FilterMatrixFilePgen

func FilterMatrixFilePgen(pgenPrefix string, nrows, ncols int, rowFiltFile, colNamesFile string, colStartPos int, colFilt []bool, outputFile string)

func FilterVec

func FilterVec(vec *mat.Dense, keep []bool) *mat.Dense

func GetDiag

func GetDiag(dst []float64, X Block, dim int, index int) bool

index 0 is the main diagonal max size of Block is dim by dim and index ranges from 0 to dim-1 (mod dim) If given diagonal does not overlap with X (matrix might be smaller), returns false

func GetDiagBool

func GetDiagBool(X Block, dim int, index int) bool

Return if a diagonal vector exists without extracting elements

func LoadCacheFromFile

func LoadCacheFromFile(cps *crypto.CryptoParams, filename string) crypto.CipherMatrix

func LoadFloatVectorFromFile

func LoadFloatVectorFromFile(filename string, n int) []float64

func LoadMatrixFromFile

func LoadMatrixFromFile(filename string, delim rune) *mat.Dense

func LoadMatrixFromFileFloat

func LoadMatrixFromFileFloat(filename string, delim rune) [][]float64

func LoadSNPPositionFile

func LoadSNPPositionFile(filename string, delim rune) []uint64

func MForm

func MForm(a, q uint64, u []uint64) (r uint64)

func MFormLvl

func MFormLvl(r *ring.Ring, level int, p1, p2 *ring.Poly)

func MatMult4Stream

func MatMult4Stream(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, gfs *GenoFileStream, maxLevel int, computeSquaredSum bool, nproc int) (crypto.CipherMatrix, []float64, []float64)

func MatMult4StreamCompute

func MatMult4StreamCompute(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, maxLevel int, cacheFilePrefix string) crypto.CipherMatrix

func MatMult4StreamPreprocess

func MatMult4StreamPreprocess(cryptoParams *crypto.CryptoParams, gfs *GenoFileStream, maxLevel int, cacheFilePrefix string)

func Max

func Max(x, y int) int

func MergeBlockFiles

func MergeBlockFiles(inputBlockFilePrefix string, nrows int, ncolsPerBlock []int, outputFile string)

func Min

func Min(a int, b int) int

func Mod

func Mod(n int, modulus int) int

func ModularReduceV1

func ModularReduceV1(cryptoParams *crypto.CryptoParams, cva CipherVectorAccV1, outScale float64) crypto.CipherVector

func ModularReduceV2

func ModularReduceV2(cryptoParams *crypto.CryptoParams, cva CipherVectorAccV2, outScale float64) crypto.CipherVector

func MulCoeffsAndAdd128

func MulCoeffsAndAdd128(a, b []uint64, c []uint128)

func NetDQRenc

func NetDQRenc(cryptoParams *crypto.CryptoParams, mpcObj *mpc.MPC, A crypto.CipherMatrix, nrowsAll []int) crypto.CipherMatrix

Since required precision scales with 1/sqrt(n) maintain sqrt(n)*v for unit vectors v

func NetDQRplain

func NetDQRplain(cryptoParams *crypto.CryptoParams, mpcObj *mpc.MPC, A crypto.PlainMatrix, nrowsAll []int) crypto.CipherMatrix

NetDQRplain returns Q all zeros (or nil) (for pid=0), else returns share of Q for each party

func Ones

func Ones(n int) []int

func OnesBool

func OnesBool(n int) []bool

func QXLazyNormStream

func QXLazyNormStream(cps *crypto.CryptoParams, mpcObj *mpc.MPC, Q crypto.CipherMatrix, Xcachefile string, XMean, XStdInv crypto.CipherVector, numInd int) (out crypto.CipherMatrix)

Multiply Q (kp by nsnp) with X (nsnp by nind) with lazy normalization of X Compute Q * S * (X - m * 1^T) as (Q * S) * X - ((Q * S) * m) * 1^T S: diagonal matrix containing 1/stdev of each SNP, m: column vector containing mean of each SNP

func QXtLazyNormStream

func QXtLazyNormStream(cps *crypto.CryptoParams, mpcObj *mpc.MPC, Q crypto.CipherMatrix, XTcachefile string, XMean, XStdInv crypto.CipherVector) (out crypto.CipherMatrix)

Multiply Q (kp by nind) with X^T (nind by nsnp) with lazy normalization of X Compute Q * (X^T - 1 * m^T) * S as ((Q * X^T) - ((Q * 1) * m^T)) * S S: diagonal matrix containing 1/stdev of each SNP, m: column vector containing mean of each SNP TODO: multiply with S AFTER aggregation across parties, that way bootstrap once for all

func ReadGenoStatsFromFile

func ReadGenoStatsFromFile(filename string, m int) (ac, gc [][]uint32, miss []uint32)

Reads in a binary file containing 6 vectors of length m (# of SNPs): ref allele count (AC), alt AC, hom-ref genotype count (GC), het GC, hom-alt GC, missing sample count. Each value is encoded as uint32 in little endian format

func ReduceAndAddUint128

func ReduceAndAddUint128(in []uint128, out []uint64, qInv, q uint64)

func SaveFloatMatrixToFile

func SaveFloatMatrixToFile(filename string, x [][]float64)

func SaveFloatVectorToFile

func SaveFloatVectorToFile(filename string, x []float64)

func SaveIntVectorToFile

func SaveIntVectorToFile(filename string, x []int)

func SaveMatrixToFile

func SaveMatrixToFile(cps *crypto.CryptoParams, mpcObj *mpc.MPC, cm crypto.CipherMatrix, nElemCol int, sourcePid int, filename string)

func Sum

func Sum(a []int) int

func SumBool

func SumBool(a []bool) int

func ToMontgomeryForm

func ToMontgomeryForm(cryptoParams *crypto.CryptoParams, pt crypto.PlainVector)

func TransposeMatrixFile

func TransposeMatrixFile(inputFile string, nrows, ncols int, outputFile string)

Types

type AssocTest

type AssocTest struct {
	Qpc crypto.CipherMatrix

	MafLowerBound float64
	MafUpperBound float64
	// contains filtered or unexported fields
}

func (*AssocTest) GenoBlockMult

func (ast *AssocTest) GenoBlockMult(b int, mat crypto.CipherMatrix) (matOut crypto.CipherMatrix, dosageSum, dosageSqSum []float64, filtOut []bool)

func (*AssocTest) GetAssociationStats

func (ast *AssocTest) GetAssociationStats() (crypto.CipherVector, []bool)

type Block

type Block interface {
	At(int, int) float64
	Dims() (int, int)
}

type BlockI8

type BlockI8 struct {
	// contains filtered or unexported fields
}

func NewBlockI8

func NewBlockI8(r, c int) BlockI8

func (BlockI8) At

func (b BlockI8) At(i, j int) float64

func (BlockI8) Dims

func (b BlockI8) Dims() (int, int)

type BlockMatrix

type BlockMatrix []BlockVector

func ToBlockMatrix

func ToBlockMatrix(A *mat.Dense, d int) BlockMatrix

type BlockVector

type BlockVector []Block

type CipherAccV1

type CipherAccV1 struct {
	// contains filtered or unexported fields
}

type CipherAccV2

type CipherAccV2 struct {
	// contains filtered or unexported fields
}

type CipherVectorAccV1

type CipherVectorAccV1 []CipherAccV1

func NewCipherVectorAccV1

func NewCipherVectorAccV1(cryptoParams *crypto.CryptoParams, n int) CipherVectorAccV1

type CipherVectorAccV2

type CipherVectorAccV2 struct {
	// contains filtered or unexported fields
}

func NewCipherVectorAccV2

func NewCipherVectorAccV2(cryptoParams *crypto.CryptoParams, n int, level int) CipherVectorAccV2

type Config

type Config struct {
	NumMainParties int `toml:"num_main_parties"`
	HubPartyId     int `toml:"hub_party_id"`

	CkksParams string `toml:"ckks_params"`

	DivSqrtMaxLen int `toml:"div_sqrt_max_len"`

	NumInds    []int `toml:"num_inds"`
	NumSnps    int   `toml:"num_snps"`
	NumCovs    int   `toml:"num_covs"`
	CovAllOnes bool  `toml:"cov_all_ones"`

	ItersPerEval  int `toml:"iter_per_eigenval"`
	NumPCs        int `toml:"num_pcs_to_remove"`
	NumOversample int `toml:"num_oversampling"`
	NumPowerIters int `toml:"num_power_iters"`

	SkipQC             bool `toml:"skip_qc"`
	SkipPCA            bool `toml:"skip_pca"`
	UseCachedQC        bool `toml:"use_cached_qc"`
	UseCachedPCA       bool `toml:"use_cached_pca"`
	UseCachedCombinedQ bool `toml:"use_cached_combined_q"`
	SkipPowerIter      bool `toml:"skip_power_iter"`
	PCARestartIter     int  `toml:"restart_pca_from_iter"`

	IndMissUB    float64 `toml:"imiss_ub"`
	HetLB        float64 `toml:"het_lb"`
	HetUB        float64 `toml:"het_ub"`
	SnpMissUB    float64 `toml:"gmiss"`
	MafLB        float64 `toml:"maf_lb"`
	HweUB        float64 `toml:"hwe_ub"`
	SnpDistThres int     `toml:"snp_dist_thres"`

	BindingIP string `toml:"binding_ipaddr"`
	Servers   map[string]mpc.Server

	SharedKeysPath string `toml:"shared_keys_path"`

	GenoFileFormat string `toml:"geno_file_format"`        // 'blocks' or 'pgen'
	GenoFilePrefix string `toml:"geno_binary_file_prefix"` // If 'pgen' expects a '%d' placeholder for chrom, e.g. "ukb_imp_chr%d_v3" (.pgen/.psam/.pvar)

	GenoNumBlocks     int    `toml:"geno_num_blocks"`
	GenoBlockSizeFile string `toml:"geno_block_size_file"`

	PhenoFile  string `toml:"pheno_file"`
	CovFile    string `toml:"covar_file"`
	SnpPosFile string `toml:"snp_position_file"`

	UsePrecomputedGenoCount bool   `toml:"use_precomputed_geno_count"`
	GenoCountFile           string `toml:"geno_count_file"`
	SampleKeepFile          string `toml:"sample_keep_file"`
	SnpIdsFile              string `toml:"snp_ids_file"`

	OutDir   string `toml:"output_dir"`
	CacheDir string `toml:"cache_dir"`

	Phase string `toml:"phase"`

	MpcFieldSize                int    `toml:"mpc_field_size"`
	MpcDataBits                 int    `toml:"mpc_data_bits"`
	MpcFracBits                 int    `toml:"mpc_frac_bits"`
	MpcNumThreads               int    `toml:"mpc_num_threads"`
	MpcBooleanShares            bool   `toml:"mpc_boolean_shares"`
	LocalNumThreads             int    `toml:"local_num_threads"`
	LocalAssocNumBlocksParallel int    `toml:"assoc_num_blocks_parallel"`
	MemoryLimit                 uint64 `toml:"memory_limit"`

	Debug          bool  `toml:"debug"`
	BlocksForAssoc []int `toml:"blocks_for_assoc_test"`
	PgenBatchSize  int   `toml:"pgen_batch_nsnp"`
}

type DiagCacheStream

type DiagCacheStream struct {
	// contains filtered or unexported fields
}

func NewDiagCacheStream

func NewDiagCacheStream(cryptoParams *crypto.CryptoParams, filePrefix string, blockRowIndex int, isWrite bool) (*DiagCacheStream, bool)

Second output is a flag indicating whether write is attempted when the file already exists

func (*DiagCacheStream) Close

func (dcs *DiagCacheStream) Close()

func (*DiagCacheStream) GetIndexTables

func (dcs *DiagCacheStream) GetIndexTables() ([]bool, []bool)

func (*DiagCacheStream) ReadDiag

func (dcs *DiagCacheStream) ReadDiag() (pv crypto.PlainVector, shift int)

func (*DiagCacheStream) ResetRead

func (dcs *DiagCacheStream) ResetRead()

func (*DiagCacheStream) SetIndexTables

func (dcs *DiagCacheStream) SetIndexTables(babyTable, giantTable []bool)

func (*DiagCacheStream) WriteDiag

func (dcs *DiagCacheStream) WriteDiag(pv crypto.PlainVector, shift uint32)

type FilterParams

type FilterParams struct {
	MafLowerBound float64
	HweUpperBound float64
	GenoMissBound float64
	IndMissBound  float64
	HetLowerBound float64
	HetUpperBound float64
}

func InitFilteringSettings

func InitFilteringSettings(maflb, hwe, gmiss, imiss, hetlb, hetub float64) *FilterParams

type GWASParams

type GWASParams struct {
	// contains filtered or unexported fields
}

func InitGWASParams

func InitGWASParams(numInds []int, numSnps, numCovs, numPCs, minSnpDist int) *GWASParams

func (*GWASParams) FiltNumInds

func (gwasParams *GWASParams) FiltNumInds() []int

func (*GWASParams) FiltNumSNP

func (gwasParams *GWASParams) FiltNumSNP() int

func (*GWASParams) GetPopStratMethod

func (gwasParams *GWASParams) GetPopStratMethod() bool

func (*GWASParams) MinSnpDistThreshold

func (gwasParams *GWASParams) MinSnpDistThreshold() uint64

func (*GWASParams) NumCov

func (gwasParams *GWASParams) NumCov() int

func (*GWASParams) NumInds

func (gwasParams *GWASParams) NumInds() []int

func (*GWASParams) NumPC

func (gwasParams *GWASParams) NumPC() int

func (*GWASParams) NumSNP

func (gwasParams *GWASParams) NumSNP() int

func (*GWASParams) SetFiltCounts

func (gwasParams *GWASParams) SetFiltCounts(filtInds []int, filtSnps int)

func (*GWASParams) SetNumPC

func (gwasParams *GWASParams) SetNumPC(numPCs int)

func (*GWASParams) SetNumSnpsPCA

func (gwasParams *GWASParams) SetNumSnpsPCA(numSnps int)

func (*GWASParams) SetPopStratMethod

func (gwasParams *GWASParams) SetPopStratMethod(s bool)

func (*GWASParams) SetSnpFilt

func (gwasParams *GWASParams) SetSnpFilt(filt []bool)

func (*GWASParams) SnpFilt

func (gwasParams *GWASParams) SnpFilt() []bool

type GenoFileStream

type GenoFileStream struct {
	// contains filtered or unexported fields
}

func NewGenoFileStream

func NewGenoFileStream(filename string, numRow, numCol uint64, replaceMissing bool) *GenoFileStream

func (*GenoFileStream) CheckEOF

func (gfs *GenoFileStream) CheckEOF() bool

func (*GenoFileStream) ColFilt

func (gfs *GenoFileStream) ColFilt() []bool

func (*GenoFileStream) LineCount

func (gfs *GenoFileStream) LineCount() uint64

func (*GenoFileStream) NextRow

func (gfs *GenoFileStream) NextRow() []int8

func (*GenoFileStream) NumCols

func (gfs *GenoFileStream) NumCols() uint64

func (*GenoFileStream) NumColsToKeep

func (gfs *GenoFileStream) NumColsToKeep() uint64

func (*GenoFileStream) NumRows

func (gfs *GenoFileStream) NumRows() uint64

func (*GenoFileStream) NumRowsToKeep

func (gfs *GenoFileStream) NumRowsToKeep() uint64

func (*GenoFileStream) Reset

func (gfs *GenoFileStream) Reset()

func (*GenoFileStream) RowFilt

func (gfs *GenoFileStream) RowFilt() []bool

func (*GenoFileStream) UpdateColFilt

func (gfs *GenoFileStream) UpdateColFilt(a []bool) int

func (*GenoFileStream) UpdateRowFilt

func (gfs *GenoFileStream) UpdateRowFilt(a []bool) int

type PCA

type PCA struct {
	Q crypto.CipherMatrix
	// contains filtered or unexported fields
}

func (*PCA) DistributedPCA

func (pca *PCA) DistributedPCA() crypto.CipherMatrix

type PlainMatrixDiagCache

type PlainMatrixDiagCache [][]crypto.PlainVector

Cache structure for MatMult4 First index corresponds to row index of blocks of size slots-by-slots Second index of indexMap corresponds to index of diagonals (0..slots-1), The table maps a diag index to the encoded PlainVector If a given index has empty data, stored element is nil

func MatMult4TransformB

func MatMult4TransformB(cryptoParams *crypto.CryptoParams, B *mat.Dense) PlainMatrixDiagCache

type ProtocolInfo

type ProtocolInfo struct {
	// contains filtered or unexported fields
}

func InitializeGWASProtocol

func InitializeGWASProtocol(config *Config, pid int, mpcOnly bool) (gwasProt *ProtocolInfo)

func (*ProtocolInfo) CZeroTest

func (g *ProtocolInfo) CZeroTest()

func (*ProtocolInfo) CachePath

func (g *ProtocolInfo) CachePath(filename string) string

func (*ProtocolInfo) ComputeAssocStatistics

func (g *ProtocolInfo) ComputeAssocStatistics(Qpca crypto.CipherMatrix) (crypto.CipherVector, []bool)

func (*ProtocolInfo) ConversionTest

func (g *ProtocolInfo) ConversionTest()

func (*ProtocolInfo) GWAS

func (g *ProtocolInfo) GWAS()

func (*ProtocolInfo) GeneratePCAInput

func (g *ProtocolInfo) GeneratePCAInput(numSnpsPCA int, snpFiltPCA []bool, isPgen bool) (*GenoFileStream, *GenoFileStream)

func (*ProtocolInfo) GetConfig

func (prot *ProtocolInfo) GetConfig() *Config

func (*ProtocolInfo) GetCryptoParams

func (prot *ProtocolInfo) GetCryptoParams() *crypto.CryptoParams

func (*ProtocolInfo) GetGenoBlocks

func (prot *ProtocolInfo) GetGenoBlocks() []*GenoFileStream

func (*ProtocolInfo) GetGwasParams

func (prot *ProtocolInfo) GetGwasParams() *GWASParams

func (*ProtocolInfo) GetMpc

func (prot *ProtocolInfo) GetMpc() mpc.ParallelMPC

func (*ProtocolInfo) InitAssociationTests

func (g *ProtocolInfo) InitAssociationTests(Qpc crypto.CipherMatrix) *AssocTest

func (*ProtocolInfo) InitPCA

func (g *ProtocolInfo) InitPCA(genoRed, genoRedT *GenoFileStream) *PCA

func (*ProtocolInfo) InitQC

func (g *ProtocolInfo) InitQC(filterParams *FilterParams) QC

func (*ProtocolInfo) IsBlockForAssocTest

func (prot *ProtocolInfo) IsBlockForAssocTest(blockId int) bool

func (*ProtocolInfo) IsPgen

func (prot *ProtocolInfo) IsPgen() bool

func (*ProtocolInfo) OutPath

func (g *ProtocolInfo) OutPath(filename string) string

func (*ProtocolInfo) Phase1

func (g *ProtocolInfo) Phase1()

func (*ProtocolInfo) Phase2

func (g *ProtocolInfo) Phase2() crypto.CipherMatrix

func (*ProtocolInfo) Phase3

func (g *ProtocolInfo) Phase3(Qpca crypto.CipherMatrix)

func (*ProtocolInfo) PopulationStratification

func (g *ProtocolInfo) PopulationStratification() crypto.CipherMatrix

func (*ProtocolInfo) SyncAndTerminate

func (g *ProtocolInfo) SyncAndTerminate(closeChannelFlag bool)

func (*ProtocolInfo) Test

func (g *ProtocolInfo) Test()

type QC

type QC struct {
	// contains filtered or unexported fields
}

func (*QC) IndividualMissAndHetFilters

func (qc *QC) IndividualMissAndHetFilters() []bool

IndividualMissAndHetFilters filters individuals based on missing rate and heterozygosity filter

func (*QC) QualityControlProtocol

func (qc *QC) QualityControlProtocol(useCache bool)

QualityControlProtocol (1) applies SNP filters and individual filters to input data, (2) filters input wrt filters

func (*QC) QualityControlProtocolWithPrecomputedGenoStats

func (qc *QC) QualityControlProtocolWithPrecomputedGenoStats(useCache bool)

func (*QC) SNPFilterWithPrecomputedStats

func (qc *QC) SNPFilterWithPrecomputedStats(ac, gc [][]uint32, miss []uint32, useCache bool) []bool

ac: allele counts (0, 1) gc: genotype counts (0, 1, 2) miss: missing value counts

func (*QC) SNPMAFAndHWEFilters

func (qc *QC) SNPMAFAndHWEFilters() []bool

func (*QC) SNPMissFilter

func (qc *QC) SNPMissFilter() []bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL