|
1 | 1 | from xml.etree import ElementTree |
| 2 | +import os |
2 | 3 | import subprocess |
3 | 4 | from configManager import ConfigManager |
4 | 5 | from logger import Logger |
@@ -46,10 +47,26 @@ def write_fasta(sequences): |
46 | 47 | f.write(f">{sequence['subject']}\n{sequence['sequence']}\n") |
47 | 48 |
|
48 | 49 | def run_uclust(): |
49 | | - args = [usearch_binary_filename, '-cluster_fast', sequences_filename, '-id', uclust_identity, '-sort', 'length', '-uc', uclust_results_filename] |
50 | | - # result = subprocess.run(args, capture_output=True, text=True) # Python3.7 |
51 | | - result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) |
52 | | - logger_.log(result.stdout, True) |
| 50 | + if whichSearch == 'vsearch': |
| 51 | + args = [usearch_binary_filename, '--cluster_fast', sequences_filename, '--id', uclust_identity, '--uc', |
| 52 | + uclust_results_filename] |
| 53 | + else: |
| 54 | + args = [usearch_binary_filename, '-cluster_fast', sequences_filename, '-id', uclust_identity, '-sort', 'length', |
| 55 | + '-uc', uclust_results_filename] |
| 56 | + logger_.log(f'******** Running {whichSearch} clustering with identity {uclust_identity} ********', True) |
| 57 | + proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) |
| 58 | + for line in proc.stderr: |
| 59 | + line = line.strip() |
| 60 | + if line: |
| 61 | + logger_.log(line, True) |
| 62 | + proc.wait() |
| 63 | + if proc.returncode != 0: |
| 64 | + logger_.log(f'******** ERROR: {whichSearch} clustering failed with exit code {proc.returncode} ********', True) |
| 65 | + raise RuntimeError(f'clustering ({whichSearch}) failed (exit {proc.returncode}) — see indexing log for details') |
| 66 | + if not os.path.exists(uclust_results_filename) or os.path.getsize(uclust_results_filename) == 0: |
| 67 | + raise RuntimeError(f'{whichSearch} clustering produced no output — {uclust_results_filename} is missing or empty') |
| 68 | + logger_.log('******** Clustering completed successfully ********', True) |
| 69 | + |
53 | 70 |
|
54 | 71 | def analyze_uclust(): |
55 | 72 | total_parts = 0 |
@@ -82,7 +99,7 @@ def uclust2uris(fileName): |
82 | 99 |
|
83 | 100 | def uclust2clusters(): |
84 | 101 | cluster2parts = {} |
85 | | - |
| 102 | + |
86 | 103 | with open(uclust_results_filename, 'r') as f: |
87 | 104 | for line in f: |
88 | 105 | parts = line.split() |
|
0 commit comments