Browse Source

corrected save_contigs function

nicolas-zimmermann 4 years ago
parent
commit
1d75d1417c
1 changed files with 8 additions and 1 deletions
  1. 8 1
      debruijn/debruijn.py

+ 8 - 1
debruijn/debruijn.py View File

1
 """
1
 """
2
 Small assembly module based on de bruijn graphs
2
 Small assembly module based on de bruijn graphs
3
 """
3
 """
4
+import os
4
 import networkx as nx
5
 import networkx as nx
5
 from networkx import algorithms
6
 from networkx import algorithms
6
 
7
 
113
 def select_best_path():
114
 def select_best_path():
114
     pass
115
     pass
115
 
116
 
117
+def fill(text, width=80):
118
+    """Split text with a line return to respect fasta format"""
119
+    return os.linesep.join(text[i:i+width] for i in range(0, len(text), width))
116
 
120
 
117
 def save_contigs(tuples, outname):
121
 def save_contigs(tuples, outname):
118
     """
122
     """
120
         tuples, tuple: Obtained from get_contigs()
124
         tuples, tuple: Obtained from get_contigs()
121
         outname, str: name of the file to be written
125
         outname, str: name of the file to be written
122
     """
126
     """
127
+    i = 0
123
     with open(outname, "w") as outfile:
128
     with open(outname, "w") as outfile:
124
         for duo in tuples:
129
         for duo in tuples:
125
-            outfile.write("{} {}".format(duo[0], duo[1]))
130
+            i += 1
131
+            outfile.write(">contig_{} len={}\n".format(i, duo[1]))
132
+            outfile.write("{}\n".format(fill(duo[0])))
126
 
133
 
127
     return
134
     return
128
 
135