mailr25969 - in /branches/frame_order_cleanup: ./ auto_analyses/relax_disp_repeat_cpmg.py test_suite/system_tests/relax_disp.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on September 23, 2014 - 14:44:
Author: bugman
Date: Tue Sep 23 14:44:55 2014
New Revision: 25969

URL: http://svn.gna.org/viewcvs/relax?rev=25969&view=rev
Log:
Merged revisions 25967-25968 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk

........
  r25967 | bugman | 2014-09-23 13:59:05 +0200 (Tue, 23 Sep 2014) | 6 lines
  
  Dependency fix for the auto_analyses.relax_disp_repeat_cpmg module.
  
  This was causing relax to fail.  SciPy is an optional dependence for relax, 
but this module caused
  relax to not start if scipy was not installed.  This was detected by 
testing relax with PyPy.
........
  r25968 | tlinnet | 2014-09-23 14:41:49 +0200 (Tue, 23 Sep 2014) | 3 lines
  
  Implemented writing out of particular correlation plots to file.
  
  Task #7826 (https://gna.org/task/index.php?7826): Write an python class for 
the repeated analysis of dispersion data.
........

Modified:
    branches/frame_order_cleanup/   (props changed)
    branches/frame_order_cleanup/auto_analyses/relax_disp_repeat_cpmg.py
    branches/frame_order_cleanup/test_suite/system_tests/relax_disp.py

Propchange: branches/frame_order_cleanup/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Sep 23 14:44:55 2014
@@ -1 +1 @@
-/trunk:1-25965
+/trunk:1-25968

Modified: branches/frame_order_cleanup/auto_analyses/relax_disp_repeat_cpmg.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/auto_analyses/relax_disp_repeat_cpmg.py?rev=25969&r1=25968&r2=25969&view=diff
==============================================================================
--- branches/frame_order_cleanup/auto_analyses/relax_disp_repeat_cpmg.py      
  (original)
+++ branches/frame_order_cleanup/auto_analyses/relax_disp_repeat_cpmg.py      
  Tue Sep 23 14:44:55 2014
