Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
urmi-21 committed Jan 15, 2020
1 parent 1f2b8b1 commit fa249d1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 36 deletions.
30 changes: 18 additions & 12 deletions pyrpipe/pyrpipe_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PyrpipeLogger():
Attributes
-----------
env_logger: logger to log the current environment
cmd_logger: logger to log the execution status, stdout, stderr and runtimes for each command run using execute_command()
"""
Expand Down Expand Up @@ -101,18 +102,19 @@ def __init__(self):

def create_logger(self,name,logfile,formatter,level=logging.DEBUG):
"""Creates a logger
Parameters
----------
name: str
name of logger
logfile: str
file name to save logs
formatter: formatter object
formatter for log
Returns
-------
logger
Returns: logger
A logger object
"""
#Get different loggers
handler = logging.FileHandler(logfile)
Expand Down Expand Up @@ -184,12 +186,13 @@ def getShellOutput(cmd,verbose=False):
Parameters
----------
cdm: list
command to run
verbose: bool
to print messages
:return: returncode, stdout and stderr
:return: (returncode, stdout and stderr)
:rtype: tuple
"""
#not logging these commands
Expand All @@ -206,8 +209,10 @@ def getShellOutput(cmd,verbose=False):
def getReturnStatus(cmd):
"""
run a shell command and get the return status
Parameters
----------
cmd: list
shell command in list
Expand Down Expand Up @@ -245,6 +250,7 @@ def execute_command(cmd,verbose=False,quiet=False,logs=True,objectid="NA",comman
Parameters
----------
cmd: list
command to execute via popen in a list
verbose: bool
Expand Down Expand Up @@ -380,10 +386,12 @@ def is_paired(sra_file):
Parameters
----------
sra_file (string) the path ro sra file
Returns
-------
bool: True is sra is paired
:return: True is sra is paired
:rtype: bool
"""
if not pu.check_files_exist(sra_file):
raise Exception("Error checking layout. {0} doesn't exist".format(sra_file));
Expand Down Expand Up @@ -431,6 +439,7 @@ def check_dependencies(dependencies):
Parameters
----------
dependencies: list
list of programs to test
Expand Down Expand Up @@ -491,8 +500,10 @@ def move_file(source,destination):
def find_files(search_path,search_pattern,recursive=False,verbose=False):
"""Function to find files using find command and return as list
Use global paths for safety
Parameters
----------
search_path: str
path to search under
search_pattern: str
Expand Down Expand Up @@ -521,9 +532,4 @@ def find_files(search_path,search_pattern,recursive=False,verbose=False):



if __name__ == "__main__":
print ("Logger")
print(os.getcwd())
print(find_files("../","*.py"))


3 changes: 3 additions & 0 deletions pyrpipe/pyrpipe_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def save_session(filename,add_timestamp=True,out_dir=""):

def restore_session(file):
"""Resore a session from file.
:return: Returns True if session is restored
:rtype: bool
"""
if not os.path.isfile(file):
print(file+" doesn't exist")
Expand Down
74 changes: 50 additions & 24 deletions pyrpipe/pyrpipe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,86 +30,89 @@ class Colors:

def print_boldred(text):
"""Print in bold red font
Parameters
----------
text: str
text to print
Returns
--------
None
Returns: None
"""
print (Colors.FAIL + Colors.BOLD+ text + Colors.ENDC)

def print_green(text):
"""Print in green font
Parameters
----------
text: str
text to print
Returns
--------
None
Returns: None
"""
print (Colors.OKGREEN + text + Colors.ENDC)

def print_blue(text):
"""Print in blue font
Parameters
----------
text: str
text to print
Returns
--------
None
Returns: None
"""
print (Colors.OKBLUE + text + Colors.ENDC)

def print_magenta(text):
"""Print in magenta font
Parameters
----------
text(str): text to print
Returns
--------
None
Returns: None
"""
print (Colors.LightMagenta + text + Colors.ENDC)

def print_info(text):
"""Print an info message
Parameters
----------
text: str
text to print
Returns
--------
None
Returns: None
"""
print_magenta(text)

def print_yellow(text):
"""Print in yellow font
Parameters
----------
text: str
text to print
Returns
--------
None
Returns: None
"""
print (Colors.LightYellow + text + Colors.ENDC)

######End color functions###################

def get_time_stamp(shorten=False):
"""Function to return current timestamp.
Parameters
----------
shorten: bool
return short version without space, dash and colons
Expand Down Expand Up @@ -141,6 +144,7 @@ def check_paths_exist(*args):
Parametrs
---------
args: tuple
a list of paths to check
Expand All @@ -161,6 +165,7 @@ def check_files_exist(*args):
Parametrs
---------
args: tuple
a list of paths to check
Expand All @@ -179,8 +184,10 @@ def check_files_exist(*args):

