@@ -112,12 +112,12 @@ def motif2factor_from_orthologs(
112112
113113 # run orthofinder on our primary genes
114114 logger .info ("Running orthofinder to find orthologs." )
115- orthofinder_result = _orthofinder (f"{ tmpdir } /prim_genes" , threads )
115+ orthofinder_results_dir = _orthofinder (f"{ tmpdir } /prim_genes" , threads )
116116
117117 # now parse the output of orthofinder
118118 logger .info ("Storing everything in a database." )
119119 orthogroup_db = f"{ tmpdir } /orthologs.sqlite"
120- load_orthogroups_in_db (orthogroup_db , all_genomes , orthofinder_result )
120+ load_orthogroups_in_db (orthogroup_db , all_genomes , orthofinder_results_dir )
121121
122122 # get all motifs and related factors from motif database
123123 motifs = read_motifs (database )
@@ -173,10 +173,12 @@ def _orthofinder(peptide_folder, threads):
173173 logger .debug (f"""stdout of orthofinder:\n { result .stdout .decode ("utf-8" )} """ )
174174 logger .debug (f"""stderr of orthofinder:\n { result .stderr .decode ("utf-8" )} """ )
175175
176- orthofinder_result = re .search (
177- "Results:\n (.*)" , result .stdout .decode ("utf-8" )
176+ # [^/]+: match anything except forward slashes (including the present ANSI codes)
177+ # (.+)/: match anything until the last forward slash before a newline
178+ orthofinder_results_dir = re .search (
179+ "Results directory:[^/]+(.+)/" , result .stdout .decode ("utf-8" )
178180 ).group (1 )
179- return orthofinder_result
181+ return orthofinder_results_dir
180182
181183
182184def _prepare_genomes_with_annot (genome , genome_dir , outdir ):
@@ -354,7 +356,7 @@ def annot2primpep(genome, outdir):
354356 f .write ("\n " )
355357
356358
357- def load_orthogroups_in_db (db , genomes , orthofinder_result ):
359+ def load_orthogroups_in_db (db , genomes , orthofinder_results_dir ):
358360 """
359361 Save the results of orthofinder (tsv file) in a relational database
360362 (SQLite). This makes it possible to easily switch between genes and
@@ -363,15 +365,16 @@ def load_orthogroups_in_db(db, genomes, orthofinder_result):
363365 We create three tables; genes, orthogroups, and assemblies.
364366 """
365367 orthogroups = pd .read_table (
366- f"{ orthofinder_result } /Phylogenetic_Hierarchical_Orthogroups/N0 .tsv"
368+ f"{ orthofinder_results_dir } /Orthogroups/Orthogroups .tsv"
367369 )
368370 unassigned = pd .read_table (
369- f"{ orthofinder_result } /Orthogroups/Orthogroups_UnassignedGenes.tsv"
371+ f"{ orthofinder_results_dir } /Orthogroups/Orthogroups_UnassignedGenes.tsv"
370372 )
371373
372- # remove old db if it exists (TODO: shouldnt be necessary?)
374+ # remove old db if it exists
373375 if os .path .exists (db ):
374376 os .remove (db )
377+
375378 conn = sqlite3 .connect (db )
376379 conn .execute (
377380 """
@@ -412,7 +415,7 @@ def load_orthogroups_in_db(db, genomes, orthofinder_result):
412415
413416 # fill up our database
414417 # all orthogroups
415- for orthogroup in orthogroups ["HOG " ]: # <-- all Hierarchical OrthoGroups
418+ for orthogroup in orthogroups ["Orthogroup " ]: # <-- all Hierarchical OrthoGroups
416419 conn .execute (f"INSERT INTO orthogroups VALUES(NULL, '{ orthogroup } ')" )
417420 conn .execute ("INSERT INTO orthogroups VALUES(NULL, 'UNASSIGNED')" )
418421
@@ -423,7 +426,7 @@ def load_orthogroups_in_db(db, genomes, orthofinder_result):
423426 # all genes per species
424427 for assembly in genomes :
425428 for orthogroup , genes in zip (
426- orthogroups ["HOG " ], orthogroups [f"{ assembly } .pep" ]
429+ orthogroups ["Orthogroup " ], orthogroups [f"{ assembly } .pep" ]
427430 ):
428431 if isinstance (genes , float ) and np .isnan (genes ):
429432 continue
0 commit comments