@@ -25,6 +25,9 @@
 U{task #7826<https://gna.org/task/index.php?78266>}, Write an python class 
for the repeated analysis of dispersion data.
 """
 
+# Dependencies.
+import dep_check
+
 # Python module imports.
 from copy import deepcopy
 from collections import OrderedDict
@@ -32,7 +35,8 @@
 from glob import glob
 from os import F_OK, access, getcwd, sep
 from numpy import asarray, arange, concatenate, max, mean, min, sqrt, std, 
sum
-from scipy.stats import pearsonr
+if dep_check.scipy_module:
+    from scipy.stats import pearsonr
 import sys
 from warnings import warn
 
@@ -1227,7 +1231,7 @@
         return res_dic
 
 
-    def plot_r2eff_corr(self, corr_data, show=False):
+    def plot_r2eff_corr(self, corr_data, show=False, write_stats=False):
 
         # Define figure.
         # Nr of columns is number of datasets.
@@ -1241,6 +1245,9 @@
 
         # axises is a tuple with number of elements corresponding to number 
of rows.
         # Each sub-tuple contains axis for each column.
+
+        # For writing out stats.
+        data_dic = OrderedDict()
 
         # Loop over the rows.
         for i, row_axises in enumerate(axises):
@@ -1254,16 +1261,20 @@
 
                 x = data_x[str(glob_ini_x)]['r2eff_arr']
                 x_err = data_x[str(glob_ini_x)]['r2eff_err_arr']
+                np = len(x)
 
                 y = data_y[str(glob_ini_y)]['r2eff_arr']
                 y_err = data_y[str(glob_ini_y)]['r2eff_err_arr']
 
                 # If row 1.
                 if i == 0:
+                    # Add to data dic.
+                    method_xy_NI = "r2eff_%s%s_%s%s" % (method_x, 
glob_ini_x, method_y, glob_ini_y)
+                    data_dic[method_xy_NI] = []
+
                     ax.plot(x, x, 'o', label='%s vs. %s' % (method_x, 
method_x))
                     ax.plot(x, y, '.', label='%s vs. %s' % (method_y, 
method_x) )
 
-                    np = len(y)
                     ax.set_title(r'$R_{2,\mathrm{eff}}$' + ' for %s %i vs. 
%s %i. np=%i' % (method_y, glob_ini_y, method_x, glob_ini_x, np), fontsize=10)
                     ax.legend(loc='upper left', shadow=True, prop = fontP)
                     ax.ticklabel_format(style='sci', axis='x', scilimits=(0, 
0))
@@ -1271,8 +1282,16 @@
                     ax.set_xlabel(r'$R_{2,\mathrm{eff}}$')
                     ax.set_ylabel(r'$R_{2,\mathrm{eff}}$')
 
+                    # Add to data.
+                    for k, x_k in enumerate(x):
+                        y_k = y[k]
+                        data_dic[method_xy_NI].append(["%3.5f"%x_k, 
"%3.5f"%y_k])
+
                 # R2eff to error.
                 if i == 1:
+                    # Add to data dic.
+                    method_xy_NI = "r2eff_to_err_%s%s_%s%s" % (method_x, 
glob_ini_x, method_y, glob_ini_y)
+                    data_dic[method_xy_NI] = []
 
                     x_to_x_err = x / x_err
                     y_to_y_err = y / y_err
@@ -1280,7 +1299,10 @@
                     # Calculate straight line.
                     # Linear a, with no intercept.
                     a = sum(x_to_x_err * y_to_y_err) / sum(x_to_x_err**2)
-                    x_to_x_err_arange = arange(min(x_to_x_err), 
max(x_to_x_err), (max(x_to_x_err) - min(x_to_x_err)) / 10)
+                    min_x = min(x_to_x_err)
+                    max_x =  max(x_to_x_err)
+                    step_x = (max_x - min_x) / np
+                    x_to_x_err_arange = arange(min_x, max_x, step_x)
                     y_to_x_err_arange = a * x_to_x_err_arange
 
                     ax.plot(x_to_x_err, x_to_x_err, 'o', label='%s vs. %s' % 
(method_x, method_x))
@@ -1288,13 +1310,108 @@
                     ax.plot(x_to_x_err, y_to_y_err, '.', label='%s vs. %s' % 
(method_y, method_x) )
                     ax.plot(x_to_x_err_arange, y_to_x_err_arange, 'g--')
 
-                    np = len(y_to_y_err)
                     
ax.set_title(r'$R_{2,\mathrm{eff}}/\sigma(R_{2,\mathrm{eff}})$' + ' for %s %i 
vs. %s %i. np=%i' % (method_y, glob_ini_y, method_x, glob_ini_x, np), 
fontsize=10)
                     ax.legend(loc='upper left', shadow=True, prop = fontP)
                     
ax.set_xlabel(r'$R_{2,\mathrm{eff}}/\sigma(R_{2,\mathrm{eff}})$')
                     
ax.set_ylabel(r'$R_{2,\mathrm{eff}}/\sigma(R_{2,\mathrm{eff}})$')
 
-            plt.tight_layout()
+                    # Add to data.
+                    for k, x_to_x_err_k in enumerate(x_to_x_err):
+                        y_to_y_err_k = y_to_y_err[k]
+                        x_to_x_err_arange_k = x_to_x_err_arange[k]
+                        y_to_x_err_arange_k = y_to_x_err_arange[k]
+                        data_dic[method_xy_NI].append(["%3.5f"%x_to_x_err_k, 
"%3.5f"%y_to_y_err_k, "%3.5f"%x_to_x_err_arange_k, 
"%3.5f"%y_to_x_err_arange_k])
+
+
+        plt.tight_layout()
+
+        # Loop over columns for writing data.
+        # Write to file.
+        if write_stats:
+            # Re-order the data.
+            headings_all = []
+            method_xy_NI_all = []
+            # Loop over the columns.
+            for j in range(nr_cols):
+                headings_j = []
+                method_xy_NI_j = []
+                # Loop over rows
+                for i in range(nr_rows):
+                    # Extract from lists.
+                    data, methods, glob_inis = corr_data[j]
+                    method_x, method_y = methods
+                    glob_ini_x, glob_ini_y = glob_inis
+
+                    # If row 1.
+                    if i == 0:
+                        # Add to headings.
+                        method_x_NI = "r2eff_%s%s" % (method_x, glob_ini_x)
+                        method_y_NI = "r2eff_%s%s" % (method_y, glob_ini_y)
+                        headings_j = headings_j + [method_x_NI, method_y_NI]
+
+                        method_xy_NI = "r2eff_%s%s_%s%s" % (method_x, 
glob_ini_x, method_y, glob_ini_y)
+                        method_xy_NI_j.append(method_xy_NI)
+
+                    # R2eff to error.
+                    if i == 1:
+                        # Add to headings
+                        method_x_NI = "r2eff_to_err_%s%s" % (method_x, 
glob_ini_x)
+                        method_y_NI = "r2eff_to_err_%s%s" % (method_y, 
glob_ini_y)
+                        method_x_NI_lin = "r2eff_to_err_lin_%s%s" % 
(method_x, glob_ini_x)
+                        method_y_NI_lin = "r2eff_to_err_lin_%s%s" % 
(method_y, glob_ini_y)
+                        headings_j = headings_j + [method_x_NI, method_y_NI, 
method_x_NI_lin, method_y_NI_lin]
+
+                        method_xy_NI = "r2eff_to_err_%s%s_%s%s" % (method_x, 
glob_ini_x, method_y, glob_ini_y)
+                        method_xy_NI_j.append(method_xy_NI)
+
+                headings_all.append(headings_j)
+                method_xy_NI_all.append(method_xy_NI_j)
+
+            # Loop over the columns.
+            for j, headings_j in enumerate(headings_all):
+                method_xy_NI_j = method_xy_NI_all[j]
+
+                data_w = []
+                data_r2eff = data_dic[method_xy_NI_j[0]]
+                data_r2eff_to_err = data_dic[method_xy_NI_j[1]]
+
+                for k, data_r2eff_k in enumerate(data_r2eff):
+                    data_r2eff_to_err_k = data_r2eff_to_err[k]
+                    data_w.append(data_r2eff_k + data_r2eff_to_err_k)
+
+                # Define file name.
+                data, methods, glob_inis = corr_data[j]
+                data_x, data_y = data
+                method_x, method_y = methods
+                glob_ini_x, glob_ini_y = glob_inis
+                np = len(data_r2eff)
+
+                # Get the spin selection for correlation.
+                selection = data_x['selection']
+
+                file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, 
glob_ini_x, method_y, glob_ini_y, np)
+                if selection == None:
+                    file_name_ini = file_name_ini + '_all'
+                else:
+                    file_name_ini = file_name_ini + '_sel'
+
+                file_name = file_name_ini + '.txt'
+                path = self.results_dir
+
+                # save figure
+                # Write png.
+                png_file_name = file_name_ini + '.png'
+                png_file_path = get_file_path(file_name=png_file_name, 
dir=path)
+                plt.savefig(png_file_path, bbox_inches='tight')
+
+                # Write file
+                file_obj, file_path = open_write_file(file_name=file_name, 
dir=path, force=True, compress_type=0, verbosity=1, return_path=True)
+
+                # Write data.
+                write_data(out=file_obj, headings=headings_j, data=data_w)
+
+                # Close file.
+                file_obj.close()
 
         if show:
             plt.show()

Modified: branches/frame_order_cleanup/test_suite/system_tests/relax_disp.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/test_suite/system_tests/relax_disp.py?rev=25969&r1=25968&r2=25969&view=diff
==============================================================================
--- branches/frame_order_cleanup/test_suite/system_tests/relax_disp.py  
(original)
+++ branches/frame_order_cleanup/test_suite/system_tests/relax_disp.py  Tue 
Sep 23 14:44:55 2014
@@ -6047,6 +6047,47 @@
             RDR.plot_r2eff_corr(corr_data=corr_data, show=True)
 
 
+        # Try write some R2eff correlations.
+        if True:
+            selection = None
+            # Collect r2eff values.
+            r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128], 
selection=selection)
+
+            # For all spins, mdd
+            r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 
126], selection=selection)
+
+            # Plot correlation of intensity
+            fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]]
+            fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]]
+            corr_data = [fig1, fig2]
+
+            write_stats = True
+            RDR.plot_r2eff_corr(corr_data=corr_data, show=True, 
write_stats=write_stats)
+
+            # Open stat file.
+            if write_stats:
+                for i, corr_data_i in enumerate(corr_data):
+                    data, methods, glob_inis = corr_data[i]
+                    data_x, data_y = data
+                    method_x, method_y = methods
+                    glob_ini_x, glob_ini_y = glob_inis
+                    x = data_x[str(glob_ini_x)]['r2eff_arr']
+                    np = len(x)
+
+                    file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % 
(method_x, glob_ini_x, method_y, glob_ini_y, np)
+
+                    if selection == None:
+                        file_name = file_name_ini + '_all.txt'
+                    else:
+                        file_name = file_name_ini + '_sel.txt'
+                    path = RDR.results_dir
+                    data = extract_data(file=file_name, dir=path)
+
+                    # Loop over the lines.
+                    for i, data_i in enumerate(data):
+                        print(i, data_i)
+
+
         # Try plot some R2eff statistics.
         if False:
             # Collect r2eff values.




Related Messages


Powered by MHonArc, Updated Tue Sep 23 17:20:02 2014