-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
329 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,3 +100,10 @@ ENV/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# Macbook | ||
.DS_Store | ||
|
||
#VScode | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,126 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Console script for merge_fastq.""" | ||
import os | ||
import sys | ||
import click | ||
import logging | ||
import time | ||
import pathlib | ||
try: | ||
import click | ||
except ImportError as e: | ||
print( | ||
"cli: click is not installed, please install click as it is one of the requirements. \n", e | ||
) | ||
exit(1) | ||
try: | ||
import click_log | ||
except ImportError as e: | ||
print( | ||
"cli: click-log is not installed, please install click_log as it is one of the requirements.\n", e | ||
) | ||
exit(1) | ||
try: | ||
import merge_fastq.merge_fastq as mf | ||
except ImportError as e: | ||
print( | ||
"cli: merge_fastq module could not be loaded, please install package correctly to get this running. \n", e | ||
) | ||
exit(1) | ||
|
||
""" | ||
cli | ||
~~~~~~~~~~~~~~~ | ||
:Description: console script for running merge_fastq | ||
""" | ||
""" | ||
Created on October 10, 2019 | ||
Description: console script for running merge_fastq | ||
@author: Ronak H Shah | ||
""" | ||
|
||
version = None | ||
scriptpath = os.path.realpath(__file__) | ||
p_scriptpath = pathlib.Path(scriptpath) | ||
with open(os.path.join(p_scriptpath.parent, "__init__.py"), "r") as f: | ||
for line in f.readlines(): | ||
line = line.strip() | ||
if line.startswith("__version__"): | ||
version = line.split("=")[-1].strip() | ||
__all__ = [] | ||
__version__ = version | ||
__date__ = "2019-10-21" | ||
__updated__ = "2019-10-21" | ||
# Making logging possible | ||
logger = logging.getLogger("merge_fastq") | ||
click_log.basic_config(logger) | ||
click_log.ColorFormatter.colors["info"] = dict(fg="green") | ||
|
||
|
||
@click.command() | ||
def main(args=None): | ||
@click.option( | ||
"--fastq1", | ||
"-fp1", | ||
required=True, | ||
multiple=True, | ||
type=click.Path(exists=True), | ||
help="Full path to gziped READ1 fastq files, can be specified multiple times for example: --fastq1 test_part1_R1.fastq.gz --fastq1 test_part2_R1.fastq.gz", | ||
) | ||
@click.option( | ||
"--fastq2", | ||
"-fp2", | ||
required=True, | ||
multiple=True, | ||
type=click.Path(exists=True), | ||
help="Full path to gziped READ2 fastq files, can be specified multiple times for example: --fastq2 test_part1_R2.fastq.gz --fastq2 test_part2_R2.fastq.gz", | ||
) | ||
@click.option( | ||
"--output-path", | ||
"-op", | ||
required=False, | ||
default=os.getcwd(), | ||
type=click.Path(exists=True), | ||
help="Full path to write the output files (default: Current working directory)", | ||
) | ||
@click.option( | ||
"--out-fastq1", | ||
"-of1", | ||
required=False, | ||
default="merged_fastq_R1.fastq.gz", | ||
type=click.STRING, | ||
help="Name of the merged output READ1 fastq file (default: merged_fastq_R1.fastq.gz)", | ||
) | ||
@click.option( | ||
"--out-fastq2", | ||
"-of2", | ||
required=False, | ||
default="merged_fastq_R2.fastq.gz", | ||
type=click.STRING, | ||
help="Name of the merged output READ2 fastq file (default: merged_fastq_R2.fastq.gz)", | ||
) | ||
def main(fastq1, fastq2, output_path, out_fastq1, out_fastq2): | ||
"""Console script for merge_fastq.""" | ||
click.echo("Replace this message by putting your code into " | ||
"merge_fastq.cli.main") | ||
click.echo("See click documentation at https://click.palletsprojects.com/") | ||
logger_output = os.path.join(output_path, "merge_fastq.log") | ||
fh = logging.FileHandler(logger_output) | ||
formatter = logging.Formatter( | ||
fmt="%(asctime)s - %(name)s - %(levelname)s - %(message)s", | ||
datefmt="%m/%d/%Y %I:%M:%S %p", | ||
) | ||
fh.setFormatter(formatter) | ||
logger.addHandler(fh) | ||
logger.info("==================================================") | ||
logger.info(">>> Running merge_fastq for <<<") | ||
logger.info("==================================================") | ||
t1_start = time.perf_counter() | ||
t2_start = time.process_time() | ||
mf.run(fastq1, fastq2, output_path, out_fastq1, out_fastq2) | ||
t1_stop = time.perf_counter() | ||
t2_stop = time.process_time() | ||
logger.info("--------------------------------------------------") | ||
logger.info("Elapsed time: %.1f [min]" % ((t1_stop - t1_start) / 60)) | ||
logger.info("CPU process time: %.1f [min]" % ((t2_stop - t2_start) / 60)) | ||
logger.info("--------------------------------------------------") | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) # pragma: no cover | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Main module.""" | ||
import os | ||
import logging | ||
import shutil | ||
|
||
""" | ||
merge_fastq | ||
~~~~~~~~~~~~~~~ | ||
:Description: main module for merge_fastq | ||
""" | ||
""" | ||
Created on October 21, 2019 | ||
Description: main module for merge_fastq | ||
@author: Ronak H Shah | ||
""" | ||
|
||
# Making logging possible | ||
logger = logging.getLogger("merge_fastq") | ||
|
||
|
||
def run(fastq1, fastq2, output_path, out_fastq1, out_fastq2): | ||
out_file1 = os.path.join(output_path, out_fastq1) | ||
out_file2 = os.path.join(output_path, out_fastq2) | ||
if(len(fastq1) == len(fastq2)): | ||
if len(fastq1) == 1: | ||
try: | ||
shutil.copyfile(fastq1[0], out_file1) | ||
except IOError as e: | ||
logging.error( | ||
"Could not copy file %s to %s, please see the execution error. \n %s \n", fastq1[0], out_file1, e) | ||
exit(1) | ||
try: | ||
shutil.copyfile(fastq2[0], out_file2) | ||
except IOError as e: | ||
logging.error( | ||
"Could not copy file %s to %s, please see the execution error. \n %s \n", fastq2[0], out_file2, e) | ||
exit(1) | ||
else: | ||
merge_fastq(fastq1, fastq2, out_file1, out_file2) | ||
logging.info("Done merging fastq file in %s and %s", out_file1, out_file2) | ||
|
||
else: | ||
logger.error("The program expects that the same number of fastq are provided for READ1 and READ2, current they dont match. \n\n ### READ1 ### \n %s \n ### READ2 ### \n %s \n", fastq1, fastq2) | ||
exit(1) | ||
|
||
|
||
def merge_fastq(fastq_list_R1, fastq_list_R2, out_file1, out_file2): | ||
with open(out_file1, 'wb') as outfile: | ||
for fastq in fastq_list_R1: | ||
with open(fastq, 'rb') as infile: | ||
shutil.copyfileobj(infile, outfile) | ||
with open(out_file2, 'wb') as outfile: | ||
for fastq in fastq_list_R2: | ||
with open(fastq, 'rb') as infile: | ||
shutil.copyfileobj(infile, outfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
pip==19.2.3 | ||
pip==19.3.1 | ||
bump2version==0.5.11 | ||
wheel==0.33.6 | ||
watchdog==0.9.0 | ||
flake8==3.7.8 | ||
tox==3.14.0 | ||
coverage==4.5.4 | ||
Sphinx==1.8.5 | ||
twine==1.14.0 | ||
Sphinx==2.2.0 | ||
twine==2.0.0 | ||
Click==7.0 | ||
pytest==4.6.5 | ||
click-log==0.3.2 | ||
pytest==5.2.1 | ||
pytest-runner==5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.