Skip to content

Commit

Permalink
Make compatible with SPAdes v4
Browse files Browse the repository at this point in the history
  • Loading branch information
rrwick committed Jun 5, 2024
1 parent 69e712e commit d153f67
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
5 changes: 4 additions & 1 deletion test/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,7 @@ def test_spades_version_status_12(self):
self.assertEqual(unicycler.misc.spades_status_from_version('3.15.3'), 'good')

def test_spades_version_status_13(self):
self.assertEqual(unicycler.misc.spades_status_from_version('4.0.0'), 'too new')
self.assertEqual(unicycler.misc.spades_status_from_version('4.0.0'), 'good')

def test_spades_version_status_14(self):
self.assertEqual(unicycler.misc.spades_status_from_version('5.0.0'), 'too new')
19 changes: 13 additions & 6 deletions test/test_spades_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,50 @@ def test_bad_fastq_2(self):
def test_build_spades_command_1(self):
command = unicycler.spades_func.build_spades_command('spades.py', 'out', 16, [21, 31, 41],
0, '1.fq.gz', '2.fq.gz', None, True,
False, None)
False, None, '3.15.5')
self.assertEqual(command, ['spades.py', '-o', 'out', '-k', '21', '--threads', '16',
'--isolate', '-1', '1.fq.gz', '-2', '2.fq.gz', '-m', '1024'])

def test_build_spades_command_2(self):
command = unicycler.spades_func.build_spades_command('spades.py', 'out', 16, [21, 31, 41],
1, '1.fq.gz', '2.fq.gz', None, True,
False, None)
False, None, '3.15.5')
self.assertEqual(command, ['spades.py', '-o', 'out', '-k', '21,31', '--threads', '16',
'--restart-from', 'k21', '-m', '1024'])

def test_build_spades_command_3(self):
command = unicycler.spades_func.build_spades_command('spades.py', 'out', 16, [21, 31, 41],
2, '1.fq.gz', '2.fq.gz', None, True,
False, None)
False, None, '3.15.5')
self.assertEqual(command, ['spades.py', '-o', 'out', '-k', '21,31,41', '--threads', '16',
'--restart-from', 'k31', '-m', '1024'])

def test_build_spades_command_4(self):
command = unicycler.spades_func.build_spades_command('spades.py', 'out', 16, [21, 31, 41],
0, None, None, 's.fq.gz', False, True,
None)
None, '3.15.5')
self.assertEqual(command, ['spades.py', '-o', 'out', '-k', '21', '--threads', '16',
'--isolate', '-s', 's.fq.gz', '-m', '1024'])

def test_build_spades_command_5(self):
command = unicycler.spades_func.build_spades_command('spades.py', 'out', 16, [21, 31, 41],
0, '1.fq.gz', '2.fq.gz', None, True,
False, '-m 123')
False, '-m 123', '3.15.5')
self.assertEqual(command, ['spades.py', '-o', 'out', '-k', '21', '--threads', '16',
'--isolate', '-1', '1.fq.gz', '-2', '2.fq.gz', '-m', '123'])

def test_build_spades_command_6(self):
command = unicycler.spades_func.build_spades_command('spades.py', 'out', 16, [21, 31, 41],
0, '1.fq.gz', '2.fq.gz', None, True,
False, '--tmp-dir abc')
False, '--tmp-dir abc', '3.15.5')
self.assertEqual(command, ['spades.py', '-o', 'out', '-k', '21', '--threads', '16',
'--isolate', '-1', '1.fq.gz', '-2', '2.fq.gz', '--tmp-dir',
'abc', '-m', '1024'])

