Commit a9585e7e authored by Jean-Benoist Leger's avatar Jean-Benoist Leger
Browse files

clang format

parent 9a5d2efa
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
RawStringFormats:
- Delimiter: pb
Language: TextProto
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...
......@@ -9,13 +9,9 @@
#ifndef Constants_h
#define Constants_h
// The constant MARKOVCHAINORDER should always be <= 9
// #define MARKOVCHAINORDER 2
// #define INITIALCOUNT 0.5
// #define THRESHOLD 0.75
#endif /* Constants_h */
This diff is collapsed.
#ifndef GENERALFUNCTIONS_H
#define GENERALFUNCTIONS_H
#include <iostream>
#include <fstream>
#include "Constants.h"
#include <assert.h>
#include <fstream>
#include <iostream>
// In the next function:
// n is an integer containing 0 1 or 2 digits where the 2 have been replaced with 0.
// Positions is the array of the positions of the digits 2 that have been replaces by 2.
// NbPositions is the number of positions.
// Value is an integer 0 <= Value < (1 << NbPositions)
// It contains the digits that should be written in n
// For instance if inout data is:
// n = 01001010 01010010 10100101 01000101
// P = ...X...X X...XX.. .X....X. X.....X.
// (NbPositions is 9)
// and Values = 00000000 00000000 00000001 10101011
// n is an integer containing 0 1 or 2 digits where the 2 have been replaced
// with 0. Positions is the array of the positions of the digits 2 that have
// been replaces by 2. NbPositions is the number of positions. Value is an
// integer 0 <= Value < (1 << NbPositions) It contains the digits that should be
// written in n For instance if inout data is: n = 01001010 01010010 10100101
// 01000101 P = ...X...X X...XX.. .X....X. X.....X. (NbPositions is 9) and
// Values = 00000000 00000000 00000001 10101011
//
// Then the returned result should be:
//
......@@ -34,87 +27,94 @@ unsigned long int GetFileSize(std::ifstream &File);
void AddTabs(std::string FileName);
unsigned int Fill(unsigned int n, unsigned char *Positions, unsigned int Values, unsigned int NbPositions);
unsigned int Fill(unsigned int n, unsigned char *Positions, unsigned int Values,
unsigned int NbPositions);
unsigned int RightShift(unsigned int LetterAtLeft, unsigned int RightDigit, unsigned short int MarkovChainOrder);
unsigned int RightShift(unsigned int LetterAtLeft, unsigned int RightDigit,
unsigned short int MarkovChainOrder);
unsigned int LeftShift(unsigned int LetterAtRight, unsigned int LeftDigit, unsigned short int MarkovChainOrder);
unsigned int LeftShift(unsigned int LetterAtRight, unsigned int LeftDigit,
unsigned short int MarkovChainOrder);
unsigned int GetInitial(char *Ind, unsigned char *PosOf2, unsigned int &Nb2, unsigned short int LengthInd);
unsigned int GetInitial(char *Ind, unsigned char *PosOf2, unsigned int &Nb2,
unsigned short int LengthInd);
long double ProbaToBe1LittleEndian(long double *Tau, unsigned short int MarkovChainOrder);
long double ProbaToBe1LittleEndian(long double *Tau,
unsigned short int MarkovChainOrder);
long double ProbaToBe1BigEndian(long double *Tau, unsigned short int MarkovChainOrder);
long double ProbaToBe1BigEndian(long double *Tau,
unsigned short int MarkovChainOrder);
int CompatibleLetters(unsigned int Basis2, unsigned int Basis3, unsigned short int MarkovChainOrder);
void FromVCFToMatrix(std::string InputFileName, std::string OutptFileName, unsigned int &NbInd, unsigned int &NbMarkers);
int CompatibleLetters(unsigned int Basis2, unsigned int Basis3,
unsigned short int MarkovChainOrder);
void FromVCFToMatrix(std::string InputFileName, std::string OutptFileName,
unsigned int &NbInd, unsigned int &NbMarkers);
int Prec1(char c);
int Prec2(char c);
int Next1(char c);
int Next2(char c);
// function that gives the length of a line
unsigned int LineLength(std::ifstream &InputFile, unsigned int &FileSize);
int get_end_metadata_position(std::string Line, int line_length, int nb_supp_elements);
int get_end_metadata_position(std::string Line, int line_length,
int nb_supp_elements);
int get_next_value_position(std::string Line, int FirstPos, int line_length);
void ImpThreshold(std::string probas_filename, std::string output_filename, double threshold, int nb_supp_elements, int ncols, bool replace_values, bool do_threshold);
void txt_to_vcf(std::string txt_filename, std::string vcf_filename, std::string output_filename, int nb_supp_elements, int nb_cols, bool replace_values);
void ImpThreshold(std::string probas_filename, std::string output_filename,
double threshold, int nb_supp_elements, int ncols,
bool replace_values, bool do_threshold);
void txt_to_vcf(std::string txt_filename, std::string vcf_filename,
std::string output_filename, int nb_supp_elements, int nb_cols,
bool replace_values);
template <typename T>
void FromBinToHR (std::string BinFileName, std::string HRFileName, unsigned int LineL)
{
unsigned int FileSize, NbLines;
std::ifstream BinFile(BinFileName.c_str(), std::ifstream::in | std::ifstream::binary);
BinFile.seekg(0, std::ios::end);
FileSize = (unsigned int) BinFile.tellg();
BinFile.seekg(0, std::ios::beg);
assert(BinFile.is_open());
std::ofstream HRFile(HRFileName.c_str(), std::ofstream::out | std::ofstream::binary);
assert(HRFile.is_open());
assert(FileSize % LineL == 0);
NbLines = FileSize / LineL;
assert((LineL - 1) % sizeof(T) == 0);
unsigned int NbOutCols = (LineL - 1) / sizeof(T);
T *Buffer = new T[LineL];
char c;
for (unsigned int i = 0; i < NbLines; i++)
{
BinFile.read((char *) Buffer, NbOutCols * sizeof(T));
BinFile.read(&c, 1);
for (unsigned int j = 0; j < NbOutCols; j++)
{
T Aux = Buffer[j];
HRFile << Aux;
if (j < NbOutCols - 1)
HRFile << '\t';
else
HRFile << '\n';
void FromBinToHR(std::string BinFileName, std::string HRFileName,
unsigned int LineL) {
unsigned int FileSize, NbLines;
std::ifstream BinFile(BinFileName.c_str(),
std::ifstream::in | std::ifstream::binary);
BinFile.seekg(0, std::ios::end);
FileSize = (unsigned int)BinFile.tellg();
BinFile.seekg(0, std::ios::beg);
assert(BinFile.is_open());
std::ofstream HRFile(HRFileName.c_str(),
std::ofstream::out | std::ofstream::binary);
assert(HRFile.is_open());
assert(FileSize % LineL == 0);
NbLines = FileSize / LineL;
assert((LineL - 1) % sizeof(T) == 0);
unsigned int NbOutCols = (LineL - 1) / sizeof(T);
T *Buffer = new T[LineL];
char c;
for (unsigned int i = 0; i < NbLines; i++) {
BinFile.read((char *)Buffer, NbOutCols * sizeof(T));
BinFile.read(&c, 1);
for (unsigned int j = 0; j < NbOutCols; j++) {
T Aux = Buffer[j];
HRFile << Aux;
if (j < NbOutCols - 1)
HRFile << '\t';
else
HRFile << '\n';
}
}
}
delete[] Buffer;
HRFile.close();
BinFile.close();
delete[] Buffer;
HRFile.close();
BinFile.close();
}
// Boolean false if we have other than 1 or 2 or 3 or 4 (ex: NA or .) at position t and t+1
// Boolean false if we have other than 1 or 2 or 3 or 4 (ex: NA or .) at
// position t and t+1
bool BothKnown(char *A);
// Boolean false if we have other than 1 or 2 or 3 or 4 (ex: NA or .) at position t
// Boolean false if we have other than 1 or 2 or 3 or 4 (ex: NA or .) at
// position t
bool Known(char A);
double P(char Y, char X);
......@@ -126,13 +126,15 @@ int LastLetter(int);
char FirstLetterChar(char i);
char LastLetterChar(char i);
void From4To2Letters(char *BufferOn4Letters, char *BufferOn2Letters, int Buffer4Size);
void From4To2Letters(char *BufferOn4Letters, char *BufferOn2Letters,
int Buffer4Size);
void CheckFile(std::ifstream &File, std::string OutputFileName);
bool CheckBuffer(char *Buffer, int First, int last, int &ErrIndex);
void Transpose(std::string InputFileName, std::string OutputFileName, unsigned int ElementSize = 1, unsigned int LineL = 0);
void Transpose(std::string InputFileName, std::string OutputFileName,
unsigned int ElementSize = 1, unsigned int LineL = 0);
int RemoveTabs(char *Buffer, int BufferSize);
......
This diff is collapsed.
......@@ -9,80 +9,81 @@
#ifndef MarkovChain_hpp
#define MarkovChain_hpp
#include <stdio.h>
#include <fstream>
#include "Transition.h"
#include <fstream>
#include <stdio.h>
#include <string>
class Transition;
// This class computes, stores and restores the Markov Chains.
class Imputator
{
////////////
// Fields //
////////////
class Imputator {
////////////
// Fields //
////////////
public:
bool DoViterbi;
bool DoProbas;
long double Threshold;
long double InitialCount;
unsigned short int MyMarkovChainOrder;
private:
unsigned int NbInd;
unsigned int NbMarkers;
long double *Forward;
long double *G;
long double *Tau;
std::string InputFileName;
std::string InputFileNameWithConstants;
std::string InputPath;
std::string OutputPath;
std::string InitialMatrixFileName;
std::string TransposedMatrixFileName;
std::string ForwardBackwardImputedFileName;
Transition *MyTransitions;
std::ofstream CheckTausFile;
std::ofstream ViterbiFile;
std::ofstream ProbasCharsFile;
std::ofstream ProbasBinaryFile;
std::ofstream ProbasHRNumbersFile;
bool CheckTauCoherence;
std::string ViterbiFileName;
std::string NumbersProbasFileName;
std::string BinaryProbasFileName;
std::string CharsProbasFileName;
unsigned char *PositionsOf2;
/////////////
// Methods //
/////////////
public:
Imputator();
Imputator(unsigned short int MarkCO, std::string InputP, std::string InputFN, std::string OutputP, long double Thresh = 0.75, long double InitialC = 0.5, bool DV = true, bool DP = true, bool CheckTaus = false);
unsigned int GetNbMarkers();
unsigned int GetNbInd();
private:
void Init();
void MoveForwardBackward();
void MoveForward(char *Ind);
void MoveBackward(char *Ind);
void Viterbi(char *Ind);
void WriteProbasImputation(char *Ind);
long double &GetTau(unsigned int Locus, unsigned int Letter);
long double &GetG(unsigned int Locus, unsigned int Letter);
long double &GetForward(unsigned int Locus, unsigned int Letter);
void CheckTaus();
long double ProbaToBe1FixedDigit(unsigned int Locus, unsigned char DistanceToLocus);
void InitializeInitialProbabilities(char *Ind);
public:
bool DoViterbi;
bool DoProbas;
long double Threshold;
long double InitialCount;
unsigned short int MyMarkovChainOrder;
private:
unsigned int NbInd;
unsigned int NbMarkers;
long double *Forward;
long double *G;
long double *Tau;
std::string InputFileName;
std::string InputFileNameWithConstants;
std::string InputPath;
std::string OutputPath;
std::string InitialMatrixFileName;
std::string TransposedMatrixFileName;
std::string ForwardBackwardImputedFileName;
Transition *MyTransitions;
std::ofstream CheckTausFile;
std::ofstream ViterbiFile;
std::ofstream ProbasCharsFile;
std::ofstream ProbasBinaryFile;
std::ofstream ProbasHRNumbersFile;
bool CheckTauCoherence;
std::string ViterbiFileName;
std::string NumbersProbasFileName;
std::string BinaryProbasFileName;
std::string CharsProbasFileName;
unsigned char *PositionsOf2;
/////////////
// Methods //
/////////////
public:
Imputator();
Imputator(unsigned short int MarkCO, std::string InputP,
std::string InputFN, std::string OutputP,
long double Thresh = 0.75, long double InitialC = 0.5,
bool DV = true, bool DP = true, bool CheckTaus = false);
unsigned int GetNbMarkers();
unsigned int GetNbInd();
private:
void Init();
void MoveForwardBackward();
void MoveForward(char *Ind);
void MoveBackward(char *Ind);
void Viterbi(char *Ind);
void WriteProbasImputation(char *Ind);
long double &GetTau(unsigned int Locus, unsigned int Letter);
long double &GetG(unsigned int Locus, unsigned int Letter);
long double &GetForward(unsigned int Locus, unsigned int Letter);
void CheckTaus();
long double ProbaToBe1FixedDigit(unsigned int Locus,
unsigned char DistanceToLocus);
void InitializeInitialProbabilities(char *Ind);
};
std::ostream &operator<<(std::ostream &s, const Imputator &I);
#endif
......@@ -3,67 +3,58 @@
using namespace Rcpp;
#include "GeneralFunctions_imp.h"
#include "Imputator.h"
#include "Transition.h"
#include "ToBinaryTransformer.h"
#include <iostream>
#include <string>
#include "Transition.h"
#include <assert.h>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
// [[Rcpp::export]]
void ImputatorCpp(NumericVector markov_order,
CharacterVector input_path,
CharacterVector input_filename,
CharacterVector output_path,
NumericVector threshold,
NumericVector initial_count,
LogicalVector do_viterbi,
LogicalVector do_probas) {
unsigned short int f0 = Rcpp::as<unsigned short int>(markov_order);
std::string f1 = Rcpp::as<std::string>(input_path);
std::string f2 = Rcpp::as<std::string>(input_filename);
std::string f3 = Rcpp::as<std::string>(output_path);
long double f4 = Rcpp::as<long double>(threshold);
long double f5 = Rcpp::as<long double>(initial_count);
bool f6 = Rcpp::as<bool>(do_viterbi);
bool f7 = Rcpp::as<bool>(do_probas);
Imputator(f0, f1, f2, f3, f4, f5, f6, f7);
void ImputatorCpp(NumericVector markov_order, CharacterVector input_path,
CharacterVector input_filename, CharacterVector output_path,
NumericVector threshold, NumericVector initial_count,
LogicalVector do_viterbi, LogicalVector do_probas) {
unsigned short int f0 = Rcpp::as<unsigned short int>(markov_order);
std::string f1 = Rcpp::as<std::string>(input_path);
std::string f2 = Rcpp::as<std::string>(input_filename);
std::string f3 = Rcpp::as<std::string>(output_path);
long double f4 = Rcpp::as<long double>(threshold);
long double f5 = Rcpp::as<long double>(initial_count);
bool f6 = Rcpp::as<bool>(do_viterbi);
bool f7 = Rcpp::as<bool>(do_probas);
Imputator(f0, f1, f2, f3, f4, f5, f6, f7);
}
// [[Rcpp::export]]
void ImpThreshold_cpp(CharacterVector probas_file,
CharacterVector output_file,
NumericVector threshold,
NumericVector nb_supp_elements,
NumericVector nb_cols,
LogicalVector replace_values,
LogicalVector do_threshold) {
std::string f1 = Rcpp::as<std::string>(probas_file);
std::string f2 = Rcpp::as<std::string>(output_file);
double f3 = Rcpp::as<double>(threshold);
int f4 = Rcpp::as<int>(nb_supp_elements);
int f5 = Rcpp::as<int>(nb_cols);
bool f6 = Rcpp::as<bool>(replace_values);
bool f7 = Rcpp::as<bool>(do_threshold);
void ImpThreshold_cpp(CharacterVector probas_file, CharacterVector output_file,
NumericVector threshold, NumericVector nb_supp_elements,
NumericVector nb_cols, LogicalVector replace_values,
LogicalVector do_threshold) {
std::string f1 = Rcpp::as<std::string>(probas_file);
std::string f2 = Rcpp::as<std::string>(output_file);
double f3 = Rcpp::as<double>(threshold);
int f4 = Rcpp::as<int>(nb_supp_elements);
int f5 = Rcpp::as<int>(nb_cols);
bool f6 = Rcpp::as<bool>(replace_values);
bool f7 = Rcpp::as<bool>(do_threshold);
ImpThreshold(f1, f2, f3, f4, f5, f6, f7);
ImpThreshold(f1, f2, f3, f4, f5, f6, f7);
}
// [[Rcpp::export]]
void txttovcfCpp(CharacterVector txt_filename,
CharacterVector vcf_filename,
CharacterVector output_filename,
NumericVector nb_supp_elements,
NumericVector nb_cols,
LogicalVector replace_values) {
std::string f1 = Rcpp::as<std::string>(txt_filename);
std::string f2 = Rcpp::as<std::string>(vcf_filename);
std::string f3 = Rcpp::as<std::string>(output_filename);
int f4 = Rcpp::as<int>(nb_supp_elements);
int f5 = Rcpp::as<int>(nb_cols);
bool f6 = Rcpp::as<bool>(replace_values);
void txttovcfCpp(CharacterVector txt_filename, CharacterVector vcf_filename,
CharacterVector output_filename,
NumericVector nb_supp_elements, NumericVector nb_cols,
LogicalVector replace_values) {
std::string f1 = Rcpp::as<std::string>(txt_filename);
std::string f2 = Rcpp::as<std::string>(vcf_filename);
std::string f3 = Rcpp::as<std::string>(output_filename);
int f4 = Rcpp::as<int>(nb_supp_elements);
int f5 = Rcpp::as<int>(nb_cols);
bool f6 = Rcpp::as<bool>(replace_values);
txt_to_vcf(f1, f2, f3, f4, f5, f6);
txt_to_vcf(f1, f2, f3, f4, f5, f6);
}
......@@ -6,85 +6,149 @@
using namespace Rcpp;
// ImputatorCpp
void ImputatorCpp(NumericVector markov_order, CharacterVector input_path, CharacterVector input_filename, CharacterVector output_path, NumericVector threshold, NumericVector initial_count, LogicalVector do_viterbi, LogicalVector do_probas);
RcppExport SEXP _LineImputer_ImputatorCpp(SEXP markov_orderSEXP, SEXP input_pathSEXP, SEXP input_filenameSEXP, SEXP output_pathSEXP, SEXP thresholdSEXP, SEXP initial_countSEXP, SEXP do_viterbiSEXP, SEXP do_probasSEXP) {
BEGIN_RCPP
void ImputatorCpp(NumericVector markov_order, CharacterVector input_path,
CharacterVector input_filename, CharacterVector output_path,
NumericVector threshold, NumericVector initial_count,
LogicalVector do_viterbi, LogicalVector do_probas);
RcppExport SEXP _LineImputer_ImputatorCpp(
SEXP markov_orderSEXP, SEXP input_pathSEXP, SEXP input_filenameSEXP,
SEXP output_pathSEXP, SEXP thresholdSEXP, SEXP initial_countSEXP,
SEXP do_viterbiSEXP, SEXP do_probasSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;