Browse code

Preserve MS precursor data

- Preserve MS precursor data even if precursor scan is not available (issue 256
in MSnbase).

jotsetung authored on 19/09/2017 05:45:47
Showing 1 changed files

... ...
@@ -671,13 +671,24 @@ void RcppPwiz::addSpectrumList(MSData& msd,
671 671
     }
672 672
     // MSn - precursor:
673 673
     if (precursorScanNum[i] > 0 | precursorMZ[i] > 0) {
674
+      // Fill precursor data. This preserves the precursor data even if the
675
+      // precursor scan is not available (e.g. after MS level filtering).
676
+      spct.precursors.resize(1);
677
+      Precursor& prec = spct.precursors.front();
678
+      if (collisionEnergy[i] != 0) {
679
+	prec.activation.set(MS_collision_induced_dissociation);
680
+	prec.activation.set(MS_collision_energy, collisionEnergy[i],
681
+			    UO_electronvolt);
682
+      }
683
+      prec.selectedIons.resize(1);
684
+      prec.selectedIons[0].set(MS_selected_ion_m_z, precursorMZ[i], MS_m_z);
685
+      prec.selectedIons[0].set(MS_peak_intensity, precursorIntensity[i],
686
+			       MS_number_of_detector_counts);
687
+      prec.selectedIons[0].set(MS_charge_state, precursorCharge[i]);
674 688
       // Get the spectrumId of the precursor. Assuming that precursorScanNum is
675 689
       // linked to the acquisitionNum of the precursor.
676 690
       // This seems to be correct, since both the acquisitionNum and the
677 691
       // precursorNum are extracted from the respective spectrum's ID.
678
-      // Also, if we DON'T find the precursorScanNum among the acquisitionNum
679
-      // we skip adding the precursor data. Might be that the MS data has been
680
-      // filtered and the precursor scan is not provided.
681 692
       precursor_idx = -1;
682 693
       for (int j = 0; j < spctr_data.size(); j++) {
683 694
 	if (precursorScanNum[i] == acquisitionNum[j]) {
... ...
@@ -686,19 +697,7 @@ void RcppPwiz::addSpectrumList(MSData& msd,
686 697
 	}
687 698
       }
688 699
       if (precursor_idx >= 0) {
689
-	spct.precursors.resize(1);
690
-	Precursor& prec = spct.precursors.front();
691 700
 	prec.spectrumID = spectrumId[precursor_idx];
692
-	if (collisionEnergy[i] > 0) {
693
-	  prec.activation.set(MS_collision_induced_dissociation);
694
-	  prec.activation.set(MS_collision_energy, collisionEnergy[i],
695
-			      UO_electronvolt);
696
-	}
697
-	prec.selectedIons.resize(1);
698
-	prec.selectedIons[0].set(MS_selected_ion_m_z, precursorMZ[i], MS_m_z);
699
-	prec.selectedIons[0].set(MS_peak_intensity, precursorIntensity[i],
700
-				 MS_number_of_detector_counts);
701
-	prec.selectedIons[0].set(MS_charge_state, precursorCharge[i]);
702 701
       }
703 702
     }
704 703
     // [X] collisionEnergy