Skip to content

Commit

Permalink
update code documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
urmi-21 committed Jan 16, 2021
1 parent e5e5068 commit 7a70908
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 128 deletions.
36 changes: 33 additions & 3 deletions pyrpipe/__diagnostic__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@


def report():
"""
Entry point for report subcommand
Returns
-------
None.
"""

parser = argparse.ArgumentParser(

Expand Down Expand Up @@ -66,7 +74,14 @@ def report():


def shell():
print("Generating bash script")
"""
Entry point for shell command
Returns
-------
None.
"""
parser = argparse.ArgumentParser(

description='pyrpipe diagnostic utility\nGenerate shell script.',
Expand Down Expand Up @@ -101,7 +116,14 @@ def shell():


def benchmark():
print("Generating benchmarks")
"""
Entry point for benchmark subcommand
Returns
-------
None.
"""
parser = argparse.ArgumentParser(

description='pyrpipe diagnostic utility\nGenerate benchmark report.',
Expand Down Expand Up @@ -147,7 +169,15 @@ def benchmark():


def multiqc():
print("Generating html report with multiqc")
"""
Entry point for multiqc subcommand
Returns
-------
None.
"""

parser = argparse.ArgumentParser(

description='pyrpipe diagnostic utility\nGenerate report with multiqc.',
Expand Down
8 changes: 6 additions & 2 deletions pyrpipe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def init_envlog(self):

#read pyrpipe.conf in current dir
class Conf:
"""
Read and store pyrpipe configuration
"""
def __init__( self):
#init default values to use
self._dry = False
Expand Down Expand Up @@ -251,8 +254,8 @@ def init_sys_args(self):
There are multiple ways to execute a python script containing pyrpipe code
if infile is present implies invoked via pyrpipe command and control will go to the __main__ module
If infile is absent, it was invoked using python script.py command. In this case all pyrpipe options are read
if infile is present implies invoked via pyrpipe command, e.g. pyrpipe --in script.py, and control will go to the __main__ module
If infile is absent, it was invoked using python script.py command, e.g python script.py. In this case all pyrpipe options are read
and removed from the argv parameters so that passed argv are available to the script.py
"""
#if pyrpipe_diagnostic is invoked
Expand Down Expand Up @@ -316,6 +319,7 @@ def init_sys_args(self):
if pu.check_files_exist(s):
_optsmd5[s]=pu.get_mdf(s)

#this will be executed at then end of script
@atexit.register
def goodbye():
logfile=os.path.join(_logs_dir,_log_name+'.log')
Expand Down
33 changes: 5 additions & 28 deletions pyrpipe/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class Stringtie(Assembly):
threads: int
number of threads
guide: str
Reference annotation gtf/gff to use as guide
"""
def __init__(self,*args,threads=None,guide=None,**kwargs):
super().__init__(*args,**kwargs)
Expand All @@ -63,24 +66,12 @@ def perform_assembly(self,bam_file,out_dir=None,out_suffix="_stringtie",objectid
bam_file: string
path to the bam file
out_dir: string
Path to out file
out_suffix: string
Suffix for the output gtf file
reference_gtf: str
Path to the reference gtf used as guide
threads: int
Number of threads to use
overwrite: bool
Overwrite if output file already exists.
verbose: bool
Print stdout and std error
quiet: bool
Print nothing
logs: bool
Log this command to pyrpipe logs
objectid: str
Provide an id to attach with this command e.g. the SRR accession. This is useful for debugging, benchmarking and reports.
kwargs: dict
Options to pass to stringtie.
:return: Returns the path to output GTF file
:rtype: string
"""
Expand Down Expand Up @@ -143,22 +134,8 @@ def perform_assembly(self,bam_file,out_dir=None,out_suffix="_cufflinks",objectid
output directory
out_suffix: string
Suffix for the output gtf file
reference_gtf: str
Path to reference gtf
threads: int
Number of threads to use
overwrite: bool
Overwrite if output file already exists.
verbose: bool
Print stdout and std error
quiet: bool
Print nothing
logs: bool
Log this command to pyrpipe logs
objectid: str
Provide an id to attach with this command e.g. the SRR accession.
kwargs: dict
Options to pass to cufflinks.
:return: Returns the path to output GTF file
:rtype: string
Expand Down
2 changes: 1 addition & 1 deletion pyrpipe/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self,*args,index=None,genome=None,threads=None,**kwargs):
Raises
------
ValueError
Raises ValueError if hista index is not found and genome is not present to generate an index.
Raises ValueError if hisat index is not found and genome is not present to generate an index.
Returns
-------
Expand Down
11 changes: 6 additions & 5 deletions pyrpipe/param_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ def add_bool(self, node):
SafeConstructor.add_constructor(u'tag:yaml.org,2002:bool', add_bool)

class YAML_loader():
"""
Load parameters from a yaml file
"""


def __init__(self,file):
self.__params=None
self.__kwargs=None
self.__args=None

if not pu.check_files_exist(file):
return
Expand All @@ -42,7 +44,7 @@ def get_kwargs(self):

def parse_params(self):
"""
separate params into args and kwargs
store params as dict
"""
#if file is empty
if not self.__params:
Expand All @@ -62,10 +64,9 @@ def parse_params(self):
params[k]=str(v)

for k in to_del:
del params[k]

del params[k]

self.__kwargs=params
#self.__args=tuple(args)



11 changes: 7 additions & 4 deletions pyrpipe/pyrpipe_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#a decorator to skip functions in safe mode
def skippable(func):
"""
Skip a function execution
Skip a function execution in safemode
"""
if not _safe:
return func
Expand Down Expand Up @@ -83,7 +83,7 @@ def dried(cmd,*args,**kwargs):
def parse_cmd(cmd):
"""This function converts a list to str.
If a command is passed as list it is converted to str.
For pyrpipe v0.0.5 onwards the get_shell_output function uses shell=True
pyrpipe v0.0.5 onwards the get_shell_output function uses shell=True
"""
if isinstance(cmd,list):
return " ".join(cmd)
Expand All @@ -94,12 +94,15 @@ def parse_cmd(cmd):
def get_shell_output(cmd,verbose=None):
"""Function to run a shell command and return returncode, stdout and stderr
Currently (pyrpipe v 0.0.4) this function is called in
getReturnStatus(), getProgramVersion(), find_files()
get_return_status(), get_program_version()
pyrpipe v0.0.5 onwards the get_shell_output function uses shell=True
Parameters
----------
cdm: list
cdm: list or string
command to run
verbose: bool
to print messages
Expand Down
15 changes: 1 addition & 14 deletions pyrpipe/pyrpipe_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import dill
import datetime as dt
import os
#importing pyrpipe_engine here causes issues and stalling of log
#from pyrpipe import pyrpipe_engine as pre
#import pyrpipe

def getTimestamp(shorten=False):
"""Return timestamp YYYYMMDDHHMISE
Expand Down Expand Up @@ -40,17 +37,7 @@ def save_session(filename,add_timestamp=True,out_dir=""):
outFile=outFile+"_"+timestamp+".pyrpipe"
else:
outFile=outFile+".pyrpipe"

"""
Do not pickle logger. This causes problems when restoring session with python < 3.7
Delete all logger instances.
del pre.pyrpipeLoggerObject
del pyrpipe.pyrpipe_engine.pyrpipeLoggerObject
"""
"""
creating a logger class fixed this issue
"""



#save workspace
try:
Expand Down
18 changes: 18 additions & 0 deletions pyrpipe/pyrpipe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ def find_files(search_path,search_pattern,recursive=False,verbose=False):
-------
result : TYPE
DESCRIPTION.
Example
--------
find_files('path/to/directory','.*\.txt$',recursive=False,verbose=False)
"""

Expand Down Expand Up @@ -544,6 +548,20 @@ def find_files(search_path,search_pattern,recursive=False,verbose=False):


def get_mdf(filename):
"""
Compute and return md5checksum
Parameters
----------
filename : str
Path to input file
Returns
-------
md5 : str
MD5 checksum value
"""
if not check_files_exist(filename):
#print_boldred('Error calculating MD5. File {} not found'.format(filename))
return None
Expand Down
43 changes: 18 additions & 25 deletions pyrpipe/qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class Trimgalore(RNASeqQC):
Parameters
----------
args: tuple
arguments passed to trim_galore
threads: int
Num threads to use
kwargs:
trim_galore arguments.
"""
Expand Down Expand Up @@ -62,21 +65,11 @@ def perform_qc(self,sra_object,out_dir="",out_suffix="_trimgalore",objectid="NA"
Path to output directory
out_suffix: string
Suffix for the output sam file
threads: int
Num threads to use
verbose: bool
Print stdout and std error
quiet: bool
Print nothing
logs: bool
Log this command to pyrpipe logs
objectid: str
Provide an id to attach with this command e.g. the SRR accession. This is useful for debugging, benchmarking and reports.
kwargs: dict
Options to pass to trimgalore. This will override the existing options
:return: Returns the path of fastq files after QC. tuple has one item for single end files and two for paired.
:rtype: tuple
:return: Returns the path of fastq files after QC. tuple has one item for single end files and two for paired.
:rtype: tuple
"""
if not out_dir:
out_dir=sra_object.directory
Expand Down Expand Up @@ -203,6 +196,15 @@ def __init__(self,*args,threads=None,memory=None,**kwargs):
def perform_qc(self,sra_object,out_dir="",out_suffix="_bbduk",objectid="NA"):
"""Run bbduk on fastq files specified by the sra_object
sra_object: SRA
An SRA object whose fastq files will be used
out_dir: str
Path to output directory
out_suffix: string
Suffix for the output sam file
objectid: str
Provide an id to attach with this command e.g. the SRR accession. This is useful for debugging, benchmarking and reports.
:return: Returns the path of fastq files after QC. tuple has one item for single end files and 2 for paired.
:rtype: tuple
Expand Down Expand Up @@ -267,17 +269,8 @@ def perform_cleaning(self,sra_object,bbsplit_index,out_dir="",out_suffix="_bbspl
Path to output dir. Default: sra_object.directory
out_suffix: string
Suffix for output file name
overwrite: bool
overwrite existing files
verbose: bool
Print stdout and std error
quiet: bool
Print nothing
logs: bool
Log this command to pyrpipe logs
objectid: str
Provide an id to attach with this command e.g. the SRR accession. This is useful for debugging, benchmarking and reports.
Provide an id to attach with this command e.g. the SRR accession. This is useful for debugging, benchmarking and reports.
kwargs: dict
options passed to bbsplit
Expand Down Expand Up @@ -361,7 +354,7 @@ def perform_cleaning(self,sra_object,bbsplit_index,out_dir="",out_suffix="_bbspl
return("",)



#used by perform_cleaning
def run_bbsplit(self,objectid="NA",**kwargs):
"""wrapper to run bbsplit
Expand Down

0 comments on commit 7a70908

Please sign in to comment.