From 5862116debc830a1e724effe7ea43272055f63d2 Mon Sep 17 00:00:00 2001
From: remy <remy.dernat@umontpellier.fr>
Date: Mon, 11 Nov 2019 21:38:49 +0100
Subject: [PATCH] bugs fixed

---
 orthofinder/orthofinder.py                  |  2 +-
 orthofinder/scripts/blast_file_processor.py | 29 +++++++++++----------
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/orthofinder/orthofinder.py b/orthofinder/orthofinder.py
index 91cd61f..2694d6f 100755
--- a/orthofinder/orthofinder.py
+++ b/orthofinder/orthofinder.py
@@ -1402,7 +1402,7 @@ def DoNormalize(options, speciesInfoObj, seqsInfo):
     for iSpecies in range(seqsInfo.nSpecies):
         cmd_queue.put((seqsInfo, blastDir_list, Lengths, iSpecies))
     # Normalization is done here
-    runningProcesses = [mp.Process(target=WaterfallMethod.Worker_ProcessBlastHits, args=(cmd_queue, options.qDoubleBlast, options.qNormalize=True)) for i_ in range(options.nProcessAlg)]
+    runningProcesses = [mp.Process(target=WaterfallMethod.Worker_ProcessBlastHits, args=(cmd_queue, options.qDoubleBlast, options.qNormalize)) for i_ in range(options.nProcessAlg)]
     for proc in runningProcesses:
         proc.start()
     parallel_task_manager.ManageQueue(runningProcesses, cmd_queue)
diff --git a/orthofinder/scripts/blast_file_processor.py b/orthofinder/scripts/blast_file_processor.py
index d928bd8..af0b6aa 100644
--- a/orthofinder/scripts/blast_file_processor.py
+++ b/orthofinder/scripts/blast_file_processor.py
@@ -103,9 +103,8 @@ def GetBLAST6Scores(seqsInfo, blastDir_list, iSpecies, jSpecies, qExcludeSelfHit
         raise 
     return B
 
-def WriteNormalizedBlastFile(blastDir_list, B, iSpecies, jSpecies, qExcludeSelfHits = True, sep = "_", qDoubleBlast=True):
+def WriteNormalizedBlastFile(blastDir_list, B, iSpecies, jSpecies, sep = "_", qDoubleBlast=True):
     qSameSpecies = iSpecies==jSpecies
-    qCheckForSelfHits = qExcludeSelfHits and qSameSpecies
     if not qDoubleBlast:
         qRev = (iSpecies > jSpecies)
     else:
@@ -120,15 +119,15 @@ def WriteNormalizedBlastFile(blastDir_list, B, iSpecies, jSpecies, qExcludeSelfH
         iH = 1
         iSpeciesOpen = iSpecies
         jSpeciesOpen = jSpecies
-
     tempfile = NamedTemporaryFile(mode='w', delete=False)
     #xSeqID, ySeqID, NormVal = ParseMatrix(B)
+    row = ""
     for d in blastDir_list:
         fn = d + "Blast%d_%d.txt" % (iSpeciesOpen, jSpeciesOpen)
         fnNorm = d + "Blast%d_%d.norm.blastout" % (iSpeciesOpen, jSpeciesOpen)
         if os.path.exists(fn) or os.path.exists(fn + ".gz"): break
     try:
-        with (gzip.open(fn + ".gz", file_reader_mode) if os.path.exists(fn + ".gz") else open(fn, file_reader_mode)) as blastfile:
+        with (gzip.open(fn + ".gz", file_read_mode) if os.path.exists(fn + ".gz") else open(fn, file_read_mode)) as blastfile:
             blastreader = csv.reader(blastfile, delimiter='\t')
             blastwriter = csv.writer(tempfile, delimiter='\t')
             for row in blastreader:
@@ -139,14 +138,16 @@ def WriteNormalizedBlastFile(blastDir_list, B, iSpecies, jSpecies, qExcludeSelfH
                 except (IndexError, ValueError):
                     sys.stderr.write("\nERROR: Query or hit sequence ID in BLAST results file was missing or incorrectly formatted.\n")
                     raise
-                try:
-                    score = float(row[11])
-                except (IndexError, ValueError):
-                    sys.stderr.write("\nERROR: 12th field in BLAST results file line should be the bit-score for the hit\n")
-                    raise
+                #try:
+                #    score = float(row[11])
+                #except (IndexError, ValueError):
+                #    sys.stderr.write("\nERROR: 12th field in BLAST results file line should be the bit-score for the hit\n")
+                #    raise
                 newscore = B[sequence1ID, sequence2ID]
-                newrow = row
-                newrow[11] = newscore
-                writer.writerow(row)
-
-            shutil.move(tempfile.name, fnNorm)
\ No newline at end of file
+                row.append(newscore)
+                blastwriter.writerow(row)
+            move(tempfile.name, fnNorm)
+    except Exception:
+        sys.stderr.write("Malformatted line in %sBlast%d_%d.txt\nOffending line was:\n" % (d, iSpecies, jSpecies))
+        sys.stderr.write("\t".join(map(str, row)) + "\n")
+        raise 
-- 
GitLab