Skip to content

Commit 1c1bf90

Browse files
authored
Merge pull request #167 from datasnakes/codecov
Migrate to pytest and implement code coverage.
2 parents 93bb265 + 3305c50 commit 1c1bf90

File tree

9 files changed

+70
-40
lines changed

9 files changed

+70
-40
lines changed

.coveragerc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[run]
2-
source=OrthoEvol
2+
source=OrthoEvol
3+
disable_warnings = couldnt-parse

.travis.yml

+39-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
language: python
2-
dist: xenial
32
os: linux
43
cache: pip
5-
python:
6-
- "3.5"
7-
- "3.6"
8-
- "3.7"
9-
- "3.8"
104
notifications:
115
12-
# command to install dependencies
13-
install:
14-
- "pip install --upgrade pip setuptools wheel"
15-
- "pip install --only-binary=numpy,scipy numpy scipy"
16-
- "pip install matplotlib ipython jupyter sympy pytest"
17-
- "pip install -r requirements.txt"
18-
- "pip install ."
19-
# command to run unittests via pytest
6+
jobs:
7+
include:
8+
- python: 3.5
9+
dist: trusty
10+
install:
11+
- pip install --upgrade pip setuptools wheel
12+
- pip install --only-binary=numpy,scipy numpy scipy
13+
- pip install matplotlib ipython jupyter sympy pytest codecov "pytest-cov<=2.6.0"
14+
- pip install -r requirements.txt
15+
- pip install .
16+
- python: 3.6
17+
dist: xenial
18+
install:
19+
- pip install --upgrade pip setuptools wheel
20+
- pip install --only-binary=numpy,scipy numpy scipy
21+
- pip install matplotlib ipython jupyter sympy pytest codecov pytest-cov
22+
- pip install -r requirements.txt
23+
- pip install .
24+
- python: 3.7
25+
dist: xenial
26+
install:
27+
- pip install --upgrade pip setuptools wheel
28+
- pip install --only-binary=numpy,scipy numpy scipy
29+
- pip install matplotlib ipython jupyter sympy pytest codecov pytest-cov
30+
- pip install -r requirements.txt
31+
- pip install .
32+
- python: 3.8
33+
dist: xenial
34+
install:
35+
- pip install --upgrade pip setuptools wheel
36+
- pip install --only-binary=numpy,scipy numpy scipy
37+
- pip install matplotlib ipython jupyter sympy pytest codecov pytest-cov
38+
- pip install -r requirements.txt
39+
- pip install .
40+
# command to run unittests
2041
script:
21-
- pytest tests/
42+
- pytest --cov-report=xml --cov=OrthoEvol tests/
43+
# upload code coverage
44+
after_success:
45+
- codecov

