From fd6c5364aa2fc453b19454fbd3e6e343b8721504 Mon Sep 17 00:00:00 2001
From: "christoph.stritt@unibas.ch" <christoph.stritt@unibas.ch>
Date: Wed, 30 Oct 2024 13:46:22 +0100
Subject: [PATCH] ... and from the rename rule

---
 workflow/rules/circularize.smk | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/workflow/rules/circularize.smk b/workflow/rules/circularize.smk
index d5e731c..2e7e496 100755
--- a/workflow/rules/circularize.smk
+++ b/workflow/rules/circularize.smk
@@ -51,6 +51,8 @@ rule circlator_removeduplicates:
                 else:
                     if not skip:
                         output_handle.write(line)
+        
+        output_handle.close()
 
 
 rule circlator_localassembly:
@@ -112,26 +114,22 @@ rule rename:
     
     run:
 
-        import os
-        import sys
-        from Bio import SeqIO
-
         contig_NR = 1
 
         fasta_handle = open(output[0], "w")
 
         with open(input.assembly) as original:
 
-            records = SeqIO.parse(original, 'fasta')
+            for line in original:
+                if line.startswith('>'):
 
-            for record in records:
+                    seq_name = line.split(' ')[0][1:].strip()
+                    seq_name_new = '>' + params.prefix + '_' + str(contig_NR)
+                    fasta_handle.write(seq_name_new + '\n')
+                    contig_NR += 1
 
-                record.id = params.prefix + "_" + str(contig_NR)
-                record.description = ""
-                
-                SeqIO.write(record, fasta_handle, 'fasta')
-                
-                contig_NR += 1
+                else:
+                    fasta_handle.write(line)
 
         fasta_handle.close()
 
-- 
GitLab