Skip to content

Commit

Permalink
Merge branch 'master' into fix-fasta
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosp420 committed Jun 28, 2020
2 parents 50a10fc + 79cf7dc commit 09fbd99
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ clean-test:
rm -rf cover/

test: clean-test
nosetests --verbosity=2 -w tests
nosetests --verbosity=2 --with-coverage -w tests

coverage: clean-test
coverage run --source=dataset_creator setup.py test
coverage: test
coverage report -m
coverage html

Expand Down
5 changes: 1 addition & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:align: center
:alt: Dataset-creator


=========================================
Dataset creator for phylogenetic software
=========================================
Expand All @@ -12,7 +13,6 @@ Dataset creator for phylogenetic software

* - tests
- | |travis| |requires| |coveralls|
| |quantified-code|
* - package
- |version| |wheel| |supported-versions| |supported-implementations|

Expand Down Expand Up @@ -44,9 +44,6 @@ Dataset creator for phylogenetic software
:alt: Supported implementations
:target: https://pypi.python.org/pypi/dataset-creator

.. |quantified-code| image:: https://www.quantifiedcode.com/api/v1/project/f059ab475f2547758722b80ea528c457/badge.svg
:target: https://www.quantifiedcode.com/app/project/f059ab475f2547758722b80ea528c457
:alt: Code issues

Dataset-Creator - easy way to creat phylogenetic datasets in many formats
=========================================================================
Expand Down
9 changes: 2 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import io
import re
import sys
from os.path import dirname
from os.path import join

Expand All @@ -24,9 +23,6 @@ def read(*names, **kwargs):
'six==1.10.0',
]

if sys.version_info < (2, 7,):
required_libs.append('ordereddict==1.1')

setup(
name='dataset-creator',
version='0.3.21',
Expand All @@ -45,12 +41,11 @@ def read(*names, **kwargs):
'Operating System :: Unix',
'Operating System :: POSIX',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Utilities',
],
Expand Down
9 changes: 7 additions & 2 deletions tests/test_creator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
from copy import copy

from .data import test_data
from dataset_creator.dataset import Dataset
Expand All @@ -8,9 +9,13 @@
class TestCreator(unittest.TestCase):
def setUp(self):
self.maxDiff = None
self.test_data = copy(test_data)

def tearDown(self):
self.test_data = None

def test_nexus_header(self):
dataset = Dataset(test_data, format='NEXUS', partitioning='by gene')
dataset = Dataset(self.test_data, format='NEXUS', partitioning='by gene')
creator = Creator(dataset.data, format='NEXUS')
expected = """
#NEXUS
Expand All @@ -24,7 +29,7 @@ def test_nexus_header(self):
self.assertEqual(expected.strip(), result)

def test_nexus_dataset_block(self):
dataset = Dataset(test_data, format='NEXUS', partitioning='by gene')
dataset = Dataset(self.test_data, format='NEXUS', partitioning='by gene')
creator = Creator(dataset.data, format='NEXUS')
expected = """
[ArgKin]
Expand Down
42 changes: 21 additions & 21 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import unittest
from copy import copy

from seqrecord_expanded import SeqRecordExpanded

Expand All @@ -15,6 +16,8 @@
class TestDataset(unittest.TestCase):
def setUp(self):
self.maxDiff = None
self.test_data = copy(test_data)
self.test_data_numbers = get_test_data("sample_data_numbers.txt")

