What does the Macro do?
This macro takes the input DataTable from the Chemical Shift Mapping analysis which lists all the data per dimension and then creates a new DataTable which lists
the data per peak. This is useful if you wish to export the data to another program.
You will need to make sure you select the correct DataTable at the top of the macro.
How to run the Macro
Create your input DataTable within the Chemical Shift Mapping module as usual. Modify line 25 of the code to point to the DataTable that you have just created. Then run the macro either from the iPython Console or the Macro Editor.
You should now have a new DataTable which you can access in the sidebar. If you open this as a module you can right-click on the table to export it in .csv, .tsv or Excel format to use elsewhere.
Code
"""
This macro takes the input DataTable from the Chemical Shift Mapping analysis
which lists all the data per dimension and then creates a new DataTable which lists
the data per peak.
This is useful if you wish to export the data to another program.
You will need to make sure you select the correct DataTable at the top of the macro.
"""
#=========================================================================================
# Last code modification:
#=========================================================================================
_modifiedBy_ = "$modifiedBy: 2024-06-10 11:13:38 +0100 (Mon, June 10, 2024) $"
_dateModified_ = "$dateModified: Vicky Higman $"
_version_ = "$Revision: 3.2.4 $"
#=========================================================================================
# Created:
#=========================================================================================
_author_ = "$Author: 2024-06-10 11:13:38 +0100 (Mon, June 10, 2024) $"
_date_ = "$Date: Vicky Higman $"
#=========================================================================================
# Start of code
#=========================================================================================
import pandas as pd
perDimDT = get('DT:Titration_inputDataTable')
df = perDimDT.data
maxNumDims = int(df.loc[:,'dimension'].max())
for dim in range(1,maxNumDims+1):
if dim == 1:
dim1Data = df.loc[df['dimension'] == float(dim)]
newData = dim1Data.copy(deep=True)
newData.rename(columns={'isotopeCode': 'isotopeCodeDim1', 'ppmPosition': 'ppmPositionDim1'}, inplace=True)
else:
extraDimData = df.loc[df['dimension'] == float(dim)]
listtodrop = []
for col in extraDimData.columns.tolist():
if col not in ['isotopeCode', 'ppmPosition', 'peakPid']:
listtodrop.append(col)
extraDimData = extraDimData.drop(listtodrop, axis=1)
newDimData = extraDimData.copy(deep=True)
dimStr = 'Dim' + str(dim)
newICColumn = 'isotopeCode'+dimStr
newPosColumn = 'ppmPosition'+dimStr
newDimData.rename(columns={'isotopeCode': newICColumn, 'ppmPosition': newPosColumn}, inplace=True)
newData = pd.merge(newData, newDimData, on='peakPid', how='outer')
newColOrder = []
for col in newData.columns.tolist():
if dimStr not in col:
newColOrder.append(col)
dimStrMinus1 = 'Dim' + str(dim-1)
if 'isotopeCode' in col and dimStrMinus1 in col:
newColOrder.append(newICColumn)
elif 'ppmPosition' in col and dimStrMinus1 in col:
newColOrder.append(newPosColumn)
newData = newData.reindex(columns= newColOrder)
project.newDataTable(name=perDimDT.name+'_perPeak', data=newData)
Credits and References
Vicky Higman, CCPN Team, University of Leicester
