Skip to content

Commit

Permalink
Export MIDs for all labeled ions
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Feb 6, 2017
1 parent bd462a7 commit db1cbbc
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gui/miamainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ void MIAMainWindow::exportMIDs()
QFile f(filename);
f.open(QIODevice::WriteOnly);
QTextStream out(&f);
networkSet->exportMIDs(out);
networkSet->exportAllMIDs(out);
}

void MIAMainWindow::updateCompoundList()
Expand Down
127 changes: 108 additions & 19 deletions src/labelingnetworkset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,28 @@ LabelingNetworkSet::~LabelingNetworkSet()
}
}

void LabelingNetworkSet::exportMIDs(QTextStream &qout)
void LabelingNetworkSet::exportSelectedMIDs(QTextStream &qout)
{
std::stringstream out;
std::string sep = ",";
std::string quote = "\"";

// header
out<<"Metabolite"<<sep<<"RI"<<sep<<"Ions (M0)"<<sep<<"M";
// header abundances
for(int ds = 0; ds < datasets.size(); ++ds) { // each experiment
std::string t = datasets[ds]->getSettings().experiment;
out <<sep<<quote<<t<<quote;
}
for(int ds = 0; ds < datasets.size(); ++ds) { // confidence intervals
// header confidence intervals
for(int ds = 0; ds < datasets.size(); ++ds) { // each experiment
std::string t = "CI " + datasets[ds]->getSettings().experiment;
out <<sep<<quote<<t<<quote;
}
out<<std::endl;

// data
for(int n = 0; n < nodes.size(); ++n) {
for(int n = 0; n < nodes.size(); ++n) { // foreach compound
NodeCompound *nc = nodes[n];

// determine max. MID length for this compound
Expand All @@ -73,22 +75,11 @@ void LabelingNetworkSet::exportMIDs(QTextStream &qout)
}
}

// ri
double ri = 0;
double riCount = 0;
for(int ds = 0; ds < datasets.size(); ++ds) { // each experiment
std::string t = datasets[ds]->getSettings().experiment;
if(nc->hasDataForExperiment(t)) {
ri += nc->getLabeledCompound(t)->getRetentionIndex();
++riCount;
}
}

ri /= riCount;
double ri = nc->getAverageRetentionIndex();


// list of selected ions m/z
std::stringstream ions;

for(int ds = 0; ds < datasets.size(); ++ds) { // each experiment
std::string t = datasets[ds]->getSettings().experiment;
double ion = 0;
Expand All @@ -99,7 +90,8 @@ void LabelingNetworkSet::exportMIDs(QTextStream &qout)
ions << ion << " ";
}

for(int i = 0; i < midLen; ++i) {
// abundances and confidence interval
for(int i = 0; i < midLen; ++i) { // for each M+x
out<<quote<<nc->getCompoundName()<<quote<<sep<<ri<<sep<<ions.str()<<sep<<i;

// abundance
Expand All @@ -125,15 +117,112 @@ void LabelingNetworkSet::exportMIDs(QTextStream &qout)
out << sep;
out << (ci.size() > i ? ci[i] : 0);
}

// out<<sep<<nc->getANOVAPvalueForMassIsotopomer(i);
out<<std::endl;
}
}

qout<<out.str().c_str();
}