OrthoEvol/Orthologs/Align/msa.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ def guidance2(self, seqFile, msaProgram, seqType, dataset='MSA', seqFilter=None,
108108
gene = Path(seqFile).stem
109109
geneDir = self.raw_data / Path(gene)
110110
self.guidancelog.info(geneDir)
111-
if seqType is 'nuc':
111+
if seqType == 'nuc':
112112
g2_seqFile = str(geneDir / Path(gene + '_G2.ffn')) # Need for all iterations
113113
rem_file = str(geneDir / Path(gene + '_G2_removed.ffn')) # Need for all iterations
114114
g2_alnFile = str(geneDir / Path(gene + '_G2_na.aln'))
115115
g2_seqcolFilter = str(geneDir / Path(gene + 'G2sfcf_na.aln'))
116116
g2_colFilter = str(geneDir / Path(gene + '_G2cf_na.aln'))
117117
g2_maskedFile = str(geneDir / Path(gene + '_G2mf_na.aln'))
118-
elif seqType is 'aa':
118+
elif seqType == 'aa':
119119
g2_seqFile = str(geneDir / Path(gene + '_G2.faa')) # Need for all iterations
120120
rem_file = str(geneDir / Path(gene + '_G2_removed.faa')) # Need for all iterations
121121
g2_alnFile = str(geneDir / Path(gene + '_G2_aa.aln'))
@@ -176,9 +176,9 @@ def guidance2(self, seqFile, msaProgram, seqType, dataset='MSA', seqFilter=None,
176176
elif set_iter >= iteration > 1:
177177

178178
# Depending on the filter strategy increment the seqCutoff
179-
if seqFilter is "inclusive":
179+
if seqFilter == "inclusive":
180180
kwargs['seqCutoff'] -= kwargs['increment']
181-
elif seqFilter is "exclusive":
181+
elif seqFilter == "exclusive":
182182
kwargs['seqCutoff'] += kwargs['increment']
183183
# seqFile changes to g2_seqFile and the cutoffs change
184184
G2Cmd = Guidance2Commandline(seqFile=g2_seqFile, msaProgram=msaProgram, seqType=seqType,

OrthoEvol/Orthologs/GenBank/genbank.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def name_fasta_file(self, path, gene, org, feat_type,
9494
# Create path variables. (typically raw_data/<gene>/GENBANK
9595
feat_path = path
9696
# Create a format-able string for file names
97-
if feat_type_rank is "CDS":
97+
if feat_type_rank == "CDS":
9898
single = '%s_%s%s%s'
9999
multi = '%s%s%s'
100100
else:
@@ -406,7 +406,7 @@ def get_fasta_files(self, acc_dict, db=True):
406406
for _, _, gbk_files in os.walk(str(self.target_gbk_files_path)):
407407
# For each genbank record write a set of FASTA files.
408408
for gbk_file in gbk_files:
409-
if Path(gbk_file).suffix is '.gbk':
409+
if Path(gbk_file).suffix == '.gbk':
410410
record = SeqIO.read(gbk_file, 'genbank')
411411
self.write_fasta_files(record, acc_dict)
412412
self.genbanklog.info("FASTA files for %s created." % gbk_file)

OrthoEvol/Tools/logit/logit.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ def custom(cls, logname, logfile, level, fmt='default'):
5353
:return: A custom_log object is returned.
5454
"""
5555

56-
if fmt is 'default':
56+
if fmt == 'default':
5757
fmt = '[%(levelname)-2s - %(name)s]: %(message)s'
58-
elif fmt is 'custom':
58+
elif fmt == 'custom':
5959
# TODO Allow customization
6060
raise NotImplementedError('Feature not integrated yet!')
61-
elif fmt is not 'default' or 'custom':
61+
elif fmt != 'default' or 'custom':
6262
raise Exception('User did not provide a format for the logger.')
6363

6464
custom_log = setup_logger(name=logname, logfile=logfile,

OrthoEvol/Tools/slackify/notify.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, slackconfig='slackconfig.cfg', cfg=True):
1919
# Use False if you did not create a config file
2020
if not cfg:
2121
apikey = input('Insert your slack apikey here: ')
22-
if len(apikey) is not 42: # Standard length of slack apikey
22+
if len(apikey) != 42: # Standard length of slack apikey
2323
raise ValueError('Your slack APIKEY is incorrect.')
2424

2525
slack = Slacker(apikey)

OrthoEvol/utilities.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# Set up logging
2929
blastutils_log = LogIt().default(logname="blast-utils", logfile=None)
3030
seqidlist_log = LogIt().default(logname="gi-lists", logfile=None)
31+
utils_log = LogIt().default(logname="utils", logfile=None)
3132
_datefmt = '%I:%M:%S %p on %m-%d-%Y'
3233
_date = str(datetime.now().strftime(_datefmt))
3334

@@ -445,17 +446,17 @@ def multi_fasta_manipulator(self, target_file, man_file, output_file,
445446
# Create a new multi-fasta record object using the target_file,
446447
# reference, and output
447448
# Remove specific sequences from a fasta file
448-
if manipulation is 'remove':
449+
if manipulation == 'remove':
449450
self.multi_fasta_remove(target_file, man_file, new_file)
450451
# Combine all the FASTA sequence in one record object
451-
elif manipulation is 'add':
452+
elif manipulation == 'add':
452453
self.muli_fasta_add(target_file, man_file, new_file)
453454
# Sort one fasta file based on the order of another
454455
# Works for alignments
455-
elif manipulation is 'sort':
456+
elif manipulation == 'sort':
456457
self.multi_fasta_sort(target_file, man_file, new_file)
457458

458-
print('A new fasta file has been created.')
459+
utils_log.info('A new fasta file has been created.')
459460
return new_file
460461

461462
# def dir_config(path, tier_frame_dict):
@@ -505,7 +506,7 @@ def multi_fasta_remove(self, target_file, man_file, output_file):
505506
target_file,
506507
'fasta') if record.id in ids)
507508

508-
print('Sequences have been filtered.')
509+
utils_log.info('Sequences have been filtered.')
509510
SeqIO.write(new_records, str(output_file), 'fasta')
510511
SeqIO.write(old_records, str(rem_file), 'fasta')
511512

@@ -532,11 +533,11 @@ def muli_fasta_add(self, target_file, man_file, output_file):
532533
target_file, 'fasta', ), SeqIO.parse(man_file, 'fasta'))
533534
count = SeqIO.write(new_records, tmp_file, 'fasta')
534535
tmp_file.seek(0)
535-
print('temp file count: ' + str(count))
536+
utils_log.info('temp file count: ' + str(count))
536537
SeqIO.write(SeqIO.parse(tmp_file, 'fasta'), str(output_file), 'fasta')
537-
print('Sequences have been added.')
538+
utils_log.info('Sequences have been added.')
538539
else:
539-
print('You can only add files together. Not python objects.')
540+
utils_log.warning('You can only add files together. Not python objects.')
540541

541542
def multi_fasta_sort(self, target_file, man_file, output_file):
542543
"""Sorts selected reference sequences in a multi-FASTA files.
@@ -569,15 +570,15 @@ def multi_fasta_sort(self, target_file, man_file, output_file):
569570
for unsorted_aln_record in SeqIO.parse(target_file, 'fasta'):
570571
# If an appropriate id is found, then append to the MSA object.
571572
if unsorted_aln_record.id == sorted_seq_record.id:
572-
print(unsorted_aln_record.id)
573-
print(sorted_seq_record.id)
573+
utils_log.info(unsorted_aln_record.id)
574+
utils_log.info(sorted_seq_record.id)
574575
aln.append(unsorted_aln_record) # MSA object
575576
break
576577
count = AlignIO.write(aln, tmp_file, 'fasta')
577578
tmp_file.seek(0)
578-
print('temp file count: ' + str(count))
579+
utils_log.info('temp file count: ' + str(count))
579580
AlignIO.write(AlignIO.read(tmp_file, 'fasta'), str(output_file), 'fasta')
580-
print('Alignment has been sorted.')
581+
utils_log.info('Alignment has been sorted.')
581582

582583

583584
class OrthologUtils(BlastUtils, GenbankUtils):
@@ -877,7 +878,7 @@ def __init__(self, packagename):
877878
def _getversion(self):
878879
import_module(self.packagename)
879880
version = pkg_resources.get_distribution(self.packagename).version
880-
print('Version %s of %s is installed.' % (version, self.packagename))
881+
utils_log.info('Version %s of %s is installed.' % (version, self.packagename))
881882

882883

883884
class FunctionRepeater(object):
@@ -933,7 +934,7 @@ def system_cmd(self, cmd, timeout=None, print_flag=True,
933934
for line in iter(proc.stdout.readline, ""):
934935
stdout_list.append(line.rstrip())
935936
if print_flag:
936-
print(line, end="")
937+
utils_log.info(line, end="")
937938
sys.stdout.flush()
938939
if write_flag:
939940
with open(file_name, 'a') as output_file:

pytest.ini

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
addopts = -ra -q
3+
testpaths =
4+
tests

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)