jjhelmus / nmrglue

A module for working with NMR data in Python
BSD 3-Clause "New" or "Revised" License
209 stars 86 forks source link

Reading Sparky .save files #118

Closed kaustubhmote closed 4 years ago

kaustubhmote commented 4 years ago

This PR adds to nmrglue the ability to read in .save files from Sparky. This reads in all annotations, annotation locations, labels, peak integrals, peak heights, and everything else associated with analysing data in Sparky. This is accessible by a single function ng.sparky.read_savefile(savefile, spectrum_file), which uses a custom parser (ng.sparky.SparkySaveParser) to parse the .save file.

Apart from giving access to all the peak analysis done in Sparky, a particularly nice use for this would be to automatically make "publication-ready" figures with peak annotations in matplotlib. A script to do so is included at examples/plotting/plot_sparky_savefile/plot_sparky.py, and it directly gives figures that (can) look like this:

bmrb_6209

Plus, this way you have the whole power of matplotlib to make additional subplots, annotations etc! This PR does not change any of the current behaviour of nmrglue.

kfritzsc commented 4 years ago

This is excellent @kaustubhmote!

I have wanted to do this for CCPN2 files for a while, but have not found the time.

In the future it might be helpful to come back and abstract out some of these ideas: for example both the Sparky and CCPN modules could share a common PeakAnnotation object.

kaustubhmote commented 4 years ago

That sounds great! Right now I am just looping over the dictionary to put in the annotations, but a PeakAnnotation object that's able to read in this dictionary or anything else from CCPN, pipe or any other format would be really useful. Then you can control peak size, label format and so many other things.

A thought along this line: more often than not, I seem to be using nmrglue for getting data to matplotlib for making the final figure (rather than actual processing, mostly because linear prediction is an issue). If that is a common use case, perhaps matplotlib can be added as a dependency and such plots can be made easy (without the boilerplate)...

jjhelmus commented 4 years ago

This looks great, merging.

@kaustubhmote You have made a number of contribution to nmrglue, would you be interested in being added as a owner to this repository so that you can help review and merge pull-requests?

kaustubhmote commented 4 years ago

@jjhelmus For sure! This is a library that I use practically everyday, so I would love to see it grow, and I will be glad to help in any way I can.

jjhelmus commented 4 years ago

@kaustubhmote I've added you as a collaborator to nmrglue. You should be able to review and merge PRs now.