-
Notifications
You must be signed in to change notification settings - Fork 0
/
poplddecay.cpp
executable file
·155 lines (131 loc) · 3.82 KB
/
poplddecay.cpp
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "poplddecay.h"
PopLDdecay::PopLDdecay()
{
}
bool PopLDdecay::makeGenotype(QString ped, QString map, QString out)
{
if (ped.isNull() || map.isNull() || out.isNull())
{
return false;
}
/*
* perl ~/software/PopLDdecay-master/bin/mis/plink2genotype.pl -inPED 222_filter1.ped
* -inMAP 222_filter1.map -outGenotype 222_filter1.genotype
*/
this->paramlist.clear();
this->paramlist.append("-inPED");
this->paramlist.append(ped);
this->paramlist.append("-inMAP");
this->paramlist.append(map);
this->paramlist.append("-outGenotype");
this->paramlist.append(out);
return true;
}
bool PopLDdecay::runLD(QString _genotype, QString out)
{
if (_genotype.isNull() || out.isNull())
{
return false;
}
// PopLDdecay -InGenotype 222_filter1.genotype -OutStat 222_filter1_LD
this->paramlist.clear();
this->paramlist.append("-InGenotype");
this->paramlist.append(_genotype);
this->paramlist.append("-OutStat");
this->paramlist.append(out);
return true;
}
bool PopLDdecay::plotLD(QString in, QString out)
{
if (in.isNull() || out.isNull())
{
return false;
}
/*
* perl ~/software/PopLDdecay-master/bin/Plot_OnePop.pl
* -inFile 222_filter1_LD.stat.gz -output 222_filter1_LD_fig
*/
this->paramlist.clear();
this->paramlist.append("-inFile");
this->paramlist.append(in);
this->paramlist.append("-output");
this->paramlist.append(out);
return true;
}
QString PopLDdecay::makeSingleKeepFile(QString src, QString fid)
{
if (src.isNull() || fid.isNull())
{
return QString::Null();
}
QFile file(src);
QFileInfo fileInfo(file);
QString fileBaseName = fileInfo.baseName();
QString fileAbPath = fileInfo.absolutePath();
QTextStream tfileStream(&file);
if (!file.open(QIODevice::ReadOnly))
{
return QString::Null();
}
QFile keepFile(fileAbPath+"/"+fileBaseName+"_"+fid+".keep");
QTextStream keepFileStream(&keepFile);
keepFile.open(QIODevice::Append);
while (!tfileStream.atEnd())
{
QStringList curLine = tfileStream.readLine().split(QRegExp("\\s+"), QString::SkipEmptyParts);
if (fid == curLine[0])
{
keepFileStream << curLine[0] << "\t" << curLine[1] << "\n";
}
qApp->processEvents(); // Avoid no responding of MainWindow.
}
keepFile.close();
return keepFile.fileName();
}
/**
* @brief PopLDdecay::makeKeepFile
* make keep file for every family according to the first 2 columns of src.
* @param src: .ped, .tfam or .fam.
* @return keepList.
*/
QStringList PopLDdecay::makeKeepFile(QString src)
{
QStringList keepList;
if (src.isNull())
{
return keepList;
}
QStringList fidList;
QFile file(src);
QFileInfo fileInfo(file);
QString fileBaseName = fileInfo.baseName();
QString fileAbPath = fileInfo.absolutePath();
QTextStream fileStream(&file);
if (!file.open(QIODevice::ReadOnly))
{
return keepList;
}
while (!fileStream.atEnd())
{
QStringList curLine = fileStream.readLine().split(QRegExp("\\s+"), QString::SkipEmptyParts);
QFile keepFile(fileAbPath+"/"+fileBaseName+"_"+curLine[0]+".keep");
QTextStream keepFileStream(&keepFile);
if (fidList.indexOf(curLine[0]) == -1)
{ // The first appearence of the FID.
keepFile.remove();
fidList.append(curLine[0]);
keepList.append(fileAbPath+"/"+fileBaseName+"_"+curLine[0]+".keep");
}
if (!keepFile.isOpen())
{
keepFile.open(QIODevice::Append);
}
keepFileStream << curLine[0] << "\t" << curLine[1] << "\n";
}
for (auto item:keepList)
{
QFile file(item);
file.close();
}
return keepList;
}