diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 583932fc933fead43ef49d65b2543bd345cbb62a..f339b4e614cdaad772c6256a8f87db11a4842178 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ ========= CHANGELOG ========= +- 1.0.6 + No default output file, only stdout + + Fixing -e and -m behavior + - 1.0.5 Fix version date inside RPG diff --git a/docs/conf.py b/docs/conf.py index 11881614d72c1a9f259f4764a2301684e32bbb49..6c548c4ab8751ef92dde0b5f67483d598d1493f0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -26,7 +26,7 @@ author = 'Nicolas Maillet' # The short X.Y version version = '' # The full version, including alpha/beta/rc tags -release = '1.0.5' +release = '1.0.6' # -- General configuration --------------------------------------------------- diff --git a/rpg/RapidPeptidesGenerator.py b/rpg/RapidPeptidesGenerator.py index ac5b5da0ab53d827fe56c650a48e4cd5654b55fc..a8b1edc32bbaa083cfc65eba5a2c70d3ad4f5ce1 100644 --- a/rpg/RapidPeptidesGenerator.py +++ b/rpg/RapidPeptidesGenerator.py @@ -29,9 +29,9 @@ necessary functions """ -__version_info__ = ('1', '0', '5') +__version_info__ = ('1', '0', '6') __version__ = '.'.join(__version_info__) -__revision_date__ = "2018-07-13" +__revision_date__ = "2018-11-19" __author__ = "Nicolas Maillet" import argparse @@ -39,7 +39,7 @@ import os import sys import uuid from pathlib import Path -from context import rpg +#from context import rpg from rpg import core from rpg import digest from rpg import enzyme @@ -277,11 +277,10 @@ def main(): "overwritten.") group_output = parser.add_mutually_exclusive_group() group_output.add_argument("-o", "--outputfile", type=str, metavar="", - default="peptides", help="Result file to " - "output result peptides (default './peptides" - ".xxx' depending of --fmt)") + default="", help="Optional result file " + "to output result peptides.") group_output.add_argument("-r", "--randomname", action="store_true", - help="Random (not used) output name file") + help="Random (not used) output file name") group_verbose = parser.add_mutually_exclusive_group() group_verbose.add_argument("-q", "--quiet", action="store_true", help="No standard output, only error(s)") @@ -315,6 +314,7 @@ def main(): args.verbose = 0 # --outputfile / --randomname options + output_file = "" # No output file (default) if args.randomname: # Generate a random file name output_file = str(uuid.uuid4().hex) + "." + args.fmt @@ -322,8 +322,8 @@ def main(): while os.path.isfile(output_file): # Generate a random file name output_file = str(uuid.uuid4().hex) + "." + args.fmt - # Chosen file name - else: + # Chosen file name if exist + elif args.outputfile: # Given name tmpname = str(args.outputfile) # No extension? @@ -366,7 +366,8 @@ def main(): print("Mode: " + mode) print("miscleavage ratio: " + str([enz.ratio_miscleavage for enz in enzymes_to_use])) - print("Output file: " + os.path.abspath(output_file)) + if output_file: + print("Output file: " + os.path.abspath(output_file)) # Make the actual digestion of input data results_digestion = digest.digest_from_input(args.inputdata, diff --git a/rpg/core.py b/rpg/core.py index 046d6b9bbda9a5ae43502e56c05a1f3bf079b2b9..8c3b0ddba69fdc90846133df28f491e1c4d5671c 100644 --- a/rpg/core.py +++ b/rpg/core.py @@ -138,7 +138,7 @@ def get_header(fmt="fasta"): def output_results(output_file, all_seq_digested, fmt, quiet, verbose): """Output results of digestion in file and optionally in `stdout`. - :param output_file: the file where to print results + :param output_file: the file where to print results, if exist :param all_seq_digested: results of digestions :param fmt: output format (`csv`, `tsv` or `fasta`) :param quiet: quiet mode, no `stdout` message @@ -150,32 +150,56 @@ def output_results(output_file, all_seq_digested, fmt, quiet, verbose): :type verbose: int """ - # Open output file - try: - with open(output_file, 'w') as outfile: - # Header - header = get_header(fmt) - # If we have a header to print (csv/tsv) - if header: - # Print it in file - outfile.write(header + "\n") - # Stdout if small verbose - if verbose < 2 and not quiet: - print(header) - # Print all peptides - for one_seq in all_seq_digested: # list of list of ResultOneDig - # For all ResultOneDigestion - for one_enz_res in one_seq: - # Print results in file - outfile.write(format(one_enz_res, fmt)) - # Print on stdout - if verbose >= 2: - # Big verbose - print(one_enz_res.get_more_info()) - if header: - print(header) - # Default stdout - if not quiet: - print(format(one_enz_res, fmt), end='') - except IOError: - handle_errors(output_file + " can't be open in 'w' mode", 0, "File ") + # Not output file + if not output_file: + # Header + header = get_header(fmt) + # If we have a header to print (csv/tsv) + if header: + # Stdout if small verbose + if verbose < 2 and not quiet: + print(header) + # Print all peptides + for one_seq in all_seq_digested: # list of list of ResultOneDig + # For all ResultOneDigestion + for one_enz_res in one_seq: + # Print on stdout + if verbose >= 2: + # Big verbose + print(one_enz_res.get_more_info()) + if header: + print(header) + # Default stdout + if not quiet: + print(format(one_enz_res, fmt), end='') + # Output file exist + else: + try: + with open(output_file, 'w') as outfile: + # Header + header = get_header(fmt) + # If we have a header to print (csv/tsv) + if header: + # Print it in file + outfile.write(header + "\n") + # Stdout if small verbose + if verbose < 2 and not quiet: + print(header) + # Print all peptides + for one_seq in all_seq_digested: # list of list of ResultOneDi + # For all ResultOneDigestion + for one_enz_res in one_seq: + # Print results in file + outfile.write(format(one_enz_res, fmt)) + # Print on stdout + if verbose >= 2: + # Big verbose + print(one_enz_res.get_more_info()) + if header: + print(header) + # Default stdout + if not quiet: + print(format(one_enz_res, fmt), end='') + except IOError: + handle_errors(output_file + " can't be open in 'w' mode", 0, + "File ") diff --git a/setup.py b/setup.py index 9e5dc87894a22c32a9b4fe689d6aef5a89b94415..ec9795783162e92b307e92d481b85c3b70e4ea88 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup, find_packages _MAJOR = 1 _MINOR = 0 -_MICRO = 5 +_MICRO = 6 version = '%d.%d.%d' % (_MAJOR, _MINOR, _MICRO) release = '%d.%d' % (_MAJOR, _MINOR)