def test_build_spades_command_7(self):
command = unicycler.spades_func.build_spades_command('spades.py', 'out', 16, [21, 31, 41],
0, '1.fq.gz', '2.fq.gz', None, True,
False, None, '4.0.0')
self.assertEqual(command, ['spades.py', '-o', 'out', '-k', '21', '--threads', '16',
'--gfa11', '--isolate', '-1', '1.fq.gz', '-2', '2.fq.gz',
'-m', '1024'])
26 changes: 13 additions & 13 deletions unicycler/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def print_table(table, alignments='', max_col_width=30, col_separation=3, indent
for text, colour_name in sub_colour.items():
row_str = row_str.replace(text, colour(text, colour_name))
if j < row_rows - 1 and UNDERLINE in row_str:
row_str = re.sub('\033\[4m', '', row_str)
row_str = re.sub('\033\\[4m', '', row_str)
if return_str:
full_table_str += indenter + row_str + '\n'
else:
Expand Down Expand Up @@ -740,8 +740,8 @@ def remove_formatting(text):

def get_ascii_art():
ascii_art = (bold_red(" __\n") +
bold_red(" \ \___\n") +
bold_red(" \ ___\\\n") +
bold_red(" \\ \\___\n") +
bold_red(" \\ ___\\\n") +
bold_red(" //\n") +
bold_red(" ____// ") +
bold_yellow("_ _ _ _\n") +
Expand All @@ -750,11 +750,11 @@ def get_ascii_art():
bold_red("// \\// \\\\ ") +
bold_yellow("| | | | _ __ _ ___ _ _ ___ | | ___ _ __\n") +
bold_red("|| (O) || ") +
bold_yellow("| | | || '_ \ | | / __|| | | | / __|| | / _ \| '__|\n") +
bold_red("\\\\ \_ // ") +
bold_yellow("| | | || '_ \\ | | / __|| | | | / __|| | / _ \\| '__|\n") +
bold_red("\\\\ \\_ // ") +
bold_yellow("| |__| || | | || || (__ | |_| || (__ | || __/| |\n") +
bold_red(" \\\\_____// ") +
bold_yellow("\____/ |_| |_||_| \___| \__, | \___||_| \___||_|\n") +
bold_yellow("\\____/ |_| |_||_| \\___| \\__, | \\___||_| \\___||_|\n") +
bold_yellow(" __/ |\n") +
bold_yellow(" |___/"))
return ascii_art
Expand Down Expand Up @@ -844,15 +844,15 @@ def spades_status_from_version(version):
major_version = int(version.split('.')[0])
if major_version < 3:
return 'too old'
if major_version >= 4:
if major_version >= 5:
return 'too new'
assert major_version == 3
assert major_version == 3 or major_version == 4

minor_version = int(version.split('.')[1])
if minor_version < 14:
return 'too old'
else:
return 'good'
if major_version == 3:
minor_version = int(version.split('.')[1])
if minor_version < 14:
return 'too old'
return 'good'


def racon_path_and_version(racon_path):
Expand Down
12 changes: 7 additions & 5 deletions unicycler/spades_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BadFastq(Exception):
def get_best_spades_graph(short1, short2, short_unpaired, out_dir, read_depth_filter, verbosity,
spades_path, threads, keep, kmer_count, min_k_frac, max_k_frac, kmers,
expected_linear_seqs, largest_component, spades_graph_prefix,
spades_options):
spades_options, spades_version):
"""
This function tries a SPAdes assembly at different k-mers and returns the best one.
"""
Expand Down Expand Up @@ -62,7 +62,7 @@ def get_best_spades_graph(short1, short2, short_unpaired, out_dir, read_depth_fi

graph_files, insert_size_mean, insert_size_deviation = \
run_spades_all_kmers(reads, spades_dir, kmer_range, threads, spades_path,
spades_graph_prefix, spades_options)
spades_graph_prefix, spades_options, spades_version)

existing_graph_files = [x for x in graph_files if x is not None]
if not existing_graph_files:
Expand Down Expand Up @@ -162,7 +162,7 @@ def get_best_spades_graph(short1, short2, short_unpaired, out_dir, read_depth_fi


def run_spades_all_kmers(read_files, spades_dir, kmers, threads, spades_path, spades_graph_prefix,
spades_options):
spades_options, spades_version):
"""
SPAdes is run with all k-mers up to the top one. For example:
* round 1: 25
Expand All @@ -183,7 +183,7 @@ def run_spades_all_kmers(read_files, spades_dir, kmers, threads, spades_path, sp
biggest_kmer = kmers[i]
command = build_spades_command(spades_path, spades_dir, threads, kmers, i, short1, short2,
unpaired, using_paired_reads, using_unpaired_reads,
spades_options)
spades_options, spades_version)
log.log(' '.join(command))
graph_file, insert_size_mean, insert_size_deviation = \
run_spades_one_kmer(command, spades_dir, biggest_kmer)
Expand Down Expand Up @@ -218,10 +218,12 @@ def run_spades_all_kmers(read_files, spades_dir, kmers, threads, spades_path, sp


def build_spades_command(spades_path, spades_dir, threads, kmers, i, short1, short2, unpaired,
using_paired_reads, using_unpaired_reads, spades_options):
using_paired_reads, using_unpaired_reads, spades_options, spades_version):
kmer_string = ','.join([str(x) for x in kmers[:i+1]])

command = [spades_path, '-o', spades_dir, '-k', kmer_string, '--threads', str(threads)]
if spades_version.startswith("4."):
command += ['--gfa11']
if i == 0: # first k-mer
command += ['--isolate']
if using_paired_reads:
Expand Down
5 changes: 3 additions & 2 deletions unicycler/unicycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def main():

check_input_files(args)
print_intro_message(args, full_command, out_dir_message)
check_dependencies(args, short_reads_available, long_reads_available)
spades_version = check_dependencies(args, short_reads_available, long_reads_available)

counter = itertools.count(start=1) # Files are numbered in chronological order.
bridges = []
Expand All @@ -78,7 +78,7 @@ def main():
args.spades_path, args.threads, args.keep,
args.kmer_count, args.min_kmer_frac, args.max_kmer_frac,
args.kmers, args.linear_seqs, args.largest_component,
spades_graph_prefix, args.spades_options)
spades_graph_prefix, args.spades_options, spades_version)
determine_copy_depth(graph)
if args.keep > 0 and not os.path.isfile(best_spades_graph):
graph.save_to_gfa(best_spades_graph, save_copy_depth_info=True, newline=True,
Expand Down Expand Up @@ -715,6 +715,7 @@ def check_dependencies(args, short_reads_available, long_reads_available):

quit_if_dependency_problem(spades_status, racon_status, makeblastdb_status, tblastn_status,
args)
return spades_version


def quit_if_dependency_problem(spades_status, racon_status, makeblastdb_status, tblastn_status,
Expand Down
2 changes: 1 addition & 1 deletion unicycler/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
not, see <http://www.gnu.org/licenses/>.
"""

__version__ = '0.5.0'
__version__ = '0.5.1'

0 comments on commit d153f67

Please sign in to comment.