void LabelingNetworkSet::exportAllMIDs(QTextStream &qout)
{
std::stringstream out;
std::string sep = ",";
std::string quote = "\"";

// header
out<<"Metabolite"<<sep<<"RI"<<sep<<"Ions (M0)"<<sep<<"M";
// header abundances
for(int ds = 0; ds < datasets.size(); ++ds) { // each experiment
std::string t = datasets[ds]->getSettings().experiment;
out <<sep<<quote<<t<<quote;
}
// header confidence intervals
for(int ds = 0; ds < datasets.size(); ++ds) { // each experiment
std::string t = "CI " + datasets[ds]->getSettings().experiment;
out <<sep<<quote<<t<<quote;
}
out<<std::endl;

// data
for(int n = 0; n < nodes.size(); ++n) { // foreach compound
NodeCompound *nc = nodes[n];

std::set<int> lions = nc->getAllLabeledIons();
for(std::set<int>::iterator it = lions.begin(); it != lions.end(); ++it) {
int ion = *it;

// determine max. MID length for this ion
int midLen = 0;
for(int ds = 0; ds < datasets.size(); ++ds) { // each experiment
std::string t = datasets[ds]->getSettings().experiment;
if(nc->hasDataForExperiment(t)) {
// index of ion
const std::vector<float> tmpIons = nc->getLabeledCompound(t)->getLabeledIons();
for(int i = 0; i < tmpIons.size(); ++i) {
if((int)tmpIons[i] == ion) {
midLen = std::max(midLen, (int) (nc->getLabeledCompound(t)->getIsotopomers()[i].size()));
break;
}
}
}
}
double ri = nc->getAverageRetentionIndex();

// abundances and confidence interval
for(int i = 0; i < midLen; ++i) { // for each M+x
out<<quote<<nc->getCompoundName()<<quote<<sep<<ri<<sep<<ion<<sep<<i;

// abundance
for(int ds = 0; ds < datasets.size(); ++ds) { // each experiment
std::string t = datasets[ds]->getSettings().experiment;
std::vector<double> mid;

if(nc->hasDataForExperiment(t)) {
// index of ion
const std::vector<float> tmpIons = nc->getLabeledCompound(t)->getLabeledIons();

for(int j = 0; j < tmpIons.size(); ++j) {

if((int)tmpIons[j] == ion) {
mid = nc->getLabeledCompound(t)->getIsotopomers()[j];
break;
}
}
}

out << sep;
out << (mid.size() > i ? mid[i] : 0);
}

// confidence interval
for(int ds = 0; ds < datasets.size(); ++ds) { // each experiment
std::string t = datasets[ds]->getSettings().experiment;
std::vector<double> ci;

if(nc->hasDataForExperiment(t)) {
// index of ion
const std::vector<float> tmpIons = nc->getLabeledCompound(t)->getLabeledIons();
for(int j = 0; j < tmpIons.size(); ++j) {
if((int)tmpIons[j] == ion) {
ci = nc->getLabeledCompound(t)->getConfidenceIntervals()[j];
break;
}
}
}

out << sep;
out << (ci.size() > i ? ci[i] : 0);
}
out<<std::endl;
}
}
}

qout<<out.str().c_str();
}


bool LabelingNetworkSet::nodeHasEdges(int n)
{
bool connected = false;
Expand Down
4 changes: 3 additions & 1 deletion src/labelingnetworkset.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class LabelingNetworkSet : public QObject
LabelingNetworkSet();
~LabelingNetworkSet();

void exportMIDs(QTextStream &qout);
void exportSelectedMIDs(QTextStream &qout);

void exportAllMIDs(QTextStream &qout);

bool nodeHasEdges(int n);

Expand Down
18 changes: 18 additions & 0 deletions src/nodecompound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ labid::LabeledCompound *NodeCompound::getLabeledCompound(std::string experiment)
return lcs[idx];
}

labid::LabeledCompound *NodeCompound::getLabeledCompound(QString experiment)
{
int idx = experimentsLab.indexOf(experiment);
return lcs[idx];
}

void NodeCompound::removeLabeledCompound(labid::LabeledCompound *lc)
{
int idx = lcs.indexOf(lc);
Expand Down Expand Up @@ -410,6 +416,18 @@ double NodeCompound::getANOVAPvalue(std::vector<double> means, std::vector<doubl
return p;
}

double NodeCompound::getAverageRetentionIndex()
{
double ri = 0;
double riCount = 0;
foreach(QString key, experimentsLab){
ri += getLabeledCompound(key)->getRetentionIndex();
++riCount;
}

return ri /= riCount;
}

std::vector<std::string> NodeCompound::getExperiments()
{
std::vector<std::string> v;
Expand Down
2 changes: 2 additions & 0 deletions src/nodecompound.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class NodeCompound

void addLabeledCompound(std::string experiment, labid::LabeledCompound *lc);
labid::LabeledCompound *getLabeledCompound(std::string experiment);
labid::LabeledCompound *getLabeledCompound(QString experiment);
void removeLabeledCompound(labid::LabeledCompound *);
void addUnlabeledCompound(std::string experiment, labid::LISpectrum *ls);
labid::LISpectrum* getUnlabeledCompound(std::string experiment);
Expand All @@ -64,6 +65,7 @@ class NodeCompound
double getMinANOVAPvalue();
double getANOVAPvalueForMassIsotopomer(int m);
double getANOVAPvalue(std::vector<double> means, std::vector<double> sds, int n);
double getAverageRetentionIndex();

std::vector<std::string> getExperiments(); // The different tracer names // unique!
bool hasDataForExperiment(std::string);
Expand Down

0 comments on commit db1cbbc

Please sign in to comment.