diff --git a/.gitignore b/.gitignore index 4d41f7c..a551d61 100644 --- a/.gitignore +++ b/.gitignore @@ -110,3 +110,6 @@ output/ validation/enterobase_90_50_with_blacklist.csv .coveragerc coverage_html_report/ + +# Conda-build backup files +*.bak diff --git a/.travis.yml b/.travis.yml index 726df1f..d39a94b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: python python: # We don't actually use the Travis Python, but this keeps it organized. + - "2.7" - "3.6" install: - sudo apt-get update @@ -18,10 +19,27 @@ install: - conda update -q conda # Useful for debugging any issues with conda - conda info -a - - conda config --add channels bioconda - - conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION samtools bowtie2 mash bcftools biopython nose blast pandas seqtk + - conda config --add channels bioconda --add channels conda-forge + - conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION samtools bowtie2 mash bcftools biopython nose blast pandas seqtk future - source activate test-environment + - if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then + conda install backports.weakref && conda install -c kevinkle subprocess32; + else + continue; + fi - python setup.py install - + # Setup automatic conda uploading. + # - conda install anaconda-client + # - conda config --set anaconda_upload yes + # test the conda build + - conda install conda-build + - if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then + conda build -c kevinkle -c bioconda recipe/ --python=2.7; + else + conda build -c bioconda recipe/ --python=3.6; + fi + - script: - - nosetests \ No newline at end of file + - nosetests +notifications: + email: false diff --git a/README.md b/README.md index 6b344d3..af9c419 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # ECTyper (an easy typer) -**ecyper** wraps a standalone serotyping module for _Escherichia coli_. +**ecyper** wraps a standalone serotyping module for _Escherichia coli_. Supports _fasta_ and _fastq_ file formats. +[![Build Status](https://travis-ci.org/phac-nml/ecoli_serotyping.svg?branch=master)](https://travis-ci.org/phac-nml/ecoli_serotyping) + # Dependencies: - python 3.6.3.* - pandas 0.21.0.* @@ -19,8 +21,8 @@ Supports _fasta_ and _fastq_ file formats. 1. `bash miniconda.sh -b -p $HOME/miniconda` 1. `export PATH="$HOME/miniconda/bin:$PATH"` 2. Install ectyper - * Directly via `conda` - 1. `conda install -c bioconda ectyper` + * Directly via `conda` + 1. `conda install -c bioconda ectyper` * Through `github` 1. Install dependencies `conda install pandas samtools bowtie2 mash bcftools biopython nose blast seqtk tqdm python=3.6` @@ -62,3 +64,13 @@ optional arguments: Directory location of output files. ``` * The first time species identification is enabled you will need to wait for **ectyper** to download the reference sequences. + +# Building the conda package +Python 2.7 +(requires a custom version of process32 from the channel kevinkle) + +`conda build -c kevinkle -c bioconda recipe/ --python=2.7` + +Python 3.6 + +`conda build -c bioconda recipe/ --python=3.6` diff --git a/ectyper.puml b/ectyper.puml deleted file mode 100644 index d0ce016..0000000 --- a/ectyper.puml +++ /dev/null @@ -1,45 +0,0 @@ -@startuml - - -(ectyper \ncommandline) as ectyper -:Third Party App: as 3rd -:User: -> [Galaxy] -[Galaxy] --> :User: -:User: --> ectyper : "\nvia REST API\n or local machine" -3rd --> ectyper : "via REST API" -Galaxy -> ectyper -(ectyper) --> Galaxy - -package JSON { - (ectyper) --> JSON -} - -package TSV{ - (ectyper) --> TSV -} - -JSON --> [Galaxy] -JSON --> 3rd -TSV --> :User: - - - -'(Use the application) as (Use) -' -'User -> (Start) -'User --> (Use) -' -'Galaxy ---> (Use) - -'note right of Galaxy : This is an example. -' -'note right of (Use) -'A note can also -'be on several lines -'end note -' -'note "This note is connected\nto several objects." as N2 -'(Start) .. N2 -'N2 .. (Use) - -@enduml \ No newline at end of file diff --git a/ectyper/blastFunctions.py b/ectyper/blastFunctions.py index dcbb87a..f961caa 100644 --- a/ectyper/blastFunctions.py +++ b/ectyper/blastFunctions.py @@ -3,6 +3,14 @@ """ Functions for setting up, running, and parsing blast """ +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import division +from __future__ import absolute_import +from builtins import open +from builtins import str +from future import standard_library +standard_library.install_aliases() import logging import os diff --git a/ectyper/commandLineOptions.py b/ectyper/commandLineOptions.py index cab18d9..28ba788 100644 --- a/ectyper/commandLineOptions.py +++ b/ectyper/commandLineOptions.py @@ -1,5 +1,12 @@ #!/usr/bin/env python +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import division +from __future__ import absolute_import +from builtins import int +from future import standard_library +standard_library.install_aliases() import argparse diff --git a/ectyper/definitions.py b/ectyper/definitions.py index 1258da7..4144c00 100644 --- a/ectyper/definitions.py +++ b/ectyper/definitions.py @@ -3,12 +3,25 @@ """ Definitions for the ectyper project """ +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import division +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() import os +import sys ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) DATA_DIR = os.path.join(ROOT_DIR, 'Data') -WORKPLACE_DIR = os.getcwd() +# Python3 vs Python2 difference. +try: + # Python3 + WORKPLACE_DIR = os.getcwdu() +except: + # Python2 + WORKPLACE_DIR = os.getcwd() SEROTYPE_FILE = os.path.join(DATA_DIR, 'ectyper_data.fasta') SEROTYPE_ALLELE_JSON = os.path.join(DATA_DIR, 'ectyper_dict.json') @@ -18,3 +31,22 @@ SAMTOOLS = 'samtools' REFSEQ_SUMMARY = os.path.join(DATA_DIR, 'assembly_summary_refseq.txt') REFSEQ_SKETCH = os.path.join(DATA_DIR, 'refseq.genomes.k21s1000.msh') + +if os.name == 'posix' and sys.version_info[0] < 3: + # Python2 + from ectyper.tempfile import TemporaryDirectory + from tempfile import NamedTemporaryFile +else: + # Python3 + from tempfile import TemporaryDirectory, NamedTemporaryFile +# Aliases +TEMPDIR = TemporaryDirectory +NAMEDTEMPFILE = NamedTemporaryFile + +# Python 2.7 Compatibility +if sys.version_info[0] < 3: + # In Python 2.7, Pandas will need binary (not unicode) when using open(). + read_flags = 'rb' +else: + # Python 3.6 will read as unicode text when using open(). + read_flags = 'r' diff --git a/ectyper/ectyper.py b/ectyper/ectyper.py index 588134e..f494a43 100644 --- a/ectyper/ectyper.py +++ b/ectyper/ectyper.py @@ -2,10 +2,17 @@ """ Predictive serotyping for _E. coli_. """ +from __future__ import division +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import absolute_import +from builtins import range +from builtins import str +from future import standard_library +standard_library.install_aliases() import logging import os import sys -import tempfile import datetime from urllib.request import urlretrieve @@ -40,7 +47,7 @@ def run_program(): LOG.debug(args) ## Initialize temporary directories for the scope of this program - with tempfile.TemporaryDirectory() as temp_dir: + with definitions.TEMPDIR() as temp_dir: temp_files = create_tmp_files(temp_dir, output_dir=args.output) LOG.debug(temp_files) @@ -167,7 +174,7 @@ def create_tmp_files(temp_dir, output_dir=None): def run_prediction(genome_files, args, predictions_file): '''Core prediction functionality - + Args: genome_files: list of genome files @@ -175,14 +182,14 @@ def run_prediction(genome_files, args, predictions_file): commandline arguments predictions_file: filename of prediction output - + Returns: predictions_file with prediction written in it ''' query_file = definitions.SEROTYPE_FILE ectyper_dict_file = definitions.SEROTYPE_ALLELE_JSON # create a temp dir for blastdb - with tempfile.TemporaryDirectory() as temp_dir: + with definitions.TEMPDIR() as temp_dir: # Divide genome files into chunks chunk_size = 50 genome_chunks = [ @@ -191,6 +198,8 @@ def run_prediction(genome_files, args, predictions_file): ] for index, chunk in enumerate(genome_chunks): LOG.info("Start creating blast database #{0}".format(index + 1)) + LOG.info("Using SEROTYPE_FILE: {0}".format(query_file)) + LOG.info("Using SEROTYPE_ALLELE_JSON: {0}".format(ectyper_dict_file)) blast_db = blastFunctions.create_blast_db(chunk, temp_dir) LOG.info("Start blast alignment on database #{0}".format(index + 1)) @@ -204,10 +213,10 @@ def run_prediction(genome_files, args, predictions_file): def get_raw_files(raw_files): """Take all the raw files, and filter not fasta / fastq - + Args: raw_files(str): list of files from user input - + Returns: A dictitionary collection of fasta and fastq files example: @@ -235,7 +244,7 @@ def filter_for_ecoli_files(raw_dict, temp_files, verify=False, species=False): Assemble fastq files to fasta files, then filter all files by reference method if verify is enabled, if identified as non-ecoli, identify species by mash method if species is enabled. - + Args: raw_dict{fasta:list_of_files, fastq:list_of_files}: dictionary collection of fasta and fastq files @@ -266,7 +275,7 @@ def filter_file_by_species(genome_file, genome_format, temp_dir, verify=False, s Assemble fastq file to fasta file, then filter the file by reference method if verify is enabled, if identified as non-ecoli, identify species by mash method if species is enabled. - + Args: genome_file: input genome file genome_format(str): fasta or fastq diff --git a/ectyper/genomeFunctions.py b/ectyper/genomeFunctions.py index 6dd7daa..ae5b401 100644 --- a/ectyper/genomeFunctions.py +++ b/ectyper/genomeFunctions.py @@ -1,12 +1,18 @@ ''' Genome Utilities ''' +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import division +from __future__ import absolute_import #!/usr/bin/env python +from builtins import str +from future import standard_library +standard_library.install_aliases() import logging import os import re -import tempfile from tarfile import is_tarfile from Bio import SeqIO @@ -63,14 +69,14 @@ def get_valid_format(file): """ for fm in ['fastq', 'fasta']: try: - with open(file, "r") as handle: + with open(file, definitions.read_flags) as handle: data = SeqIO.parse(handle, fm) if any(data): if is_tarfile(file): LOG.warning("Compressed file is not supported: {}".format(file)) return None return fm - except FileNotFoundError as err: + except IOError as err: LOG.warning("{0} is not found".format(file)) return None except UnicodeDecodeError as err: @@ -113,14 +119,14 @@ def get_genome_names_from_files(files, temp_dir): n_name = file_path_name.replace(' ', '_') # create a new file for the updated fasta headers - new_file = tempfile.NamedTemporaryFile(dir=temp_dir, delete=False).name + new_file = definitions.NAMEDTEMPFILE(dir=temp_dir, delete=False).name # add the new name to the list of files and genomes list_of_files.append(new_file) list_of_genomes.append(n_name) with open(new_file, "w") as outfile: - with open(file) as infile: + with open(file, definitions.read_flags) as infile: for record in SeqIO.parse(infile, "fasta"): outfile.write(">lcl|" + n_name + "|" + record.description + "\n") outfile.write(str(record.seq) + "\n") diff --git a/ectyper/loggingFunctions.py b/ectyper/loggingFunctions.py index d55f1ac..3a22bcf 100644 --- a/ectyper/loggingFunctions.py +++ b/ectyper/loggingFunctions.py @@ -2,7 +2,13 @@ """ Set up the logging """ +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import division +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() import logging import os diff --git a/ectyper/predictionFunctions.py b/ectyper/predictionFunctions.py index 8401e10..be33083 100644 --- a/ectyper/predictionFunctions.py +++ b/ectyper/predictionFunctions.py @@ -1,9 +1,18 @@ #!/usr/bin/env python +from __future__ import division +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import absolute_import +# from builtins import open +from future import standard_library +standard_library.install_aliases() import json import logging import os +import sys from collections import defaultdict +from ectyper import definitions import pandas as pd @@ -15,7 +24,7 @@ def predict_serotype(blast_output_file, ectyper_dict_file, predictions_file, detailed=False): """Make serotype prediction for all genomes based on blast output - + Args: blast_output_file(str): blastn output with outfmt: @@ -26,7 +35,7 @@ def predict_serotype(blast_output_file, ectyper_dict_file, predictions_file, det csv file to store result detailed(bool, optional): whether to generate detailed output or not - + Returns: predictions_file """ @@ -64,7 +73,7 @@ def predict_serotype(blast_output_file, ectyper_dict_file, predictions_file, det def get_prediction(per_genome_df, predictions_columns, gene_pairs, detailed, ): """Make serotype prediction for single genomes based on blast output - + Args: per_genome_df(DataFrame): blastn outputs for the given genome @@ -96,7 +105,7 @@ def get_prediction(per_genome_df, predictions_columns, gene_pairs, detailed, ): predictions[gene] = True if not predictions[predicting_antigen+'_prediction']: serotype = row['serotype'] - if serotype[0] is not predicting_antigen: + if serotype[0] != predicting_antigen: continue genes_pool[gene].append(serotype) prediction = None @@ -135,16 +144,20 @@ def blast_output_to_df(blast_output_file): '''Convert raw blast output file to DataFrame Args: blast_output_file(str): location of blast output - + Returns: DataFrame: DataFrame that contains all informations from blast output ''' # Load blast output output_data = [] - with open(blast_output_file, 'r') as fh: + with open(blast_output_file, definitions.read_flags) as fh: for line in fh: fields = line.strip().split() + # Python 2.7 Compatibility + sframe_value = fields[7] + if sys.version_info[0] < 3 and sframe_value == '-1': + sframe_value = '1' entry = { 'qseqid': fields[0], 'qlen': fields[1], @@ -153,7 +166,7 @@ def blast_output_to_df(blast_output_file): 'pident': fields[4], 'sstart': fields[5], 'send': fields[6], - 'sframe': fields[7], + 'sframe': sframe_value, 'qcovhsp': fields[8] } output_data.append(entry) @@ -172,7 +185,7 @@ def blast_output_to_df(blast_output_file): def ectyper_dict_to_df(ectyper_dict_file): # Read ectyper dict - with open(ectyper_dict_file) as fh: + with open(ectyper_dict_file, definitions.read_flags) as fh: ectyper_dict = json.load(fh) temp_list = [] for antigen, alleles in ectyper_dict.items(): @@ -202,11 +215,11 @@ def store_df(src_df, dst_file): def report_result(csv_file): '''Report the content of dataframe in log - + Args: csv_file(str): location of the prediction file ''' - df = pd.read_csv(csv_file) + df = pd.read_csv(csv_file, encoding='utf-8') if df.empty: LOG.info('No prediction was made becuase no alignment was found') return @@ -214,7 +227,7 @@ def report_result(csv_file): def add_non_predicted(all_genomes_list, predictions_file): '''Add genomes that do not show up in blast result to prediction file - + Args: all_genome_list(list): list of genomes from user input @@ -223,9 +236,9 @@ def add_non_predicted(all_genomes_list, predictions_file): Returns: str: location of the prediction file ''' - df = pd.read_csv(predictions_file) + df = pd.read_csv(predictions_file, encoding='utf-8') df = df.merge(pd.DataFrame(all_genomes_list, columns=['genome']), on='genome', how='outer') df.fillna({'O_info':'No alignment found', 'H_info':'No alignment found'}, inplace=True) df.fillna('-', inplace=True) - df.to_csv(predictions_file, index=False) + df.to_csv(predictions_file, index=False, encoding='utf-8') return predictions_file diff --git a/ectyper/speciesIdentification.py b/ectyper/speciesIdentification.py index bb1e63e..a8a5519 100644 --- a/ectyper/speciesIdentification.py +++ b/ectyper/speciesIdentification.py @@ -1,7 +1,14 @@ +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import division +from __future__ import absolute_import +from builtins import open +from builtins import str +from future import standard_library +standard_library.install_aliases() import logging import multiprocessing import os -import tempfile from Bio import SeqIO from ectyper import genomeFunctions, blastFunctions, definitions, subprocess_util @@ -51,7 +58,7 @@ def get_num_hits(target): ''' num_hit = 0 try: - with tempfile.TemporaryDirectory() as temp_dir: + with definitions.TEMPDIR() as temp_dir: blast_db = blastFunctions.create_blast_db([target], temp_dir) result = blastFunctions.run_blast_for_identification( definitions.ECOLI_MARKERS, @@ -83,7 +90,7 @@ def get_species(file): return None species = 'unknown' if genomeFunctions.get_valid_format(file) == 'fasta': - tmp_file = tempfile.NamedTemporaryFile().name + tmp_file = definitions.NAMEDTEMPFILE().name basename = os.path.basename(file).replace(' ', '_') with open(tmp_file, 'w') as new_fh: header = '> {0}\n'.format(basename) diff --git a/ectyper/subprocess_util.py b/ectyper/subprocess_util.py index 5f1391f..1a594c0 100644 --- a/ectyper/subprocess_util.py +++ b/ectyper/subprocess_util.py @@ -1,9 +1,21 @@ ''' Utilities ''' +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import division +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() import logging -import subprocess import timeit +import os +import sys + +if os.name == 'posix' and sys.version_info[0] < 3: + import subprocess32 as subprocess +else: + import subprocess LOG = logging.getLogger(__name__) diff --git a/ectyper/tempfile.py b/ectyper/tempfile.py new file mode 100644 index 0000000..de3d79d --- /dev/null +++ b/ectyper/tempfile.py @@ -0,0 +1,75 @@ +""" +Partial backport of Python 3.5's tempfile module: + + TemporaryDirectory + +Backport modifications are marked with marked with "XXX backport". +""" +from __future__ import absolute_import + +import sys +import warnings as _warnings +from shutil import rmtree as _rmtree + +from backports.weakref import finalize + + +# XXX backport: Rather than backporting all of mkdtemp(), we just create a +# thin wrapper implementing its Python 3.5 signature. +if sys.version_info < (3, 5): + from tempfile import mkdtemp as old_mkdtemp + + def mkdtemp(suffix=None, prefix=None, dir=None): + """ + Wrap `tempfile.mkdtemp()` to make the suffix and prefix optional (like Python 3.5). + """ + kwargs = {k: v for (k, v) in + dict(suffix=suffix, prefix=prefix, dir=dir).items() + if v is not None} + return old_mkdtemp(**kwargs) + +else: + from tempfile import mkdtemp + + +# XXX backport: ResourceWarning was added in Python 3.2. +# For earlier versions, fall back to RuntimeWarning instead. +_ResourceWarning = RuntimeWarning if sys.version_info < (3, 2) else ResourceWarning + + +class TemporaryDirectory(object): + """Create and return a temporary directory. This has the same + behavior as mkdtemp but can be used as a context manager. For + example: + + with TemporaryDirectory() as tmpdir: + ... + + Upon exiting the context, the directory and everything contained + in it are removed. + """ + + def __init__(self, suffix=None, prefix=None, dir=None): + self.name = mkdtemp(suffix, prefix, dir) + self._finalizer = finalize( + self, self._cleanup, self.name, + warn_message="Implicitly cleaning up {!r}".format(self)) + + @classmethod + def _cleanup(cls, name, warn_message): + _rmtree(name) + _warnings.warn(warn_message, _ResourceWarning) + + + def __repr__(self): + return "<{} {!r}>".format(self.__class__.__name__, self.name) + + def __enter__(self): + return self.name + + def __exit__(self, exc, value, tb): + self.cleanup() + + def cleanup(self): + if self._finalizer.detach(): + _rmtree(self.name) diff --git a/recipe/ectyper/build.sh b/recipe/ectyper/build.sh deleted file mode 100644 index 55ea547..0000000 --- a/recipe/ectyper/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -$PYTHON setup.py install \ No newline at end of file diff --git a/recipe/ectyper/meta.yaml b/recipe/ectyper/meta.yaml index 209efd2..3bd4873 100644 --- a/recipe/ectyper/meta.yaml +++ b/recipe/ectyper/meta.yaml @@ -6,25 +6,36 @@ about: package: name: ectyper - version: 0.0.8 + version: 0.0.9 source: - url: https://github.com/phac-nml/ecoli_serotyping/archive/239795e27446c467c8100aeaa73a741efdbb026f.zip - md5: d2cfb90afe8290b60c9c491aaee8db70 + path: ../../ + +build: + script: python setup.py install requirements: build: - - python 3.6.3.* + - python >=2.7,<3|>=3.3,{{PY_VER}}* + - future + - backports.weakref # [py27] run: - - python 3.6.3.* - - pandas 0.21.0.* - - samtools 1.5.* - - bowtie2 2.3.0.* - - mash 1.1.* - - bcftools 1.6.* - - biopython 1.69.* - - blast 2.2.31 .* - - seqtk 1.2.* + - python {{PY_VER}}* + - future + - backports.weakref # [py27] + - pandas >=0.21.1.* + - samtools >=1.5.* + - bowtie2 >=2.3.0.* + - mash >=1.1.* + - bcftools >=1.6.* + - biopython >=1.68.* + - blast >=2.2.31.* + - seqtk >=1.2.* + - subprocess32 >=3.5.0 # [py27] test: + requires: # note: our travis env is defined in .travis.yml, not here. + - backports.weakref # [py27] + - future + - subprocess32 >=3.5.0 # [py27] commands: - ectyper -h diff --git a/setup.py b/setup.py index 27ecb89..72066c3 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,8 @@ +from __future__ import print_function +from __future__ import division +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() try: from setuptools import setup except ImportError: @@ -5,7 +10,7 @@ setup( name='ectyper', - version='0.0.8', + version='0.0.9', description='E. coli serotyping', url='https://github.com/phac-nml/ecoli_serotyping', author='Camille La Rose, Chad Laing, Sam Sung', @@ -14,6 +19,9 @@ scripts=['bin/ectyper'], packages=['ectyper'], package_data={'ectyper': ['Data/*']}, + install_requires=[ + 'future', + ], zip_safe=False, test_suite='nose.collector' -) \ No newline at end of file +) diff --git a/test/ectyper_test.py b/test/ectyper_test.py index 69f240e..d9ab7dc 100644 --- a/test/ectyper_test.py +++ b/test/ectyper_test.py @@ -1,8 +1,15 @@ +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import division +from __future__ import absolute_import +from builtins import open +from builtins import str +from future import standard_library +standard_library.install_aliases() import argparse import hashlib import os import sys -import tempfile import unittest sys.path.append(os.path.join(os.path.dirname(__file__), "..")) diff --git a/test/genome_test.py b/test/genome_test.py index 86bc7fb..25a3086 100644 --- a/test/genome_test.py +++ b/test/genome_test.py @@ -1,3 +1,9 @@ +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import division +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() import os import sys import unittest diff --git a/test/prediction_test.py b/test/prediction_test.py index 09b3377..28d6610 100644 --- a/test/prediction_test.py +++ b/test/prediction_test.py @@ -1,12 +1,17 @@ +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import division +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() import datetime import os import sys -import tempfile import unittest import pandas as pd sys.path.append(os.path.join(os.path.dirname(__file__), "..")) -from ectyper import commandLineOptions, ectyper, predictionFunctions +from ectyper import commandLineOptions, ectyper, predictionFunctions, definitions class TestPrediction(unittest.TestCase): @@ -60,14 +65,14 @@ def test_two_prediction(self): def helper(self, genome_file): args = commandLineOptions.parse_command_line(['-i', 'test']) genome_file = genome_file - with tempfile.TemporaryDirectory() as temp_dir: + with definitions.TEMPDIR() as temp_dir: prediction_file = os.path.join(temp_dir + 'output.csv') ectyper.run_prediction([genome_file], args, prediction_file) basename, extension = os.path.splitext(prediction_file) raw_prediction_file = ''.join([basename, '_raw', extension]) predictionFunctions.add_non_predicted( [os.path.splitext(os.path.basename(genome_file))[0]], prediction_file) - return pd.read_csv(prediction_file), pd.read_csv(raw_prediction_file) + return pd.read_csv(prediction_file, encoding='utf-8'), pd.read_csv(raw_prediction_file, encoding='utf-8') if __name__ == '__main__': diff --git a/test/species_test.py b/test/species_test.py index ab8b7e9..09ca38f 100644 --- a/test/species_test.py +++ b/test/species_test.py @@ -1,3 +1,9 @@ +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import division +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() import os import sys import unittest