-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Very first version. Updating for efficiency and handling increased complexity to be done.
- Loading branch information
Showing
16 changed files
with
1,246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.