ChemStation How to create a macro to Extracting Specific Absorbance Signal from 3D IsoPlot

I have existing data from runs looking at a spectrum of wavelengths and am looking to streamline the 'saving to .csv' part of the process.
Currently I am opening each sample as an isoabsorbance plot and saving individual wavelengths as signals (eg 300-600 in increments of 10), then extracting those as .csv files.

For a more detailed explanation, I am following this method: 

  1.  Extracting Specific Absorbance Signal from 3D IsoPlot with OpenLab ChemStation: https://community.agilent.com/knowledge/chromatography-software-portal/kmp/chromatography-software-articles/kp764.extracting-specific-absorbance-signal-from-3d-isoplot-with-openlab-chemstation  
  2. then this:  How to Export XY Data from Chemstation or OpenLab ChemStation to a CSV File 
  3. Then combining the saves into one file with Time and Absorbance values for each wavelength.
      1. e.g
    Time 400 410 420
    0.00145 1.173496 1.142502 1.424313
    0.008117 1.178265 1.146317

    1.426697

I found this which is similar however is for the online/current runs only and not for already saved runs, and also for pre-set wavelengths and not spectrum:  RE: Post-run Macro to export Signal Raw Data to ASCII 

I have been having troubles trying to adapt this macro to be used in my case.
Any help will be appreciated.

  • Hi there,

    You can extract a specific signal from the DAD data by using the LoadChrom command;

    LoadChrom [Detector], [TimeRange], [WLRange], [RefWLRAnge], ToReg

    So for example LoadChrom, 0:0, 215:225, , ChromReg would load 220 nm with a bandwidth of 10 and no reference and would add this signal to the ChromReg register.  Note that this will not actually display the signal graphically; the DrawSignals macro can be used for displaying it although it's not necessary if you just want to extract the data to a .csv file.

    DrawSignals [DrawAnew], [DrawSig], [ChromNormalized], [ChromOverlaid], [ShowFileInfo], [FreezeLayout], [DrawCmd$], [ZoomSeparate]

    ex.; DrawSignals 1, 3,,,,1

    So you could have a macro that loads all the desired extracted signals to the ChromReg register and you can then go through the data (starting at the original RegSize + 1) by accessing that register using the signal numbers and looping through all of the data points as DataCols(ChromReg[signalIndex]) much like the example that you linked; Data(ChromReg[signalIndex], 0, a) would be the time and Data(ChromReg[signalIndex], 1, a) - you could then print that out to a text file and format it as you wish.  You could also go through the timepoints first and loop through the signals for each timepoint if you wanted an output file formatted as you had above.

    If this is part of a sequence, you could also set up your macro to run on all the files in the sequence and output the data file name and data to your .csv file.  You could also do that with single files in a folder, but you might need to access that list with an external script (ChemStation can run scripts through the ExecWait/ExecNoWait commands).

    Hope this helps.

  • Had to write something else this week and thought I would modify the code to exemplify what I meant above in more detail (this is sort of simple, but it should give you a good starting point and you can then modify as you wish);

    name exportAbsSignals
    parameter startWavelength default 190, endWavelength default 400, stepWavelength default 10, bandwidth default -1
    local exportDataReg$, signalID, outputFile$, currentFile$, a, b, currentWavelength, lineToPrint$, errorNumber

    exportDataReg$ = "userAbsSignals"
    signalID = 1 !use the first one, shouldn't matter
    errorNumber = 0
    outputFile$ = DADATAPATH$ + "absSignals.txt"
    OPEN outputFile$ FOR OUTPUT as #33

    If (RegSize(exportDataReg$) > 0) Then
      DelReg(exportDataReg$)
    EndIf

    If (_MethodSequence = 1) Then !Example using a sequence folder; but one could replace this by going through specified files in a folder as well and load them by path/name
      For a = 1 to TabHdrVal(_SEQUENCE[1], "SeqTable1", "NumberOfRows")
        currentFile$ = DADATAPATH$ + TabText$(_SEQUENCE[1], "SeqTable1", a, "DataFileName") + ".D"
        If (FILESTAT(MODE, currentFile$) <> -1) Then
          LoadFile currentFile$, 0
          !Cross-check parameters
          If (startWavelength < ObjHdrVal("RC" + ConvertText$(trim, ObjHdrText$(ChromReg[1], "Detector")) + "Method[1]", "SpectraAcquisition_From")) Then
            startWavelength = ObjHdrVal("RC" + ConvertText$(trim, ObjHdrText$(ChromReg[1], "Detector")) + "Method[1]", "SpectraAcquisition_From")
          EndIf
          If (endWavelength > ObjHdrVal("RC" + ConvertText$(trim, ObjHdrText$(ChromReg[1], "Detector")) + "Method[1]", "SpectraAcquisition_To")) Then
            endWavelength = ObjHdrVal("RC" + ConvertText$(trim, ObjHdrText$(ChromReg[1], "Detector")) + "Method[1]", "SpectraAcquisition_To")
          EndIf
          !could add code here to modify the step based on start/end, using a percentage step instead
          If (stepWavelength < ObjHdrVal("RC" + ConvertText$(trim, ObjHdrText$(ChromReg[1], "Detector")) + "Method[1]", "SpectraAcquisition_Step")) Then
            stepWavelength = ObjHdrVal("RC" + ConvertText$(trim, ObjHdrText$(ChromReg[1], "Detector")) + "Method[1]", "SpectraAcquisition_Step")
          EndIf
          If (bandwidth = -1) Then !use the one set in the method for the first signal (could override this)
            bandwidth = ObjHdrVal("RC" + ConvertText$(trim, ObjHdrText$(ChromReg[1], "Detector")) + "Method[1]", "Signal_Bandwidth")
          EndIf
          print #33, dadatapath$ + dadatafile$ + chr$(13) + chr$(10) !+ "Time" + chr$(09) + "Absorbance"
          lineToPrint$ = "Time (mins)" + chr$(09) + chr$(09)
          currentWavelength = startWavelength
          While (currentWavelength <= endWavelength)
            LoadChrom ObjHdrText$(ChromReg[signalID], "Detector"), 0:0, currentWavelength-bandwidth:currentWavelength+bandwidth, , exportDataReg$
            NewObjHdrVal exportDataReg$ + "[" + Val$(RegSize(exportDataReg$)) + "]", "Wavelength", currentWavelength
            lineToPrint$ = lineToPrint$ + Val$(currentWavelength) + " [" + Val$(bandwidth) + "] nm" + chr$(09) !should add error-checking here in case of mismatch
            currentWavelength = currentWavelength + stepWavelength
          EndWhile
          lineToPrint$ = lineToPrint$ + chr$(13) + chr$(10)
          print #33, linetoPrint$
          lineToPrint$ = ""
          !currentWavelength = startWavelength
          numberOfDataPoints = Datacols(exportDataReg$ + "[1]") !based off the first one; assume all files have the same start/end
          For b = 1 to numberOfDataPOints
          currentWavelength = startWavelength
            For c = 1 to RegSize(exportDataReg$)
              If (ObjHdrVal(exportDataReg$ + "[" + Val$(c) + "]", "Wavelength") = currentWavelength) Then
                If (c = 1) Then
                  lineToPrint$ = Val$(Data(exportDataReg$ + "[" + Val$(c) + "]", 0, b)) + chr$(09)
                EndIf
                lineToPrint$ = lineToPrint$ + chr$(09) + Val$(Data(exportDataReg$ + "[" + Val$(c) + "]", 1, b))
              Else
                !should add error-checking here also in case of mismatch
              EndIf
              currentWavelength = currentWavelength + stepWavelength    
            Next c
              print #33, lineToPrint$
              lineToPrint$ = ""
          Next b
        Else
          errorNumber = 1
          GoTo macroEnd
        EndIf
        print #33, chr$(13) + chr$(10)
      Next a
    Else
      print "Current macro set for sequences only."
    EndIf

    macroEnd:
    If (errorNumber = 1) Then !this is where we could address other errors as well
      print "File not found; " + currentFile$ + "."
    Else
      print "Export completed; output file located at " + outputFile$ + "."
    EndIf

    close #33
    endmacro

  • Good to see another Chemstation macro creator in the community Slight smile

    /Andy

  • It's most definitely a bit of a lost art.  : )

Was this helpful?