forked from jianyangqt/smr
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCommFunc.h
executable file
·141 lines (128 loc) · 4.63 KB
/
CommFunc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Interface to the commonly-used functions
*
* 2010 by Jian Yang <jian.yang@qimr.edu.au>
*
* This file is distributed under the GNU General Public
* License, Version 2. Please see the file COPYING for more
* details
*/
#ifndef _COMMFUNC_H
#define _COMMFUNC_H
#define MAX_BUF_SIZE 0x40000000
#if defined _WIN64 || defined _WIN32
#define MAX_LINE_SIZE 0x10000
#else
#define MAX_LINE_SIZE 0x80000
#endif
//#define __DBL_MIN__ 2.225e-308
#define MAX_LINE_BUF 0x1000000
#define MAXSNPNUMPERPROBEINSPARSE 0x300000
#define MAX_PROBE_NUM 0xF0000
#define MAX_SNP_NAME 64
#define DENSE_FILE_TYPE_1 0 // uint32 + floats
#define SPARSE_FILE_TYPE_3F 0x40400000 // uint32 + uint64_t + uint64_ts + uint32_ts + floats
#define SPARSE_FILE_TYPE_3 3 // 16*uint32s + uint64_t + uint64_ts + uint32_ts + floats (indicator+samplesize+snpnumber+probenumber+ 6*-9s +valnumber+cols+rowids+betases) [default]
#define DENSE_FILE_TYPE_3 5 // 16*uint32s + floats (indicator+samplesize+snpnumber+probenumber+ 6*-9s + values) [default]
#define RESERVEDUNITS 16
#define FNAMESIZE 4096
//#define BEST_NUM_HEIDI 41
#define MAX_NUM_LD 500
#define MIN_PVAL_ADJUSTED 1e-150
//typedef unsigned long long uint64_t;
//typedef unsigned int uint32_t;
#include <limits>
#include <complex>
#include <vector>
#include <algorithm>
#include <ctime>
#include <fstream>
#include "StrFunc.h"
#include <string.h>
#include <Eigen/Dense>
#include <Eigen/Sparse>
#include <Eigen_unsupported/Eigen/SparseExtra>
#include <Eigen/Eigenvalues>
#include <queue>
//#include <cmath> //already in Eigen
using namespace Eigen;
using namespace std;
namespace CommFunc
{
const double FloatErr=numeric_limits<double>::epsilon();
template <typename T>
inline T ABS(T const& a)
{
return (T{} < a) ? a : -a;
}
template <typename T>
extern void free2(T** to)
{
if(*to != NULL)
{
// delete(*to);
*to=NULL;
}
}
template <typename T>
extern inline string atosm (T const& a)
{
if(a==-9) return("NA");
stringstream ss;
ss << a;
return(ss.str());
}
double Abs(const double &x);
double sum(const vector<double> &x);
double mean(const vector<double> &x);
double median(const vector<double> &x);
double var(const vector<double> &x);
double cov(const vector<double> &x, const vector<double> &y);
bool FloatEqual(double lhs, double rhs);
bool FloatNotEqual(double lhs, double rhs);
const double Sqr(const double &a);
const double Max(const double &a, const double &b);
const double Min(const double &a, const double &b);
const double Sign(const double &a, const double &b);
int rand_seed(); //positive value, return random seed using the system time
void FileExist(string filename);
int max_abs_id(VectorXd &zsxz);
int max_abs_id(vector<double> &zsxz);
int min_id(vector<double> &pyz);
int min_id(VectorXd &pyz);
void getRank(vector<double> &a, vector<int> &b);
void getRank(vector<int> &a, vector<int> &b);
void getRank_norep(vector<int> &a, vector<int> &b);
void getUnique(vector<uint32_t> &a);
void match(const vector<uint32_t> &VecA, const vector<uint32_t> &VecB, vector<int> &VecC);
static inline unsigned int fputs_checked(const char* ss, FILE* outfile) {
fputs(ss, outfile);
return ferror(outfile);
}
void strcpy2(char** to, string from);
float readfloat(FILE *f);
uint64_t readuint64(FILE *f);
uint32_t readuint32(FILE *f);
int readint(FILE *f);
double cor(vector<double> &y, vector<double> &x);
double cor(VectorXd &Y, VectorXd &X, bool centered=false, bool standardised=false);
void update_map_kp(const vector<string> &id_list, map<string, int> &id_map, vector<int> &keep);
void update_map_rm(const vector<string> &id_list, map<string, int> &id_map, vector<int> &keep);
template <typename T>
inline string atos (T const& a)
{
stringstream ss;
ss << a;
return(ss.str());
}
string dtos(double value);
string dtosf(double value);
string itos(int value);
string ltos(long value);
void update_id_map_kp(const vector<string> &id_list, map<string, int> &id_map, vector<int> &keep);
void update_id_map_rm(const vector<string> &id_list, map<string, int> &id_map, vector<int> &keep);
void read_indi_list(string indi_list_file, vector<string> &indi_list);
void read_msglist(string msglistfile, vector<string> &msglist, string msg);
void progress(int &cur, double &disp, int ttl);
}
#endif