@@ -1359,14 +1359,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
13591359 }
13601360 else
13611361 {
1362- spectrum . precursorList = new PrecursorListType
1363- {
1364- count = "0" ,
1365- precursor = new PrecursorType [ 0 ]
1366- } ;
1367-
1368- Log . Error ( $ "Failed finding precursor for { scanNumber } ") ;
1369- ParseInput . NewError ( ) ;
1362+ spectrum . precursorList = ConstructPRMPrecursorList ( scanEvent , charge , isolationWidth ) ;
13701363 }
13711364 }
13721365 else
@@ -2424,6 +2417,152 @@ private PrecursorListType ConstructPrecursorList(int precursorScanNumber, IScanE
24242417
24252418 }
24262419
2420+ /// <summary>
2421+ /// Populate the precursor list element for PRM/MS2-only datasets (No MS1 scans)
2422+ /// </summary>
2423+ /// <param name="scanEvent">the scan event</param>
2424+ /// <param name="charge">the charge from trailer</param>
2425+ /// <param name="isolationWidth">the isolation width value from trailer</param>
2426+ /// <returns>the precursor list</returns>
2427+ private PrecursorListType ConstructPRMPrecursorList ( IScanEventBase scanEvent , int ? charge , double ? isolationWidth )
2428+ {
2429+ List < PrecursorType > precursors = new List < PrecursorType > ( ) ;
2430+
2431+
2432+ int msLevel = ( int ) scanEvent . MSOrder ;
2433+ IReaction reaction = scanEvent . GetReaction ( 0 ) ;
2434+ double precursorMz = reaction . PrecursorMass ;
2435+
2436+ //if isolation width was not found in the trailer, try to get one from the reaction
2437+ if ( isolationWidth == null ) isolationWidth = reaction . IsolationWidth ;
2438+
2439+ var precursor = new PrecursorType
2440+ {
2441+ selectedIonList =
2442+ new SelectedIonListType { count = "1" , selectedIon = new ParamGroupType [ 1 ] } ,
2443+ } ;
2444+
2445+ precursor . selectedIonList . selectedIon [ 0 ] = new ParamGroupType ( ) ;
2446+
2447+ var ionCvParams = new List < CVParamType >
2448+ {
2449+ new CVParamType
2450+ {
2451+ name = "selected ion m/z" ,
2452+ value = precursorMz . ToString ( CultureInfo . InvariantCulture ) ,
2453+ accession = "MS:1000744" ,
2454+ cvRef = "MS" ,
2455+ unitCvRef = "MS" ,
2456+ unitAccession = "MS:1000040" ,
2457+ unitName = "m/z"
2458+ }
2459+ } ;
2460+
2461+ if ( charge != null )
2462+ {
2463+ ionCvParams . Add ( new CVParamType
2464+ {
2465+ name = "charge state" ,
2466+ value = charge . ToString ( ) ,
2467+ accession = "MS:1000041" ,
2468+ cvRef = "MS"
2469+ } ) ;
2470+ }
2471+ precursor . selectedIonList . selectedIon [ 0 ] . cvParam = ionCvParams . ToArray ( ) ;
2472+
2473+ precursor . isolationWindow =
2474+ new ParamGroupType
2475+ {
2476+ cvParam = new CVParamType [ 3 ]
2477+ } ;
2478+
2479+ precursor . isolationWindow . cvParam [ 0 ] =
2480+ new CVParamType
2481+ {
2482+ accession = "MS:1000827" ,
2483+ name = "isolation window target m/z" ,
2484+ value = precursorMz . ToString ( CultureInfo . InvariantCulture ) ,
2485+ cvRef = "MS" ,
2486+ unitCvRef = "MS" ,
2487+ unitAccession = "MS:1000040" ,
2488+ unitName = "m/z"
2489+ } ;
2490+ if ( isolationWidth != null )
2491+ {
2492+ var offset = isolationWidth . Value / 2 + reaction . IsolationWidthOffset ;
2493+ precursor . isolationWindow . cvParam [ 1 ] =
2494+ new CVParamType
2495+ {
2496+ accession = "MS:1000828" ,
2497+ name = "isolation window lower offset" ,
2498+ value = ( isolationWidth . Value - offset ) . ToString ( CultureInfo . InvariantCulture ) ,
2499+ cvRef = "MS" ,
2500+ unitCvRef = "MS" ,
2501+ unitAccession = "MS:1000040" ,
2502+ unitName = "m/z"
2503+ } ;
2504+ precursor . isolationWindow . cvParam [ 2 ] =
2505+ new CVParamType
2506+ {
2507+ accession = "MS:1000829" ,
2508+ name = "isolation window upper offset" ,
2509+ value = offset . ToString ( CultureInfo . InvariantCulture ) ,
2510+ cvRef = "MS" ,
2511+ unitCvRef = "MS" ,
2512+ unitAccession = "MS:1000040" ,
2513+ unitName = "m/z"
2514+ } ;
2515+ }
2516+
2517+ // Activation
2518+ var activationCvParams = new List < CVParamType > ( ) ;
2519+ if ( reaction != null )
2520+ {
2521+ if ( reaction . CollisionEnergyValid )
2522+ {
2523+ activationCvParams . Add (
2524+ new CVParamType
2525+ {
2526+ accession = "MS:1000045" ,
2527+ name = "collision energy" ,
2528+ cvRef = "MS" ,
2529+ value = reaction . CollisionEnergy . ToString ( CultureInfo . InvariantCulture ) ,
2530+ unitCvRef = "UO" ,
2531+ unitAccession = "UO:0000266" ,
2532+ unitName = "electronvolt"
2533+ } ) ;
2534+ }
2535+
2536+ if ( ! OntologyMapping . DissociationTypes . TryGetValue ( reaction . ActivationType , out var activation ) )
2537+ {
2538+ activation = new CVParamType
2539+ {
2540+ accession = "MS:1000044" ,
2541+ name = "Activation Method" ,
2542+ cvRef = "MS" ,
2543+ value = ""
2544+ } ;
2545+ }
2546+
2547+ activationCvParams . Add ( activation ) ;
2548+ }
2549+
2550+ precursor . activation =
2551+ new ParamGroupType
2552+ {
2553+ cvParam = activationCvParams . ToArray ( )
2554+ } ;
2555+
2556+ precursors . Add ( precursor ) ;
2557+
2558+ return new PrecursorListType
2559+ {
2560+ count = precursors . Count . ToString ( ) ,
2561+ precursor = precursors . ToArray ( )
2562+ } ;
2563+
2564+ }
2565+
24272566 private int GetParentFromScanString ( string scanString )
24282567 {
24292568 var result = _filterStringIsolationMzPattern . Match ( scanString ) ;
0 commit comments