From 1d75d1417c0460bdf8410335b84c7e7f7b5593f6 Mon Sep 17 00:00:00 2001 From: nicolas-zimmermann Date: Tue, 22 Oct 2019 16:26:04 +0200 Subject: [PATCH] corrected save_contigs function --- debruijn/debruijn.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/debruijn/debruijn.py b/debruijn/debruijn.py index c0b6f9f..f0e8753 100644 --- a/debruijn/debruijn.py +++ b/debruijn/debruijn.py @@ -1,6 +1,7 @@ """ Small assembly module based on de bruijn graphs """ +import os import networkx as nx from networkx import algorithms @@ -113,6 +114,9 @@ def remove_paths(): def select_best_path(): pass +def fill(text, width=80): + """Split text with a line return to respect fasta format""" + return os.linesep.join(text[i:i+width] for i in range(0, len(text), width)) def save_contigs(tuples, outname): """ @@ -120,9 +124,12 @@ def save_contigs(tuples, outname): tuples, tuple: Obtained from get_contigs() outname, str: name of the file to be written """ + i = 0 with open(outname, "w") as outfile: for duo in tuples: - outfile.write("{} {}".format(duo[0], duo[1])) + i += 1 + outfile.write(">contig_{} len={}\n".format(i, duo[1])) + outfile.write("{}\n".format(fill(duo[0]))) return