CcpnForum
Copy Assignments macro - Printable Version

+- CcpnForum (https://www.ccpn.ac.uk/forums)
+-- Forum: CcpNmr Analysis Version 3 (https://www.ccpn.ac.uk/forums/forumdisplay.php?fid=4)
+--- Forum: V3 Macros (https://www.ccpn.ac.uk/forums/forumdisplay.php?fid=14)
+--- Thread: Copy Assignments macro (/showthread.php?tid=70)



Copy Assignments macro - VickyH - 01-29-2020

Here is a macro to copy assignments from one peak to one or more others. This would be useful if you have two spectra recorded under different conditions where some or all of the peaks have moved (e.g with/without ligand, different temperature, buffer etc.) and want to copy the assignments from one spectrum to another.

Select one (fully or partially) assigned peak and one or more unassigned peaks. The assignments from the assigned peak will be copied to the unassigned peaks. This will work both within and between peak lists, spectra and spectrum displays.

The macro works in a similar way to the V2 "Propagate Assignment" function. However, note that the peak dimensions are matched by their Axis Codes and there is no checking of chemical shifts. This is deliberate, so that you can copy assignments in situations where the chemical shift has changed. It will only work for peaks belonging to spectra with the same number/type of axes (e.g. HN and HN, HNC and HNC etc.). Also, your dimensions will be swapped if you apply it to two peaks on opposite sides of the diagonal of a homonuclear spectrum.

Python
  1. # Macro to copy the peak assignments from one peak to another
  2.  
  3. from ccpn.core.lib.ContextManagers import undoBlock
  4.  
  5. with undoBlock():
  6. assignmentsToCopy = None
  7. # Check only one peak is fully or partially assigned and get the assignments to copy
  8. for peak in current.peaks:
  9. if len(peak.assignments) != 0 and assignmentsToCopy is None:
  10. assignmentsToCopy = peak.assignmentsByDimensions
  11. elif len(peak.assignments) != 0 and assignmentsToCopy is not None:
  12. print("You have more than one assigned peak.")
  13. assignmentsToCopy = None
  14.  
  15. if assignmentsToCopy is not None:
  16. for peak in current.peaks:
  17. if len(peak.assignments) == 0: # only copy assignments to unassigned peaks
  18. peak.dimensionNmrAtoms = assignmentsToCopy
  19. else:
  20. print("Please make sure you have one assigned peak.")



Any problems, let me know.

Vicky


RE: Copy Assignments macro - Carolina - 10-23-2020

(01-29-2020, 02:02 PM)VickyH Wrote: Here is a macro to copy assignments from one peak to one or more others. This would be useful if you have two spectra recorded under different conditions where some or all of the peaks have moved (e.g with/without ligand, different temperature, buffer etc.) and want to copy the assignments from one spectrum to another.

Select one (fully or partially) assigned peak and one or more unassigned peaks. The assignments from the assigned peak will be copied to the unassigned peaks. This will work both within and between peak lists, spectra and spectrum displays.

The macro works in a similar way to the V2 "Propagate Assignment" function. However, note that the peak dimensions are matched by their Axis Codes and there is no checking of chemical shifts. This is deliberate, so that you can copy assignments in situations where the chemical shift has changed. But this does mean that you might encounter unexpected behaviour for spectra with at least two dimensions belonging to the same isotope (e.g. when copying assignments across the diagonal of a homonuclear spectrum), or for two spectra where the peaks' Axis Codes and Assignments don't line up. But this should hopefully only be a minority of cases.

Python
  1. def copyAssignment(peak, assignmentsToCopy, axisCodesToUse):
  2.    assignDone = 0
  3.    count = 0
  4.    for assignment in assignmentsToCopy:
  5.        temp = str(assignment)
  6.        assignmentLabels = temp.split(',')
  7.        assignmentLabels[0] = assignmentLabels[0][1:]
  8.        assignmentLabels[-1] = assignmentLabels[-1][0:-1]
  9.        axCodes = dict(zip(assignmentLabels, axisCodesToUse))
  10.        for label in assignmentLabels:
  11.            count = count+1
  12.            if 'None' not in label:
  13.                temp = str(label)
  14.                assignmentComponents = temp.split(':')
  15.                assignmentComponents[0] = 'NA'
  16.                assignmentComponents[1] = assignmentComponents[1][0:-1]
  17.                axCde = axCodes[label]
  18.                newAssignment = ':'.join(assignmentComponents)
  19.                if axCde in peak.axisCodes:
  20.                    peak.assignDimension(axCde, newAssignment)
  21.                    assignDone = 1
  22.    if assignDone == 0:
  23.        print('Your peaks have to have matching Axis Codes in at least one assigned dimension in order to copy an assignment.')
  24.  
  25.  
  26. assignmentsToCopy = None
  27. axisCodesToUse = None
  28. # Check only one peak is fully or partially assigned and get the assignments and Axis Codes to copy
  29. for peak in current.peaks:
  30.    if len(peak.assignments) != 0 and assignmentsToCopy is None:
  31.        assignmentsToCopy = peak.assignments
  32.        axisCodesToUse = peak.axisCodes
  33.    elif len(peak.assignments) != 0 and assignmentsToCopy is not None:
  34.        print("You have more than one assigned peak.")
  35.        assignmentsToCopy = None
  36.  
  37.  
  38. if assignmentsToCopy is not None:
  39.    for peak in current.peaks:
  40.        if len(peak.assignments) == 0:  # only copy assignments to unassigned peaks
  41.            copyAssignment(peak, assignmentsToCopy, axisCodesToUse)
  42. else:
  43.    print("Please make sure you have one assigned peak.")



Any problems, let me know.

Vicky

Hi Vicky,

I am trying to run this macro, but it doesn't seem to work for me. I select the two peaks in the two spectra, one assigned, another unassigned and then run the macro and nothing happened. I am new to macros, so I don't know if I am making any mistake. I would appreciate any help.
Thanks! Carolina


RE: Copy Assignments macro - VickyH - 11-04-2020

Hi Carolina,

sorry to be slow to get back to you on this one. See above for an improved version of the macro (which you can also Undo after running). Note that it will only work if your two peaks are from spectra with the same number/type of axes. If you still have a problem, let me know. Perhaps also mention what you are trying to copy to what.

Thanks,

Vicky


RE: Copy Assignments macro - gina wimberly-gard - 12-10-2020

Hi Vicky I am new to NMR so I am not sure what the exact process is for running this script and having it carry assignments/spectra peaks forward. I am using CCPM NMR3 to work with Protein against which I titrate in a ligand. So I have about 10 sets of spectra and there are accordingly peak shifts. This is a 2D spectra so there are no assignments other than maybe saying something is backbone amides. I understand that in CCPNMR 2 there is a process for assigning the peaks to the next series of spectra data so one can plot changes in peak shift as the ligand is added in each data collection run, for the purpose of kD calculations etc.


RE: Copy Assignments macro - LucaM - 12-10-2020

Hi Gina, have a look at the ChemicalShift Mapping tutorials. You will find instructions how to do most of the operations you will need for a titration analysis. Assuming you have the assignments, otherwise you might have a look at the Bmrb database.


RE: Copy Assignments macro - VickyH - 12-11-2020

Hi Gina,

you can access the Chemical Shift Mapping tutorial either in the Help Menu in the programme: Help / Tutorials / Chemical Shift Perturbation Tutorial or from the website: https://www.ccpn.ac.uk/v3-software/tutorials/chemical-shift-perturbation-analysis-tutorial/view
This will take you through how to set up a titration series and analyse the data. The macro above is just an alternative way to transfer the assignments from one peak to another, if (like me) you are not so keen to do it with the system outlined in the tutorial.
It is worth pointing out, though, that V2 does have a "Follow Shift Changes" routine which we don't yet have in V3. So transferring the assignments from one spectrum to another is slightly less automated in V3 compared to V2 at the moment.

Best wishes,

Vicky


RE: Copy Assignments macro - GMWG - 03-09-2021

(12-11-2020, 02:25 PM)VickyH Wrote: Hi Gina,

you can access the Chemical Shift Mapping tutorial either in the Help Menu in the programme: Help / Tutorials / Chemical Shift Perturbation Tutorial or from the website: https://www.ccpn.ac.uk/v3-software/tutorials/chemical-shift-perturbation-analysis-tutorial/view
This will take you through how to set up a titration series and analyse the data. The macro above is just an alternative way to transfer the assignments from one peak to another, if (like me) you are not so keen to do it with the system outlined in the tutorial.
It is worth pointing out, though, that V2 does have a "Follow Shift Changes" routine which we don't yet have in V3. So transferring the assignments from one spectrum to another is slightly less automated in V3 compared to V2 at the moment.

Best wishes,

Vicky
Hi Vicky (I am actually the person who asked this question , above,  but was unable to re-access the account so started under a new user name :)). I see the tutorial. Apologies, I don't understand why I want to drop my original Apo peak list onto the final "eqb" spectrum  when I want to follow the shift change and read out the peak list of the shift changes correlated with each other? Wouldn't that delete my peak list for my original apo data? Just wondering "Will Follow Shift Change" be implemented at all? I don't have a BMRB assignment for this particular data (hoping to collect a C13N15). This is an HSQC experiment only looking at titrations.  I want to calculate Kds from the peak shifts etc at different concentrations fro different peaks.


RE: Copy Assignments macro - VickyH - 03-10-2021

Hi Gina,

when you drop a peak lists onto another spectrum you simply invoke the "Copy Peak List" function. So you are not moving it from one spectrum to another, but copying it - you will retain your apo peak list if you drop it on another spectrum. But by copying it to another spectrum you will have it as a starting point in the other spectrum.

Yes, all you need is a series of peak lists (one for each spectrum) and the peaks need to be correlated.
We correlate the peaks by giving them the same assignment (technically the same NmrAtoms). If you don't yet have your assignments, then you can use place holders. So in your case I would take the first spectrum and run Assignment / Set up NmrResidues (SN for short). This will create random NmrResidues and NmrAtoms for you for each NH peak.
You are then left with having to peak pick the other spectra and assign the peaks (either using the real assignments if you have those, or the randomly generated NmrAtoms). It is really simply a matter of preference whether you prefer to copy the peak list from one spectrum to another and then move the peaks to their true positions (the system described in the tutorial), or whether you prefer to peak pick each spectrum and then copy over the assignments (the system enabled by the macro here).

Yes, we will certainly be implementing the "Follow Shift Changes" function from V2 at some point, though there are other things higher up on the priority list at the moment, so it will be a little while yet, I would have thought.

Best wishes,

Vicky


RE: Copy Assignments macro - GMWG - 03-10-2021

(03-10-2021, 02:27 PM)VickyH Wrote: Hi Gina,

when you drop a peak lists onto another spectrum you simply invoke the "Copy Peak List" function. So you are not moving it from one spectrum to another, but copying it - you will retain your apo peak list if you drop it on another spectrum. But by copying it to another spectrum you will have it as a starting point in the other spectrum.

Yes, all you need is a series of peak lists (one for each spectrum) and the peaks need to be correlated.
We correlate the peaks by giving them the same assignment (technically the same NmrAtoms). If you don't yet have your assignments, then you can use place holders. So in your case I would take the first spectrum and run Assignment / Set up NmrResidues (SN for short). This will create random NmrResidues and NmrAtoms for you for each NH peak.
You are then left with having to peak pick the other spectra and assign the peaks (either using the real assignments if you have those, or the randomly generated NmrAtoms). It is really simply a matter of preference whether you prefer to copy the peak list from one spectrum to another and then move the peaks to their true positions (the system described in the tutorial), or whether you prefer to peak pick each spectrum and then copy over the assignments (the system enabled by the macro here).

Yes, we will certainly be implementing the "Follow Shift Changes" function from V2 at some point, though there are other things higher up on the priority list at the moment, so it will be a little while yet, I would have thought.

Best wishes,

Vicky

---------------------------------

Hi Vicky OK thanks for the explanation I will try that. G