comparison data_manager/plasmidfinder_fetch_database.py @ 1:9ef108e34063 draft

planemo upload commit 32f035f6404452fc8a1cf01d71be3c0b46548338
author pimarin
date Wed, 15 Feb 2023 10:35:15 +0000
parents 8ad77a9dc91d
children bd56ac4cca16
comparison
equal deleted inserted replaced
0:8ad77a9dc91d 1:9ef108e34063
141 os.makedirs(output_tar_path) 141 os.makedirs(output_tar_path)
142 os.makedirs(output_path) 142 os.makedirs(output_path)
143 with open(output_tar_path_file, 'wb') as output_dir: 143 with open(output_tar_path_file, 'wb') as output_dir:
144 output_dir.write(request_info.content) 144 output_dir.write(request_info.content)
145 untar_output = self.untar_files(file_path=output_tar_path_file, extracted_path_output=output_tar_path.joinpath(self._db_name)) 145 untar_output = self.untar_files(file_path=output_tar_path_file, extracted_path_output=output_tar_path.joinpath(self._db_name))
146 146 self.moove_download_files(source=untar_output, destination=output_path)
147 self.moove_download_files(older_path=untar_output, new_path=output_path)
148 except requests.exceptions.HTTPError as http_error: 147 except requests.exceptions.HTTPError as http_error:
149 print(f"Requests Error: {http_error}") 148 print(f"Requests Error: {http_error}")
150 print(f"Fail to import Plasmidfinder database from {self._plasmidfinder_url}") 149 print(f"Fail to import Plasmidfinder database from {self._plasmidfinder_url}")
151 150
152 def moove_download_files(self, older_path, new_path, expression_search="*fsa"): 151 def moove_download_files(self, source, destination, expression_search="*"):
153 """ 152 """
154 Clean downloaded data by mooving fasta files in the final folder 153 Clean downloaded data by mooving fasta files in the final folder
155 @older_path: previous path where the files are located 154 @older_path: previous path where the files are located
156 @new_path: final path where files will be mooved 155 @new_path: final path where files will be mooved
157 @expression_search: keep only file with this expression 156 @expression_search: keep only file with this expression
158 """ 157 """
159 fasta_files = Path(older_path).rglob(expression_search) 158 fasta_files = Path(source).rglob(expression_search)
160 file_list_paths = [file for file in fasta_files if file.is_file()] 159 file_list_paths = [file for file in fasta_files if file.is_file()]
161 [self.keep_filename(pathname=path, output_path=new_path) for path in file_list_paths] 160 [self.keep_filename(pathname=path, output_path=destination) for path in file_list_paths]
162 161
163 def keep_filename(self, pathname, output_path): 162 def keep_filename(self, pathname, output_path):
164 """ 163 """
165 Moove files 164 Moove files
166 @pathname: previous path 165 @pathname: previous path