def check_hisatindex(index):
"""Function to check if hisat2 index is valid and exists.
Parameters
----------
index: str
Path to the index
Expand All @@ -191,8 +198,10 @@ def check_hisatindex(index):

def check_salmonindex(index):
"""Function to check if salmon index is valid and exists.
Parameters
----------
index: str
Path to the index
Expand All @@ -205,8 +214,10 @@ def check_salmonindex(index):

def check_starindex(index):
"""Function to check if star index is valid and exists.
Parameters
----------
index: str
Path to the index
Expand All @@ -229,8 +240,10 @@ def check_starindex(index):

def check_bowtie2index(index):
"""Function to check if bowtie2 index is valid and exists.
Parameters
----------
index: str
Path to the index
Expand All @@ -242,8 +255,10 @@ def check_bowtie2index(index):

def byte_to_readable(size_bytes):
"""Function to convert bytes to human readable format (MB,GB ...)
Parameters
----------
size_bytes: float
size in bytes
Expand All @@ -259,8 +274,10 @@ def byte_to_readable(size_bytes):

def get_file_size(file_path):
"""Returns file size in human readable format
Parameters
----------
file_path: str
Path to file
Expand All @@ -277,8 +294,10 @@ def get_file_size(file_path):
def parse_java_args(valid_args_list,passed_args):
"""
Function creates arguments to pass to java programs
Parameters
----------
valid_args_list: list
list of valid arguments. Invalid arguments will be ignored
passed_args: *dict
Expand Down Expand Up @@ -323,8 +342,10 @@ def parse_java_args(valid_args_list,passed_args):

def parse_unix_args(valid_args_list,passed_args):
"""Function creates command line arguments to pass to unix programs
Parameters
----------
valid_args_list: list
list of valid arguments. Invalid arguments will be ignored
passed_args: *dict
Expand Down Expand Up @@ -382,8 +403,10 @@ def parse_unix_args(valid_args_list,passed_args):

def get_file_directory(file_path):
"""Returns directory of a file
Parameters
----------
file_path: str
Path to file
Expand All @@ -394,8 +417,10 @@ def get_file_directory(file_path):

def get_filename(file_path):
"""Returns filename with extension
Parameters
----------
file_path: str
Path to file
Expand All @@ -406,8 +431,10 @@ def get_filename(file_path):

def get_fileext(file_path):
"""Returns file extension
Parameters
----------
file_path: str
Path to file
Expand All @@ -418,8 +445,10 @@ def get_fileext(file_path):

def get_file_basename(file_path):
"""Returns file basename without extension
Parameters
----------
file_path: str
Path to file
Expand Down Expand Up @@ -451,10 +480,7 @@ def get_union(*args):
"""
return list(set().union(*args))

def scan_SRA_dir(path):
pass
#def scan_SRA_dir(path):
# pass


if __name__ == "__main__":
print("main")
#print(parse_unix_style_args(['-O','-t','-q'], {"-O": "./test", "Attr2": "XX","--":("IN1","IN2")}))
print(parse_java_args(['A','B','-C'], {"A": "3", "B": "22","-C":"","--":("-Xmx2g","-da",)}))

0 comments on commit fa249d1

Please sign in to comment.