Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from moka-guys/development
Browse files Browse the repository at this point in the history
Update wscleaner logfile count and use local nexus auth file
  • Loading branch information
Aled Jones authored Apr 3, 2020
2 parents 4ad2abd + 16948a9 commit 8df0aa6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 99 deletions.
4 changes: 2 additions & 2 deletions wscleaner/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

setup(name='wscleaner',
version='1.0',
version='1.1',
description='Package to remove uploaded runfolders from \
the Viapath Genome Informatics NGS workstation',
url='https://github.com/NMNS93/wscleaner',
Expand All @@ -13,7 +13,7 @@

python_requires = '>=3.6.8',
install_requires = ['docutils>=0.3', 'dxpy==0.279.0', 'pytest==4.4.0', 'pytest-cov==2.6.1',
'Sphinx==2.0.1', 'psutil==5.6.1'],
'Sphinx==2.0.1'],

package_data = {},

Expand Down
83 changes: 0 additions & 83 deletions wscleaner/wscleaner/auth.py

This file was deleted.

4 changes: 2 additions & 2 deletions wscleaner/wscleaner/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ def check_fastqs(self, runfolder):
self.logger.debug(f'{runfolder.name} FASTQ BOOL: {fastq_bool}')
return fastq_bool

def check_logfiles(self, runfolder):
def check_logfiles(self, runfolder, logfile_count):
"""Returns true if a runfolder's DNAnexus project contains 6 logfiles in the
expected location"""
dx_logfiles = runfolder.dx_project.count_logfiles()
logfile_bool = dx_logfiles >= 6
logfile_bool = (dx_logfiles == logfile_count)
self.logger.debug(f'{runfolder.name} LOGFILE BOOL: {logfile_bool}')
return logfile_bool

Expand Down
21 changes: 9 additions & 12 deletions wscleaner/wscleaner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import argparse
import logging
import pkg_resources
import dxpy
from wscleaner import mokaguys_logger
from wscleaner.auth import SetKeyAction, PrintKeyAction, dx_set_auth
from wscleaner.lib import RunFolder, RunFolderManager


Expand All @@ -24,17 +24,12 @@ def cli_parser():
Otherwise, --set-key and --print-key exit after actions are performed.
"""
parser = argparse.ArgumentParser()
# argparse API for adding custom routines. SetKeyAction and PrintKeyAction are classes with
# routines that exit the software after an action is performed.
parser.register('action', 'setkey', SetKeyAction)
parser.register('action', 'printkey', PrintKeyAction)
# Define CLI arguments
parser.add_argument('--set-key', action='setkey', help='Cache a DNA Nexus API key')
parser.add_argument('--print-key', nargs=0, action='printkey', help='Print the cached DNA Nexus API key')
parser.add_argument('--auth', help='A text file containing the DNANexus authentication token', type=str, default='/usr/local/src/mokaguys/.dnanexus_auth_token')
parser.add_argument('--dry-run', help='Perform a dry run without deleting files', action='store_true', default=False)
parser.add_argument('root', help='A directory containing runfolders to process')
parser.add_argument('--logfile', help='A path for the application logfile', default='mokaguys_logger.log')
parser.add_argument('--min-age', help='The age (days) a runfolder must be to be deleted', type=int, default=14)
parser.add_argument('--logfile-count', help='The number of logfiles a runfolder must have in /Logfiles', type=int, default=5)
# Get version from setup.py as version CLI response
version_number = pkg_resources.require("wscleaner")[0].version
parser.add_argument('--version', help='Print version', action='version', version=f"wscleaner v{version_number}")
Expand All @@ -50,8 +45,10 @@ def main():
logger = logging.getLogger(__name__)
logger.info(f'START')

# Setup dxpy with cached authentication token
dx_set_auth()
# Setup dxpy authentication token read from command line file.
with open(args.auth) as f:
auth_token = f.read().rstrip()
dxpy.set_security_context({'auth_token_type': 'Bearer', 'auth_token': auth_token})

# Set root directory and search it for runfolders
# If dry-run CLI flag is given, no directories are deleted by the runfolder manager.
Expand All @@ -66,7 +63,7 @@ def main():
# runfolder.dx_project is evaluated first as following criteria checks depend on it
if runfolder.dx_project:
fastqs_uploaded = RFM.check_fastqs(runfolder)
logfiles_uploaded = RFM.check_logfiles(runfolder)
logfiles_uploaded = RFM.check_logfiles(runfolder, args.logfile_count)
if fastqs_uploaded and logfiles_uploaded:
RFM.delete(runfolder)
elif not fastqs_uploaded:
Expand All @@ -83,4 +80,4 @@ def main():


if __name__ == '__main__':
main()
main()
12 changes: 12 additions & 0 deletions wscleaner/wscleaner_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Activate wscleaner environment
eval "$(/usr/local/bin/miniconda3/bin/conda shell.bash hook)" # Add conda environment to system path
conda activate wscleaner

# Set variables
logfile="/home/mokaguys/Documents/automate_demultiplexing_logfiles/wscleaner_logs/$(date -d now +%y%m%d)_wscleaner.log"
runfolders="/media/data3/share"

# Execute
wscleaner $runfolders --logfile $logfile

0 comments on commit 8df0aa6

Please sign in to comment.