Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Very first version. Updating for efficiency and handling increased complexity to be done.
  • Loading branch information
drarwood authored Oct 4, 2018
1 parent 477b0fa commit 5a2b94a
Show file tree
Hide file tree
Showing 16 changed files with 1,246 additions and 0 deletions.
70 changes: 70 additions & 0 deletions Calculator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// GAGS
// Developed by Andrew R Wood
// [email protected]

#include "Calculator.h"
#include <math.h>
#include <vector>
#include <cmath>

using namespace std;


double CalcVariance(vector<double>& v) {
double s;
double m;
int i;
s=0;
for (i=0;i<v.size();++i) {
s+=v[i];
}
m=s/(double) v.size();
s=0;
for (i=0;i<v.size();++i) {
s+=(v[i]-m)*(v[i]-m);
}
return (s/(v.size()-1)) ;
}


double CalcMean(vector<double>& v) {
double s;
s=0;
for (int i=0;i<v.size();++i) {
s+=v[i];
}
return s/v.size();
}


double CalcSum(vector<double>& v) {
double s;
s=0;
for (int i=0;i<v.size();++i) {
s+=v[i];
}
return s;
}


bool doubleEqual(double l, double r, double e) {
return (fabs(l-r)<e);
}


bool doubleLess(double l, double r, double e, bool orequal) {
if (fabs(l-r)<e) {
// within epsilon so considered equal
return orequal;
}
return (l<r);
}


bool doubleGreater(double l, double r, double e, bool orequal) {
if (fabs(l-r)<e) {
// within epsilon so considered equal
return orequal;
}
return (l>r);
}
13 changes: 13 additions & 0 deletions Calculator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __CALCULATOR__
#define __CALCULATOR__

#include <vector>
#include <string>

double CalcVariance(std::vector<double>&);
double CalcMean(std::vector<double>&);
bool doubleEqual(double, double, double);
bool doubleLess(double, double, double, bool);
bool doubleGreater(double, double, double, bool);

#endif
28 changes: 28 additions & 0 deletions ExclusionListProcessor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// GAGS
// Developed by Andrew R Wood
// [email protected]

#include "ExclusionListProcessor.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>

using namespace std;

void ReadExclusionsFile(string f, map<string, int>& m) {
string line, id;
ifstream inFile(f.c_str());
if (inFile.is_open()) {
while (inFile.good()) {
getline (inFile, line);
if (!line.empty()) {
m[line] = 0;
}
}
inFile.close();
}
else {
cout << "Unable to open " << f << " for reading" << endl;
exit(EXIT_FAILURE);
}
}
9 changes: 9 additions & 0 deletions ExclusionListProcessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __ExclusionListProcessor__
#define __ExclusionListProcessor__

#include <string>
#include <map>

void ReadExclusionsFile(std::string, std::map<std::string, int>&);

#endif
73 changes: 73 additions & 0 deletions FileWriter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// GAGS
// Developed by Andrew R Wood
// [email protected]

#include "FileWriter.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>

using namespace std;

void OutputSolution(vector<string>& s, map<string,double>& m, vector<int>& n, string& o, int& g) {
ofstream outFile;
outFile.open(o.c_str(), ios_base::out);
if (outFile.is_open()) {
int index = 0;
//int group = 0;
int offset = 0;
outFile << "Group\tID\tPhenotype\n";
for (int i = 0; i < n.size(); ++i) {
//group++;
while (index < n[i] + offset) {
outFile << g << "\t" << s[index] << "\t" << m[s[index]] << endl;
index++;
}
offset = offset + index;
g++;
}
outFile.close();
}
else {
cout << "Can not open " << o << " for writing" << endl;
exit(EXIT_FAILURE);
}
}

void OutputIndependentSolution(vector<string>& s, map<string,double>& m, vector<int>& n, string& o, int& g) {

ofstream outFile;

if (g == 1) {
outFile.open(o.c_str(), ios_base::out);
if (outFile.is_open()) {
outFile << "Group\tID\tPhenotype\n";
for (int i = 0; i < n.size(); ++i) {
for (int j = 0; j < n[i]; ++j) {
outFile << g << "\t" << s[j] << "\t" << m[s[j]] << endl;
}
}
outFile.close();
}
else {
cout << "Can not open " << o << " for writing" << endl;
exit(EXIT_FAILURE);
}
}
else {
outFile.open(o.c_str(), ios_base::app);
if (outFile.is_open()) {
for (int i = 0; i < n.size(); ++i) {
for (int j = 0; j < n[i]; ++j) {
outFile << g << "\t" << s[j] << "\t" << m[s[j]] << endl;
}
}
outFile.close();
}
else {
cout << "Can not open " << o << " for appending" << endl;
exit(EXIT_FAILURE);
}
}
}

11 changes: 11 additions & 0 deletions FileWriter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __FILEWRITER__
#define __FILEWRITER__

#include <string>
#include <vector>
#include <map>

void OutputSolution(std::vector<std::string>&, std::map<std::string, double>&, std::vector<int>&, std::string&, int&);
void OutputIndependentSolution(std::vector<std::string>&, std::map<std::string, double>&, std::vector<int>&, std::string&, int&);

#endif
Loading

0 comments on commit 5a2b94a

Please sign in to comment.