From 1471cfc7569e31361530bfd56de7393da73de28e Mon Sep 17 00:00:00 2001
From: remy <remy.dernat@umontpellier.fr>
Date: Sun, 24 Nov 2019 18:41:52 +0100
Subject: [PATCH] not the right way to do fix this

---
 orthofinder/scripts/blast_file_processor.py |  5 +++--
 orthofinder/scripts/scnorm.py               | 25 +++++++++++----------
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/orthofinder/scripts/blast_file_processor.py b/orthofinder/scripts/blast_file_processor.py
index be32ead..a22ad19 100644
--- a/orthofinder/scripts/blast_file_processor.py
+++ b/orthofinder/scripts/blast_file_processor.py
@@ -34,6 +34,7 @@ from . import util
 from . import matrices
 from tempfile import NamedTemporaryFile
 from shutil import move
+from . import scnorm as sc
 
 PY2 = sys.version_info <= (3,)       
 file_read_mode = 'rb' if PY2 else 'rt'
@@ -140,8 +141,8 @@ def WriteNormalizedBlastFile(blastDir_list, B, iSpecies, jSpecies, sep = "_", qD
                     raise
                 try:
                     newscore = B[sequence1ID, sequence2ID]
-                    #if newscore == "0.0":
-                    #    FixZeroNormScore(int(row[12]))
+                    #if newscore == 0.0:
+                    #    newscore = sc.scnorm.FixZeroNormalizedScores(iSpeciesOpen, float(row[11]))
                     row.append(newscore)
                 except IndexError as e:
                     sys.stderr.write("\nERROR: Matrix index on Blast species %d %d, sequences B[%d, %d] : %s \n" % (iSpeciesOpen, jSpeciesOpen, sequence1ID, sequence2ID, e))
diff --git a/orthofinder/scripts/scnorm.py b/orthofinder/scripts/scnorm.py
index d28a4ef..1f60037 100644
--- a/orthofinder/scripts/scnorm.py
+++ b/orthofinder/scripts/scnorm.py
@@ -34,6 +34,7 @@ import matplotlib.pyplot as plt                 # install
 
 
 counter=0
+curvefitplt=[]
 
 """
 scnorm
@@ -85,7 +86,7 @@ class scnorm:
         # curve_fit doc.: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html
         Slog = np.log10(S)
         pars, covar =  curve_fit(scnorm.loglinear, Lf, Slog)
-        scnorm.DrawLogLinear(pars, Lf, Slog)
+        scnorm.DrawLogLinear(pars, Lf)
         return pars
 
     @staticmethod
@@ -101,24 +102,24 @@ class scnorm:
         return sparse.lil_matrix(10**(-params[1]) * li_matrix * b * lj_matrix)
 
     @staticmethod
-    def DrawLogLinear(params, x, y):
+    def DrawLogLinear(params, x):
+        global counter
+        global curvefitplt
         nbvals=5000
         maxBS=2500
         minBS=0
         x = np.linspace(minBS, maxBS, nbvals)
-        plt.plot(x, scnorm.loglinear(x, *params), label='species '+str(counter))
+        plot = plt.plot(x, scnorm.loglinear(x, *params), label='species '+str(counter))
+        curvefitplt.append(plot)
         plt.legend()
-        plt.xlabel('Normalized Scores')
-        plt.ylabel('Bits Scores')
-        plt.title("Normalisation fitting curve for species")
+        plt.xlabel('Bits Scores')
+        plt.ylabel('Normalized Scores')
+        plt.title("Normalization fitting curve for species")
         plt.grid(True)
-        #plt.savefig('foo'+str(counter)+'.png')
         plt.savefig('fitting_curve.png')
-        global counter
         counter+=1
 
     @staticmethod
-    def FixZerosNormalizedBS(x):
-        Xlog=log10(x)
-        return Xlog
-        #return NBS
+    def FixZeroNormalizedScores(species, x):
+        NormBS = curvefitplt[species][int(x)].get_data()
+        return NormBS
-- 
GitLab