Skip to content

Commit

Permalink
#62 Breaking fasta file into chunks files and retrieving all sequence…
Browse files Browse the repository at this point in the history
…s. Updating to DNASkittleUtils 1.0.11
  • Loading branch information
josiahseaman committed Nov 15, 2018
1 parent 72b94c0 commit 21e127a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 441 deletions.
18 changes: 16 additions & 2 deletions DDV/TileLayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def level_layout_factory(modulos, padding=None):
return levels



class TileLayout(object):

def __init__(self, use_fat_headers=False, use_titles=True, sort_contigs=False,
Expand Down Expand Up @@ -245,8 +246,10 @@ def draw_nucleotides(self):


def output_fasta(self, output_folder, fasta, no_webpage, extract_contigs, sort_contigs):
fasta_destination = os.path.join(output_folder, os.path.basename(fasta))
bare_file = os.path.basename(fasta)
fasta_destination = os.path.join(output_folder, bare_file)
if extract_contigs or sort_contigs:
write_contigs_to_chunks_dir(output_folder, bare_file, self.contigs)
length_sum = sum([len(c.seq) for c in self.contigs])
fasta_destination = '%s__%ibp.fa' % (os.path.splitext(fasta_destination)[0], length_sum)
write_contigs_to_file(fasta_destination, self.contigs) # shortened fasta
Expand All @@ -257,7 +260,7 @@ def output_fasta(self, output_folder, fasta, no_webpage, extract_contigs, sort_c
except shutil.SameFileError:
pass # not a problem

self.fasta_source.append(os.path.basename(fasta_destination))
self.fasta_source.append(bare_file)
print("Sequence saved in:", fasta_destination)
return fasta_destination

Expand Down Expand Up @@ -587,3 +590,14 @@ def get_packed_coordinates(self):
def additional_html_content(self, html_content):
return {} # override in children


def write_contigs_to_chunks_dir(project_dir, fasta_name, contigs):
chunks_dir = os.path.join(project_dir, 'chunks', fasta_name)
try:
os.makedirs(chunks_dir, exist_ok=True)
except BaseException:
pass
for i, contig in enumerate(contigs):
filename = os.path.join(chunks_dir, '%i.fa' % i)
write_contigs_to_file(filename, [contig],verbose=False)

Loading

0 comments on commit 21e127a

Please sign in to comment.