Kaynağa Gözat

corrected save_contigs function

nicolas-zimmermann 5 yıl önce
ebeveyn
işleme
1d75d1417c
1 değiştirilmiş dosya ile 8 ekleme ve 1 silme
  1. 8 1
      debruijn/debruijn.py

+ 8 - 1
debruijn/debruijn.py Dosyayı Görüntüle

@@ -1,6 +1,7 @@
1 1
 """
2 2
 Small assembly module based on de bruijn graphs
3 3
 """
4
+import os
4 5
 import networkx as nx
5 6
 from networkx import algorithms
6 7
 
@@ -113,6 +114,9 @@ def remove_paths():
113 114
 def select_best_path():
114 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 121
 def save_contigs(tuples, outname):
118 122
     """
@@ -120,9 +124,12 @@ def save_contigs(tuples, outname):
120 124
         tuples, tuple: Obtained from get_contigs()
121 125
         outname, str: name of the file to be written
122 126
     """
127
+    i = 0
123 128
     with open(outname, "w") as outfile:
124 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 134
     return
128 135