# Path: ariba/common.py
# class Error (Exception): pass
# def syscall(cmd, allow_fail=False, verbose=False, verbose_filehandle=sys.stdout, print_errors=True, shell=True):
# def decode(x):
# def cat_files(infiles, outfile):
# def download_file(url, outfile, max_attempts=3, sleep_time=2, verbose=False):
# def rmtree(input_dir):


import os
import sys
import csv
import zipfile
import pyfastaq
from ariba import common
    @classmethod
    def _extract_files(cls, zip_file, outdir):
        original_files = {'annotations': None, 'fasta': None, 'header_mappings': None}

        try:
            os.mkdir(outdir)
        except:
            raise Error('Error making directory ' + outdir)

        # Old <2.0.0 megares has eg these files:
        #  megares_annotations_v1.01.csv
        #  megares_database_v1.01.fasta
        #  megares_to_external_header_mappings_v1.01.tsv
        # megares 2.0.0 has these files:
        #  megares_drugs_annotations_v2.00.csv
        #  megares_drugs_database_v2.00.fasta
        #  megares_modified_annotations_v2.00.csv
        #  megares_modified_database_v2.00.fasta
        #  megares_to_external_header_mappings_v2.00.csv
        # The sequences in *_modified_* files seem to be a superset of
        # *_drugs_*, so use the *_modified_* ones. This will happen
        # as long as we loop over sorted filenames, because the _modified_
        # csv and fasta are listed last
        zfile = zipfile.ZipFile(zip_file)
        for member in sorted(zfile.namelist()):
            if '_annotations_' in member:
                original_files['annotations'] = member
            elif '_database_' in member and member.endswith('.fasta'):
                original_files['fasta'] = member
            elif '_header_mappings_' in member:

# Path: ariba/common.py
# class Error (Exception): pass
# def syscall(cmd, allow_fail=False, verbose=False, verbose_filehandle=sys.stdout, print_errors=True, shell=True):
# def decode(x):
# def cat_files(infiles, outfile):
# def download_file(url, outfile, max_attempts=3, sleep_time=2, verbose=False):
# def rmtree(input_dir):


# Path: ariba/megares_zip_parser.py
import os
import sys
import csv
import zipfile
import pyfastaq
from ariba import common

    @classmethod
    def _extract_files(cls, zip_file, outdir):
        original_files = {'annotations': None, 'fasta': None, 'header_mappings': None}

        try:
            os.mkdir(outdir)
        except:
            raise Error('Error making directory ' + outdir)

        # Old <2.0.0 megares has eg these files:
        #  megares_annotations_v1.01.csv
        #  megares_database_v1.01.fasta
        #  megares_to_external_header_mappings_v1.01.tsv
        # megares 2.0.0 has these files:
        #  megares_drugs_annotations_v2.00.csv
        #  megares_drugs_database_v2.00.fasta
        #  megares_modified_annotations_v2.00.csv
        #  megares_modified_database_v2.00.fasta
        #  megares_to_external_header_mappings_v2.00.csv
        # The sequences in *_modified_* files seem to be a superset of
        # *_drugs_*, so use the *_modified_* ones. This will happen
        # as long as we loop over sorted filenames, because the _modified_
        # csv and fasta are listed last
        zfile = zipfile.ZipFile(zip_file)
        for member in sorted(zfile.namelist()):
            if '_annotations_' in member:
                original_files['annotations'] = member
            elif '_database_' in member and member.endswith('.fasta'):
                original_files['fasta'] = member
            elif '_header_mappings_' in member:

                original_files['header_mappings'] = member