Skip to content

Commit

Permalink
add manifests to default zip collection output
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Jun 23, 2021
1 parent 99199ee commit 096b141
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/sourmash/sourmash_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import traceback
import gzip
import zipfile
from io import StringIO

import screed
import sourmash
Expand All @@ -20,6 +21,7 @@
from .index import (LinearIndex, ZipFileLinearIndex, MultiIndex)
from . import signature as sigmod
from .picklist import SignaturePicklist, PickStyle
from .manifest import CollectionManifest


DEFAULT_LOAD_K = 31
Expand Down Expand Up @@ -722,10 +724,20 @@ def __repr__(self):
return f"SaveSignatures_ZipFile('{self.location}')"

def close(self):
# finish constructing manifest object & save
manifest = CollectionManifest(self.manifest_rows)
manifest_name = f"SOURMASH-MANIFEST.csv"

manifest_fp = StringIO()
manifest.write_to_csv(manifest_fp, write_header=True)
manifest_data = manifest_fp.getvalue().encode("utf-8")

self.zf.writestr(manifest_name, manifest_data)
self.zf.close()

def open(self):
self.zf = zipfile.ZipFile(self.location, 'w', zipfile.ZIP_STORED)
self.manifest_rows = []

def _exists(self, name):
try:
Expand Down Expand Up @@ -754,6 +766,11 @@ def add(self, ss):
json_str = sourmash.save_signatures([ss], compression=1)
self.zf.writestr(outname, json_str)

# update manifest
row = CollectionManifest.make_manifest_row(ss, outname,
include_signature=False)
self.manifest_rows.append(row)


class SigFileSaveType(Enum):
SIGFILE = 1
Expand Down

0 comments on commit 096b141

Please sign in to comment.