WGLab / LinkedSV

MIT License
20 stars 8 forks source link

Find executable from PATH env var #5

Closed bioinfornatics closed 5 years ago

bioinfornatics commented 5 years ago

Dear currently path to the executable is hardcoded which involve many problems outside your environment.

could you update your code with this a function like:

def get_absolute_path_from_path_env_var( executable_name ):
  index=0
  is_searching=True
  paths=os.getenv('PATH').split(':')
  result=None
  full_path_name=None
  while is_searching:
    if index >= len( paths ):
      is_searching=False
    else:
      full_path_name=os.path.join( paths[index], executable_name )
      if os.path.exists( full_path_name ):
        is_searching=False
        result=full_path_name
      else:
        index+=1
  if result is None:
    raise Exception( 'The executable named {} was not found in PATH'.format(executable_name) )
  return result

The patch file:

diff -up linkedsv/scripts/arguments.py.ori linkedsv/scripts/arguments.py
--- linkedsv/scripts/arguments.py.ori   2019-05-06 16:09:39.686042000 +0200
+++ linkedsv/scripts/arguments.py       2019-05-06 16:34:44.788665000 +0200
@@ -6,6 +6,26 @@ import os
 import sys
 import my_utils

+def get_absolute_path_from_path_env_var( executable_name ):
+  index=0
+  is_searching=True
+  paths=os.getenv('PATH').split(':')
+  result=None
+  full_path_name=None
+  while is_searching:
+    if index >= len( paths ):
+      is_searching=False
+    else:
+      full_path_name=os.path.join( paths[index], executable_name )
+      if os.path.exists( full_path_name ):
+        is_searching=False
+        result=full_path_name
+      else:
+        index+=1
+  if result is None:
+    raise Exception( 'The executable named {} was not found in PATH'.format(executable_name) )
+  return result
+
 class global_parameter:
     def __init__(self, parser_args):

@@ -57,18 +77,18 @@ class global_parameter:

         self.faidx_file = self.ref_fa + '.fai'

-        self.extract_barcode = os.path.join(self.root_dir, 'bin/extract_barcode_info')
-        self.remove_sparse_nodes = os.path.join(self.root_dir, 'bin/remove_sparse_nodes');
-        self.output_bam_coreinfo = os.path.join(self.root_dir, 'bin/output_bam_coreinfo');
-        self.cal_read_depth_from_bcd21 = os.path.join(self.root_dir, 'bin/cal_read_depth_from_bcd21');
-        self.cal_barcode_depth_from_bcd21 = os.path.join(self.root_dir, 'bin/cal_barcode_depth_from_bcd21');
-        self.cal_centroid_from_read_depth = os.path.join(self.root_dir, 'bin/cal_centroid_from_read_depth');
-        self.cal_twin_win_bcd_cnt = os.path.join(self.root_dir, 'bin/cal_twin_win_bcd_cnt');
-        self.grid_overlap = os.path.join(self.root_dir, 'bin/grid_overlap');
-        self.split_weird_reads_program = os.path.join(self.root_dir, 'scripts/split_weird_reads_file.py')
-        self.cal_expected_overlap_value = os.path.join(self.root_dir, 'scripts/cal_expected_overlap_value.py')
-        self.cal_2d_overlapping_barcodes = os.path.join(self.root_dir, 'bin/cal_2d_overlapping_barcodes')
-        self.pigz = os.path.join(self.root_dir, 'bin/pigz')
+        self.extract_barcode = get_absolute_path_from_path_env_var( 'extract_barcode_info')
+        self.remove_sparse_nodes = get_absolute_path_from_path_env_var( 'remove_sparse_nodes');
+        self.output_bam_coreinfo = get_absolute_path_from_path_env_var( 'output_bam_coreinfo');
+        self.cal_read_depth_from_bcd21 = get_absolute_path_from_path_env_var( 'cal_read_depth_from_bcd21');
+        self.cal_barcode_depth_from_bcd21 = get_absolute_path_from_path_env_var( 'cal_barcode_depth_from_bcd21');
+        self.cal_centroid_from_read_depth = get_absolute_path_from_path_env_var( 'cal_centroid_from_read_depth');
+        self.cal_twin_win_bcd_cnt = get_absolute_path_from_path_env_var( 'cal_twin_win_bcd_cnt');
+        self.grid_overlap = get_absolute_path_from_path_env_var( 'grid_overlap');
+        self.split_weird_reads_program = get_absolute_path_from_path_env_var( 'split_weird_reads_file.py')
+        self.cal_expected_overlap_value = get_absolute_path_from_path_env_var( 'cal_expected_overlap_value.py')
+        self.cal_2d_overlapping_barcodes = get_absolute_path_from_path_env_var( 'cal_2d_overlapping_barcodes')
+        self.pigz = get_absolute_path_from_path_env_var( 'pigz')

         self.alt_ctg_file  = os.path.join(self.root_dir, 'black_lists/alternative_contigs.txt')

thanks

bioinfornatics commented 5 years ago

any reason ?

fangli80 commented 5 years ago

What environment are you using? I have tested in CentOS 7 and LinkedSV can run without a problem. If I understand correctly, if I changed the code as you requested, users will need to add the LinkedSV/bin/ path to the PATH environmental variable. I don't know what the other users like, but I personally prefer a software tool that can run directly without changing the PATH environmental variable. There may be issues if the PATH environmental variable is not correctly set.

In addition, it's been too long time. If you still want LinkedSV work on your environment, please let me know what your environment is and we can see if there are any other options.

Best, Li