def test_sorting_seq_records(self):
"""Test SeqRecordExpanded objects are sorted by gene_code and then by
Expand Down Expand Up @@ -61,113 +64,110 @@ def test_sorting_seq_records(self):
self.assertEqual(expected, [i.voucher_code for i in result])

def test_extract_genes(self):
dataset = Dataset(test_data, format='NEXUS', partitioning='by gene')
dataset = Dataset(self.test_data, format='NEXUS', partitioning='by gene')
expected = ['ArgKin', 'COI-begin', 'COI_end', 'ef1a', 'RpS2', 'RpS5', 'wingless']
result = dataset.gene_codes
self.assertEqual(expected, result)

def test_extract_number_of_chars(self):
dataset = Dataset(test_data, format='NEXUS', partitioning='by gene')
dataset = Dataset(self.test_data, format='NEXUS', partitioning='by gene')
expected = '4739'
result = dataset.number_chars
self.assertEqual(expected, result)

def test_extract_number_of_chars_wrong_argument(self):
self.assertRaises(AttributeError,
Dataset, test_data, format='NEXUS', partitioning='by gene',
Dataset, self.test_data, format='NEXUS', partitioning='by gene',
codon_positions='5th position')

def test_extract_number_of_chars_first_codon_positions(self):
dataset = Dataset(test_data, format='NEXUS', partitioning='by gene',
dataset = Dataset(self.test_data, format='NEXUS', partitioning='by gene',
codon_positions='1st')
expected = '1578'
result = dataset.number_chars
self.assertEqual(expected, result)

def test_extract_number_of_chars_second_codon_positions(self):
dataset = Dataset(test_data, format='NEXUS', partitioning='by gene',
dataset = Dataset(self.test_data, format='NEXUS', partitioning='by gene',
codon_positions='2nd')
expected = '1577'
result = dataset.number_chars
self.assertEqual(expected, result)

def test_extract_number_of_chars_third_codon_positions(self):
dataset = Dataset(test_data, format='NEXUS', partitioning='by gene',
dataset = Dataset(self.test_data, format='NEXUS', partitioning='by gene',
codon_positions='3rd')
expected = '1573'
result = dataset.number_chars
self.assertEqual(expected, result)

def test_extract_number_of_chars_first_and_second_codon_positions(self):
dataset = Dataset(test_data, format='NEXUS', partitioning='by gene',
dataset = Dataset(self.test_data, format='NEXUS', partitioning='by gene',
codon_positions='1st-2nd')
expected = '3155'
result = dataset.number_chars
self.assertEqual(expected, result)

def test_extract_number_of_taxa(self):
dataset = Dataset(test_data, format='NEXUS', partitioning='by gene')
dataset = Dataset(self.test_data, format='NEXUS', partitioning='by gene')
expected = '10'
result = dataset.number_taxa
self.assertEqual(expected, result)

def test_prepared_data(self):
dataset = Dataset(test_data, format='NEXUS', partitioning='by gene')
dataset = Dataset(self.test_data, format='NEXUS', partitioning='by gene')
expected = ['ArgKin', 'COI-begin', 'COI_end', 'ef1a', 'RpS2', 'RpS5', 'wingless']
result = dataset.data.gene_codes
self.assertEqual(expected, result)

def test_dataset_nexus(self):
dataset = Dataset(test_data, format='NEXUS', partitioning='by gene')
dataset = Dataset(self.test_data, format='NEXUS', partitioning='by gene')
test_data_file = os.path.join(NEXUS_DATA_PATH, 'dataset.nex')
expected = open(test_data_file, 'r').read()
result = dataset.dataset_str
self.assertEqual(expected.strip(), result)

def test_dataset_nexus_using_default_parameters(self):
dataset = Dataset(test_data, format='NEXUS')
dataset = Dataset(self.test_data, format='NEXUS')
test_data_file = os.path.join(NEXUS_DATA_PATH, 'dataset.nex')
expected = open(test_data_file, 'r').read()
result = dataset.dataset_str
self.assertEqual(expected.strip(), result)

def test_dataset_nexus_wrong_partitioning_parameter(self):
self.assertRaises(AttributeError, Dataset, seq_records=test_data, format='NEXUS',
self.assertRaises(AttributeError, Dataset, seq_records=self.test_data, format='NEXUS',
codon_positions='1st', partitioning='1st-2nd-3rd')

def test_dataset_nexus_1st_codon_position(self):
test_data = get_test_data("sample_data_numbers.txt")
dataset = Dataset(test_data, format='NEXUS', codon_positions='1st', partitioning='by gene')
dataset = Dataset(self.test_data_numbers, format='NEXUS', codon_positions='1st', partitioning='by gene')
test_data_file = os.path.join(NEXUS_DATA_PATH, 'dataset_1st_codon_numbers.nex')
expected = open(test_data_file, 'r').read()
result = dataset.dataset_str
self.assertEqual(expected.strip(), result)

def test_dataset_nexus_3rd_codon_position(self):
test_data = get_test_data("sample_data_numbers.txt")
dataset = Dataset(test_data, format='NEXUS', codon_positions='3rd', partitioning='by codon position')
dataset = Dataset(self.test_data_numbers, format='NEXUS', codon_positions='3rd', partitioning='by codon position')
test_data_file = os.path.join(NEXUS_DATA_PATH, 'dataset_3rd_codon_numbers.nex')
expected = open(test_data_file, 'r').read()
result = dataset.dataset_str
self.assertEqual(expected, result)

def test_dataset_nexus_3rd_codon_position_partitioned_as_1st2nd_3rd(self):
test_data = get_test_data("sample_data_numbers.txt")
dataset = Dataset(test_data, format='NEXUS', codon_positions='3rd', partitioning='1st-2nd, 3rd')
dataset = Dataset(self.test_data_numbers, format='NEXUS', codon_positions='3rd', partitioning='1st-2nd, 3rd')
test_data_file = os.path.join(NEXUS_DATA_PATH, 'dataset_3rd_codon_numbers.nex')
expected = open(test_data_file, 'r').read()
result = dataset.dataset_str
self.assertEqual(expected.strip(), result)

def test_dataset_nexus_all_codon_positions_partitioned_by_codon_positions(self):
dataset = Dataset(test_data, format='NEXUS', codon_positions='ALL', partitioning='by codon position')
dataset = Dataset(self.test_data, format='NEXUS', codon_positions='ALL', partitioning='by codon position')
test_data_file = os.path.join(NEXUS_DATA_PATH, 'dataset_partitioned_as_each.nex')
expected = open(test_data_file, 'r').read()
result = dataset.dataset_str
self.assertEqual(expected.strip(), result)

def test_dataset_nexus_all_codon_positions_partitioned_as_1st2nd_3rd(self):
dataset = Dataset(test_data, format='NEXUS', codon_positions='ALL', partitioning='1st-2nd, 3rd')
dataset = Dataset(self.test_data, format='NEXUS', codon_positions='ALL', partitioning='1st-2nd, 3rd')
test_data_file = os.path.join(NEXUS_DATA_PATH, 'dataset_partitioned_as_1st2nd_3rd.nex')
expected = open(test_data_file, 'r').read()
result = dataset.dataset_str
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_degenerate(self):
self.assertEqual(expected, result)

def test_using_outgroup(self):
dataset = Dataset(test_data, format='NEXUS', codon_positions='ALL',
dataset = Dataset(self.test_data, format='NEXUS', codon_positions='ALL',
outgroup='CP100-19')
expected = 'outgroup CP100_19_Aus_jus;'
result = dataset.dataset_str
Expand Down
3 changes: 2 additions & 1 deletion tests/test_nexus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: UTF-8 -*-
from copy import copy
import json
import os

Expand Down Expand Up @@ -43,7 +44,7 @@ def get_test_data(type_of_data=None, filename="sample_data.txt"):
class TestNexus(unittest.TestCase):
def setUp(self):
self.maxDiff = None
self.seq_records = get_test_data('seq_records')
self.seq_records = copy(get_test_data('seq_records'))

def tearDown(self):
del self.seq_records
Expand Down

0 comments on commit 09fbd99

Please sign in to comment.