21 int main(
int argc,
char *argv[])
27 cerr <<
"USAGE : " << argv[0] <<
" (Rangefile| Ion list)" << endl;
36 if(!rng.
open(argv[1]))
38 cerr <<
"Failed to open rangefile :" << argv[1] << rng.
getErrString() << endl;
41 cerr <<
"Rangefile has :" << rng.
getNumIons() <<
" ranges, and " << rng.
getNumIons() <<
" ions." << endl;
49 for(
unsigned int ui=1;ui<argc;ui++)
50 ionNames.insert(
string(argv[ui]));
52 for(
const auto & ionName : ionNames)
57 rng.
addIon(s.c_str(),s.c_str(),rgbf);
64 if(natTable.
open(
"naturalAbundance.xml"))
66 cerr <<
"failed to open natural abundance file" << endl;
75 const float MASS_DELTA=0.05;
77 const unsigned int MAX_CHARGE=3;
78 vector<pair<size_t,size_t> > overlapIdx;
79 vector<pair<float,float> > overlapMass;
80 findOverlaps(natTable,rng,MASS_DELTA,MAX_CHARGE,overlapIdx,overlapMass);
82 cerr <<
"Found :" << overlapIdx.size() <<
" overlaps, using max charge=" << MAX_CHARGE <<
" and mass delta=" << MASS_DELTA << endl;
87 ofstream f(
"dotFile.txt");
90 cerr <<
"Unable to open output file." <<endl;
95 vector<pair<string, unsigned int> > nodeList;
96 vector<string> nodeNames;
97 for(
unsigned int ui=0; ui<overlapIdx.size(); ui++)
100 unsigned int rawId,id,charge;
101 rawId =overlapIdx[ui].first;
102 id = rawId/MAX_CHARGE;
103 charge=rawId%MAX_CHARGE +1;
104 nodeList.push_back( make_pair(rng.
getName(
id), charge) );
109 std::stringstream buffer;
110 buffer <<
"\"" << rng.
getName(
id) <<
"|" << charge <<
"+\" ";
111 buffer <<
" [ label = <" << rng.
getName(
id) <<
"<SUP>" << charge <<
"+</SUP>> ];" << endl;
112 nodeNames.push_back(buffer.str());
115 rawId =overlapIdx[ui].second;
116 id = rawId/MAX_CHARGE;
117 charge=rawId%MAX_CHARGE+1;
118 nodeList.push_back( make_pair(rng.
getName(
id), charge) );
122 buffer <<
"\"" << rng.
getName(
id) <<
"|" << charge <<
"+\" ";
123 buffer <<
" [ label = <" << rng.
getName(
id) <<
"<SUP>" << charge <<
"+</SUP>> ];" << endl;
124 nodeNames.push_back(buffer.str());
132 f <<
"strict graph overlap_map {" << endl;
136 set <std::string> uniqueStrings;
137 for (
auto & nodeName : nodeNames)
139 uniqueStrings.insert(nodeName);
142 for (
const auto & uniqueString : uniqueStrings)
147 for(
unsigned int ui=0; ui<overlapIdx.size(); ui++)
150 f <<
"\"" << nodeList[ui*2].first <<
"|" << nodeList[ui*2].second <<
"+\" -- ";
152 f <<
"\"" << nodeList[ui*2+1].first <<
"|" << nodeList[ui*2+1].second <<
"+\"";
155 float avgMass = (overlapMass[ui].first + overlapMass[ui].second)/2.0;
156 f <<
" [ label = \"" << std::fixed << std::setprecision( 1 ) << avgMass <<
"\" ];" << endl;
161 cerr <<
"Wrote overlaps to dotFile.txt" << endl;
std::string getName(unsigned int ionID, bool shortName=true) const
Get the short name or long name of a specified ionID.
unsigned int addIon(const std::string &shortName, const std::string &longName, const RGBf &ionCol)
Add the ion to the database returns ion ID if successful, -1 otherwise.
Data holder for colour as float.
void findOverlaps(const AbundanceData &natData, const RangeFile &rng, float massDelta, unsigned int maxCharge, std::vector< std::pair< size_t, size_t > > &overlapIdx, std::vector< std::pair< float, float > > &overlapMasses)
Find the overlaps stemming from a given rangefile.
int main(int argc, char *argv[])
size_t open(const char *file, bool strict=false)
Attempt to open the abundance data file, return 0 on success, nonzero on failure. ...
Class to load abundance information for natural isotopes.
bool open(const char *rangeFile)
Open a specified range file - returns true on success.
Data storage and retrieval class for various range files.
unsigned int getNumIons() const
Get the number of unique ions.
std::string getErrString() const
Retrieve the translated error associated with the current range file state.