Commit 51691249 authored by Nicolas  MAILLET's avatar Nicolas MAILLET
Browse files

Remove default output file, now it is stdout

parent 5f142911
Pipeline #7746 passed with stages
in 2 minutes and 10 seconds
=========
CHANGELOG
=========
- 1.0.6
No default output file, only stdout
Fixing -e and -m behavior
- 1.0.5
Fix version date inside RPG
......
......@@ -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 ---------------------------------------------------
......
......@@ -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,
......
......@@ -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 ")
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment