diff --git a/src/outils.py b/src/outils.py index 4021381674f0ad62b6b92ffbc8d857846d617fc7..f8d60deabc399b1b8b61916f4650d3f9a91711d8 100644 --- a/src/outils.py +++ b/src/outils.py @@ -891,4 +891,11 @@ def get_R_libraries(script): libraries = [] for match in re.finditer(r"library\s*\(\s*(\w+)\s*\)", script): libraries.append(match.group(1)) - return libraries \ No newline at end of file + return libraries + +#Function that parses perl script and extracts the modules which are imported +def get_perl_modules(script): + libraries = [] + for match in re.finditer(r"(package|use)\s+([^\s;]+)\s*;", script): + libraries.append(match.group(2)) + return libraries diff --git a/src/process.py b/src/process.py index c825e4ce2a11d98745fb8de2b9b2243122dda251..76f5993ff4a34ccf5bf191c1439cc46cf0191137 100644 --- a/src/process.py +++ b/src/process.py @@ -3,7 +3,7 @@ import glob from .code_ import Code from .nextflow_building_blocks import Nextflow_Building_Blocks -from .outils import remove_jumps_inbetween_parentheses, remove_jumps_inbetween_curlies, sort_and_filter, get_dico_from_tab_from_id, check_if_element_in_tab_rocrate, get_python_packages, get_R_libraries +from .outils import remove_jumps_inbetween_parentheses, remove_jumps_inbetween_curlies, sort_and_filter, get_dico_from_tab_from_id, check_if_element_in_tab_rocrate, get_python_packages, get_R_libraries, get_perl_modules from .bioflowinsighterror import BioFlowInsightError from . import constant @@ -118,16 +118,30 @@ class Process(Nextflow_Building_Blocks): libraries+= get_R_libraries(s) return libraries - #This methods checks the script and the external script calls for python packages imports + #This methods checks the script and the external script calls for R libraries loaded def get_R_libraries_loaded(self): libraries = [] libraries+= self.get_R_libraries_loaded_internal_script() libraries+= self.get_R_libraries_loaded_external_scripts() return list(set(libraries)) + - #TODO -> do the same with Ruby/PErl scripts - + def get_perl_modules_imported_internal_script(self): + libraries = [] + libraries+= get_perl_modules(self.get_script_code()) + return libraries + + def get_perl_modules_imported_external_scripts(self): + libraries = [] + for s in self.get_external_scripts_code(): + libraries+= get_perl_modules(s) + return libraries + def get_perl_modules_imported(self): + libraries = [] + libraries+= self.get_perl_modules_imported_internal_script() + libraries+= self.get_perl_modules_imported_external_scripts() + return list(set(libraries)) #def get_source(self):