Skip to content

Commit

Permalink
Fixed centroiding algorithm to process peaks beyond 2000 m/z.
Browse files Browse the repository at this point in the history
Added new parameter molecule_max_mz, which sets the upper boundary of molecules to find features for.
  • Loading branch information
mhoopmann committed Nov 11, 2019
1 parent bc1d152 commit 9564c11
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
13 changes: 10 additions & 3 deletions CHardklor2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,13 @@ void CHardklor2::Centroid(Spectrum& s, Spectrum& out){

out.clear();

//Get boundaries of the spectrum. centroids must be within boundaries.
double minMZ, maxMZ;
if(s.size()>0){
minMZ = s[0].mz;
maxMZ = s[s.size()-1].mz;
}

bLastPos=false;
for(i=0;i<s.size()-1;i++){

Expand Down Expand Up @@ -385,9 +392,9 @@ void CHardklor2::Centroid(Spectrum& s, Spectrum& out){
centroid.intensity=s[bestPeak].intensity;
}

//Hack until I put in mass ranges
if(centroid.mz<0 || centroid.mz>2000) {
//do nothing if invalid mz
//Centroided peaks must fall within spectrum mass range
if(centroid.mz<minMZ || centroid.mz>maxMZ) {
//do nothing if invalid mz, but perhaps find a better way to handle this one day.
} else {
out.add(centroid);
}
Expand Down
4 changes: 4 additions & 0 deletions CHardklorParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ void CHardklorParser::parse(char* cmd) {
strcpy(global.MercuryFile,tok);

} else if(strcmp(param,"max_features")==0){

} else if(strcmp(param,"molecule_max_mz")==0){
global.maxMolMZ=atof(tok);

} else if(strcmp(param,"ms_level")==0){
if(atoi(tok)==3){
global.mzXMLFilter=MS3;
Expand Down
6 changes: 6 additions & 0 deletions CHardklorSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ CHardklorSetting::CHardklorSetting(){
//rawAvgWidth=1;
//rawAvgCutoff=1000;

maxMolMZ=5000;

strcpy(rawFilter,"");
}

Expand Down Expand Up @@ -134,6 +136,9 @@ CHardklorSetting::CHardklorSetting(const CHardklorSetting& c){
//rawAvg=c.rawAvg;
//rawAvgWidth=c.rawAvgWidth;
//rawAvgCutoff=c.rawAvgCutoff;

maxMolMZ=c.maxMolMZ;

strcpy(rawFilter,c.rawFilter);
}

Expand Down Expand Up @@ -199,6 +204,7 @@ CHardklorSetting& CHardklorSetting::operator=(const CHardklorSetting& c){
//rawAvg=c.rawAvg;
//rawAvgWidth=c.rawAvgWidth;
//rawAvgCutoff=c.rawAvgCutoff;
maxMolMZ = c.maxMolMZ;

strcpy(rawFilter,c.rawFilter);
}
Expand Down
1 change: 1 addition & 0 deletions CHardklorSetting.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class CHardklorSetting {
int smooth; //Savitsky-Golay smoothing window size
//int sna; //Signal-to-noise algorithm; 0=THRASH, 1=Persistent peaks (PP)

double maxMolMZ; //Largest m/z to detect in the data
double corr; //correlation threshold
double ppm; //ppm tolerance of m/z values to match across scans
double res400; //resolution at m/z 400
Expand Down
15 changes: 13 additions & 2 deletions CModelLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ bool CModelLibrary::buildLibrary(int lowCharge, int highCharge, vector<CHardklor
return false;
}

//Fill in boundaries
//Fill in boundaries; Note Nov11_2019: This needs dynamic updating, perhaps drawn from a new parameter.
chargeMin=lowCharge;
chargeCount=highCharge+1;
varCount=(int)pepVariants.size();
merCount=1000;
if(merCount==0) merCount=1000;

libModel = new mercuryModel**[chargeCount];
for(i=chargeMin;i<chargeCount;i++){
Expand Down Expand Up @@ -127,12 +127,23 @@ void CModelLibrary::eraseLibrary(){
delete [] libModel;

libModel=NULL;
merCount=0;

}

mercuryModel* CModelLibrary::getModel(int charge, int var, double mz){

int intMZ=(int)(mz/5);

//punting this for now. A better solution needs to be made, but will wait until necessary.
if(intMZ>=merCount) {
cout << "Spectrum feature beyond molecule_max_mz. Hard boundary encountered. Please increase molecule_max_mz." << endl;
exit(-47);
}
return &libModel[charge][var][intMZ];

}

void CModelLibrary::setSize(double mz){
merCount=(int)(mz/5)+1;
}
1 change: 1 addition & 0 deletions CModelLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CModelLibrary {
bool buildLibrary(int lowCharge, int highCharge, std::vector<CHardklorVariant>& pepVariants);
void eraseLibrary();
mercuryModel* getModel(int charge, int var, double mz);
void setSize(double mz);

protected:

Expand Down
5 changes: 3 additions & 2 deletions HardklorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ int main(int argc, char* argv[]) {
CMercury8 *mercury;
CModelLibrary *models;

cout << "Hardklor v2.3.1, April 23 2018" << endl;
cout << "Mike Hoopmann, Mike MacCoss\nCopyright 2007-2018\nUniversity of Washington" << endl;
cout << "Hardklor v2.3.2, November 11 2019" << endl;
cout << "Mike Hoopmann, Mike MacCoss\nCopyright 2007-2019\nUniversity of Washington" << endl;
if(argc < 2 || (argc>2 && strcmp(argv[1],"-cmd")!=0) ){
cout << "Usage:\t\thardklor <config file>\n";
cout << "\t\thardklor -cmd [options] <input file> <output file>\n" << endl;
Expand Down Expand Up @@ -78,6 +78,7 @@ int main(int argc, char* argv[]) {
for(j=0;j<hp.queue(i).variant->size();j++) pepVariants.push_back(hp.queue(i).variant->at(j));

models->eraseLibrary();
models->setSize(hp.queue(i).maxMolMZ);
models->buildLibrary(hp.queue(i).minCharge,hp.queue(i).maxCharge,pepVariants);
h2.GoHardklor(hp.queue(i));
} else {
Expand Down

0 comments on commit 9564c11

Please sign in to comment.