Browse code

Add function to access SpectrumIdentificationResult-level cvParams

Bryson Gibbons authored on 11/05/2018 06:12:08
Showing 2 changed files

... ...
@@ -319,6 +319,62 @@ Rcpp::DataFrame RcppIdent::getScore(  )
319 319
     }
320 320
 }
321 321
 
322
+Rcpp::DataFrame RcppIdent::getSpecParams(  )
323
+{
324
+    vector<SpectrumIdentificationResultPtr> spectrumIdResult = mzid->analysisCollection.spectrumIdentification[0]->spectrumIdentificationListPtr->spectrumIdentificationResult;
325
+    vector<string> spectrumID;
326
+    vector<string> names;
327
+    int count = 0;
328
+
329
+    for(size_t i = 0; i < spectrumIdResult[0]->cvParams.size(); i++)
330
+    {
331
+        if(!spectrumIdResult[0]->cvParams[i].value.empty())
332
+        {
333
+            count++;
334
+            names.push_back(cvTermInfo(spectrumIdResult[0]->cvParams[i].cvid).name);
335
+        }
336
+    }
337
+    if(count == 0)
338
+    {
339
+        Rcpp::Rcout << "No scoring information available" << std::endl;
340
+        return Rcpp::DataFrame::create();
341
+    }
342
+    else
343
+    {
344
+        vector<vector<string> > score(count);
345
+
346
+        for (size_t i = 0; i < spectrumIdResult.size(); i++)
347
+        {
348
+            spectrumID.push_back(spectrumIdResult[i]->spectrumID);
349
+            count = 0;
350
+            for(size_t j = 0; j < spectrumIdResult[i]->cvParams.size(); j++)
351
+            {
352
+                if(!spectrumIdResult[i]->cvParams[j].value.empty())
353
+                {
354
+                    score[count].push_back(lexical_cast<string>(spectrumIdResult[i]->cvParams[j].value));
355
+                    count++;
356
+                }
357
+            }
358
+        }
359
+
360
+        Rcpp::List res(score.size() + 1);
361
+        
362
+        names.insert(names.begin(), "spectrumID");
363
+        
364
+        res[0] = Rcpp::wrap(spectrumID);
365
+        
366
+        for(size_t i = 0; i < score.size(); i++)
367
+        {
368
+            res[i + 1] = Rcpp::wrap(score[i]);
369
+        }
370
+        
371
+        res.attr("names") = names;
372
+        Rcpp::DataFrame out(res);
373
+
374
+        return out;
375
+    }
376
+}
377
+
322 378
 Rcpp::List RcppIdent::getPara(  )
323 379
 {
324 380
 
... ...
@@ -52,6 +52,8 @@ public:
52 52
 
53 53
     Rcpp::DataFrame getScore();
54 54
 
55
+    Rcpp::DataFrame getSpecParams();
56
+
55 57
     Rcpp::List getPara();
56 58
 
57 59
     Rcpp::DataFrame getDB();