Does nmrglue have a sparky peak list reader?

86 views
Skip to first unread message

Troels Emtekær Linnet

unread,
Apr 17, 2013, 3:53:27 PM4/17/13
to nmrglue...@googlegroups.com
Hi.

I am looking for a clever solution to read in a sparky peak list.

The problem is, that the header of the file can change.
Exist, not exist, and have an empty line space-between header and peak list.
Also the column order of HN, and N, can be different.

Analysis export: Resn - HN - N - no line skip between header and files. Have Height/Volumne column.
SPARKY export: Resn - N - HN - one line skip between header and files
Personal peak: Probably don't have header line.

------------------------------
Ex 1: Analysis export.
------------------------------
      Assignment         w1         w2       Height       Volume
              ?-?      9.061    132.333   1.14E+05   7.66E+05 bx
         V2HN-V2N      8.856    131.178   2.33E+03   9.26E+03 bx
         F3HN-F3N      8.856    131.178   2.33E+03   9.26E+03 bx
------------------------------
Ex 2: Sparky export
------------------------------
      Assignment         w1         w2

           G4N-HN    108.175      8.386
           E7N-HN    129.130      8.131
------------------------------

So, I am looking for a clever solution to solve this, since it would be nice to read in peak list, and auto-detect 
which order the data is sorted.

The reason is that I am looking into to try to use the auto-integrate function of nmrglue.
I have a folder with qMDD processed files, and make a settings file list.
-   path to ft.2               peak-list timeT2  NCYC  freq(NU)
../0plane.proc/test.ft2 peaks.list 0.06 28 466.667
../1plane.proc/test.ft2 peaks.list 0.06 0 0.000
../2plane.proc/test.ft2 peaks.list 0.06 4 66.667
../3plane.proc/test.ft2 peaks.list 0.06 32 533.333
--------

----------------------------
import nmrglue as ng
import matplotlib.pyplot as plt
import numpy as np

# Open settings
fl = np.recfromtxt("sparkylists.csv", names="ftfile, peakfile, timeT2, NI, nu")

## read in the data from a NMRPipe file
dics = []
datas = []
for line in fl[:1]:
    ftfile=line['ftfile']; peakfile=line['peakfile']; timeT2=line['timeT2']
    NI=line['NI']; ni=line['nu']
    dic, data = ng.pipe.read(ftfile)
    dics.append(dic); datas.append(data)
    frqX=dic['FDF2OBS']; frqY=dic['FDF1OBS']
    sizeX=dic['FDSIZE']; sizeY=dic['FDSPECNUM']
    origX=dic['FDF2ORIG']; origY=dic['FDF1ORIG']
    swX=dic['FDF2SW']; swY=dic['FDF1SW']
    #
    stepX=swX/frqX/sizeX;
    highX=(origX+swX)/frqX;
    stepY=swY/frqY/sizeY;
    highY=(origY+swY)/frqY;
    #
    pf = np.recfromtxt(peakfile,  names="resn, N, HN")
    for pfl in pf:
        print pfl
        #ptsX=(highX-$HN-proton)/stepX
        #ptsY=(highY-$N-nitrogen)/stepY
-----------------------------------------------
With the ptsX, and ptsY, I will subtract 1 in each direction (or similar)
and follow:

Like using SeriesTab:
  • seriesTab -in test.tab -out 12Out.out -list 12List -dx 6 -dy 6
  • This will tabulate the same peaks from both spectra side by side. -dx and -dy specify a box of 6 x 6 points that will be centered on each peak to tabulate the volume of the peak.


Best

Troels Emtekær Linnet
Ved kløvermarken 9, 1.th
2300 København S
Mobil:
+45 60210234

Jonathan Helmus

unread,
Apr 17, 2013, 4:29:27 PM4/17/13
to nmrglue...@googlegroups.com
Troels,

    nmrglue doesn't have a built in way to read sparky peak lists.  I usually use numpy.genfromtxt to read tabular text data such as sparky lists, etc.  The following works to read in the HSQC Sparky list at (1):

In [1]: import numpy as np
In [2]: peak_list = np.genfromtxt('Downloads/sparky_hsqc.txt', names=True, dtype=['S24', 'f', 'f'])
In [3]: peak_list[0]
Out[3]: ('?-?', 8.902000427246094, 132.86500549316406)
In [4]: peak_list[1]
Out[4]: ('A46H-A46N', 8.824000358581543, 132.86500549316406)

The documentation (2) on genfromtxt is very good and describes how to skip row, columns, etc.  If you expect your peak lists to have similar layout you can probably just figure out the genfromtxt parameters once and include them in the scripts. 

A more general sparky peak list reader could likely be created which examines the first few lines of a sparky text file and then calls numpy.genfromtxt with the appropriate parameters.  This is what nmrglue.pipe.read_table (3) does to read NMRPipe .tab files.  I'd be happy to include such a reader in nmrglue if anyone happens to implement one.

(1) http://pine.nmrfam.wisc.edu/sparky_hsqc.txt
(2) http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html
(3) https://github.com/jjhelmus/nmrglue/blob/master/nmrglue/fileio/pipe.py#L24

Cheers,

    - Jonathan Helmus
--
You received this message because you are subscribed to the Google Groups "nmrglue-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nmrglue-discu...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages