Skip to content

Commit

Permalink
new output eigvec2, which is plink2-like
Browse files Browse the repository at this point in the history
  • Loading branch information
Zilong-Li committed Feb 23, 2024
1 parent 1567eb4 commit 46f3196
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- v0.4.3
- new output =eigvecs2= for plink input
- fix ld clumping and sort snps by pvalues

- v0.4.2
- fix slowness due to the ld logics
- add ld-clump functions
Expand Down
3 changes: 3 additions & 0 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ int main(int argc, char * argv[])
cao << tick.date() << "total elapsed wall time: " << tick.abstime() << " seconds" << endl;
cao << tick.date() << "eigenvecs and eigenvals are saved. have a nice day. bye!\n";

if(params.file_t == FileType::PLINK)
make_plink2_eigenvec_file(params.k, params.fileout + ".eigvecs2", params.fileout + ".eigvecs",
params.filein + ".fam");
delete data;

return 0;
Expand Down
16 changes: 16 additions & 0 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,19 @@ void get_snp_pos_bim(const std::string & filebim,
chr_pos_end.push_back(i - 1); // add the last SNP
}

void make_plink2_eigenvec_file(int K, std::string fout, const std::string & fin, const std::string & fam)
{
std::ifstream ifam(fam);
std::ifstream ifin(fin);
std::ofstream ofs(fout);
ofs << "#FID\tIID";
for(int i = 0; i < K; i++) ofs << "\tPC" << i + 1;
ofs << "\n";
std::string line1, line2, sep{" \t"};
while(getline(ifam, line1))
{
auto tokens = split_string(line1, sep);
getline(ifin, line2);
ofs << tokens[0] + "\t" + tokens[1] + "\t" << line2 << std::endl;
}
}
3 changes: 2 additions & 1 deletion src/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ inline std::vector<size_t> sortidx(const std::vector<T> & v)
return idx;
}


struct Line
{
std::string data;
Expand Down Expand Up @@ -107,4 +106,6 @@ void get_snp_pos_bim(const std::string & filebim,
bool header = false,
Int1D idx = Int1D{0, 3});

void make_plink2_eigenvec_file(int K, std::string fout, const std::string & fin, const std::string & fam);

#endif // PCAONE_UTILES_

0 comments on commit 46f3196

Please sign in to comment.