Skip to content

Commit

Permalink
removed additional codacy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam R. Rivers committed Dec 14, 2017
1 parent 0f0b5de commit 012a8d1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion tests/test_khmer_features.py
@@ -1,5 +1,4 @@
import vica
import khmer
import tempfile
import os
import filecmp
Expand Down
6 changes: 2 additions & 4 deletions vica/get_features.py
Expand Up @@ -2,16 +2,14 @@
"""prodigal.py: a module to call genes with prodigal then count codon usage
and transform into centered log ratio returning values as a CSV"""

import argparse

import tempfile
import os
import glob
import shutil
import logging
import time
import datetime

import pyfaidx
import yaml

import vica
Expand All @@ -30,7 +28,7 @@ def run(infile, output, label, minhashlocal=None, configpath=vica.CONFIG_PATH):
t0 = time.perf_counter()
# read config
with open(configpath) as cf:
config = yaml.load(cf)
config = yaml.safe_load(cf)
# Set up temp directory
if config["get_features"]["tempdir"]:
if not os.path.exists(config["get_features"]["tempdir"]):
Expand Down
7 changes: 3 additions & 4 deletions vica/train_eval.py
Expand Up @@ -12,7 +12,6 @@
import shutil

import yaml
import numpy as np
import tensorflow as tf
import csv
# from google.protobuf.json_format import MessageToDict
Expand Down Expand Up @@ -157,7 +156,7 @@ def train(infiles, out, modeldir, n_classes, configpath):
logging.exception("While exporting the model after tensorflow training the following exception occured:")


def eval(infiles, out, modeldir, n_classes, configpath):
def evaluate(infiles, out, modeldir, n_classes, configpath):
""" Main evaluation function called by vica_cli. Load a model from a model directory
returning a file of predictions. In the fiture it will have other evaluation datd.
Expand Down Expand Up @@ -197,10 +196,10 @@ def eval(infiles, out, modeldir, n_classes, configpath):
os.mkdir(out)
predictions = os.path.join(out, "modelpredictions.txt")
idlist = _ids_from_tfrecords(infile)
header = ["ID", "Class", "Class_id"] + ["Prob_class_" + str(i) for i in range(int(n_classes))]
csv_writer_instance.writerow(header)
with open(predictions, "w") as outfile:
csv_writer_instance = csv.writer(outfile, lineterminator='\n')
header = ["ID", "Class", "Class_id"] + ["Prob_class_" + str(i) for i in range(int(n_classes))]
csv_writer_instance.writerow(header)
for idrec, rec in zip(idlist,preds):
plist = rec['probabilities']
pliststr = [str(x) for x in plist]
Expand Down
7 changes: 4 additions & 3 deletions vica/vica_cli.py
Expand Up @@ -8,6 +8,7 @@
import os
import sys
import logging
import ast

import yaml

Expand Down Expand Up @@ -204,7 +205,7 @@ def main():
try:
with open(args.config) as cf:
global config
config = yaml.load(cf)
config = yaml.save_load(cf)
except:
print("Could not parse the configuration file.")
raise SystemExit(1)
Expand All @@ -230,7 +231,7 @@ def main():
n_per_class=args.n_per_class,
testfrac =args.testfrac,
splitlevel=args.level,
classes=eval(args.classes),
classes=ast.literal_eval(args.classes),
configpath = args.config)
elif args.whichmethod == 'get_features':
vica.get_features.run(infile=args.infile,
Expand All @@ -245,7 +246,7 @@ def main():
n_classes= args.n_classes,
configpath= args.config)
elif args.whichmethod == 'evaluate':
vica.train_eval.eval(infiles=args.infile,
vica.train_eval.evaluate(infiles=args.infile,
out= args.out,
modeldir= args.modeldir,
n_classes= args.n_classes,
Expand Down

0 comments on commit 012a8d1

Please sign in to comment.