Skip to content

Commit

Permalink
update output precesion for Q
Browse files Browse the repository at this point in the history
  • Loading branch information
Zilong-Li committed Feb 6, 2024
1 parent eaf2368 commit 3f108a8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
14 changes: 3 additions & 11 deletions src/admixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,6 @@ void Admixture::setStartPoint(const std::unique_ptr<BigAss> & genome, std::strin
if(!qfile.empty()) load_csv(Q, qfile);
}

void Admixture::writeQ(std::string out)
{
std::ofstream ofs(out);
if(!ofs) cao.error(out, strerror(errno));
Q = (Q * 1e6).round() / 1e6;
ofs << std::fixed << Q.transpose() << "\n";
ofs.close();
}

void Admixture::setFlags(bool debug_, bool nonewQ_, bool cF_)
{
debug = debug_;
Expand Down Expand Up @@ -370,11 +361,12 @@ int run_admix_main(Options & opts)
}
}
cao.done(tim.date(), "admixture done and outputting");
admixer.writeQ(opts.out + ".Q");
std::ofstream oq(opts.out + ".Q");
oq << std::fixed << admixer.Q.transpose().format(fmt10) << "\n";
if(opts.oF)
{
std::ofstream of(opts.out + ".F");
of << admixer.F.transpose().format(fmt) << "\n";
of << admixer.F.transpose().format(fmt6) << "\n";
}
cao.done(tim.date(), "-> good job. have a nice day, bye!");

Expand Down
1 change: 0 additions & 1 deletion src/admixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class Admixture
void constrainF();
void setFlags(bool, bool, bool);
void setStartPoint(const std::unique_ptr<BigAss> & genome, std::string qfile);
void writeQ(std::string out);
double runNativeWithBigAss(int ind, const std::unique_ptr<BigAss> & genome);
double runOptimalWithBigAss(int ind, const std::unique_ptr<BigAss> & genome);
};
Expand Down
3 changes: 2 additions & 1 deletion src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ using MyMat1D = Eigen::Matrix<MyFloat, Eigen::Dynamic, 1, Eigen::ColMajor>;
using MyArr2D = Eigen::Array<MyFloat, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;
using MyArr1D = Eigen::Array<MyFloat, Eigen::Dynamic, 1, Eigen::ColMajor>;

inline Eigen::IOFormat fmt(6, Eigen::DontAlignCols, " ", "\n");
inline Eigen::IOFormat fmt6(6, Eigen::DontAlignCols, " ", "\n");
inline Eigen::IOFormat fmt10(10, Eigen::DontAlignCols, " ", "\n");

template<typename MatrixType, typename RandomEngineType>
inline MatrixType RandomUniform(const Eigen::Index numRows,
Expand Down
8 changes: 4 additions & 4 deletions src/fastphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,12 @@ int run_impute_main(Options & opts)
assert(std::filesystem::file_size(opts.out + ".pars.bin") == bytes_written);
cao.done(tim.date(), "imputation done and outputting.", bytes_written, " bytes written to file");
std::ofstream orecomb(opts.out + ".recomb");
orecomb << faith.R.transpose().format(fmt) << "\n";
orecomb << faith.R.transpose().format(fmt6) << "\n";
std::ofstream opi(opts.out + ".pi");
opi << faith.PI.transpose().format(fmt) << "\n";
opi << faith.PI.transpose().format(fmt6) << "\n";
std::ofstream ohap(opts.out + ".hapfreq");
ohap << faith.HapSum.transpose().format(fmt) << "\n";
ohap << faith.HapSum.transpose().format(fmt6) << "\n";
std::ofstream oae(opts.out + ".ae");
oae << faith.Ezj.transpose().format(fmt) << "\n";
oae << faith.Ezj.transpose().format(fmt6) << "\n";
return 0;
}
5 changes: 2 additions & 3 deletions src/phaseless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,9 @@ int run_phaseless_main(Options & opts)
}
}
}
faith.Q = (faith.Q * 1e6).round() / 1e6;
oanc << std::fixed << faith.Q.transpose().format(fmt) << "\n";
oanc << std::fixed << faith.Q.transpose().format(fmt10) << "\n";
oanc.close();
op << std::fixed << faith.P.format(fmt) << "\n";
op << faith.P.format(fmt6) << "\n";
std::unique_ptr<Pars> par = std::make_unique<Pars>();
par->init(faith.K, faith.C, faith.M, faith.N, faith.er, faith.P, faith.Q, faith.F);
par->pos = genome->pos;
Expand Down

0 comments on commit 3f108a8

Please sign in to comment.