From f722e66b60dcd13a38d8a0c471218e5d7d362130 Mon Sep 17 00:00:00 2001 From: Roberto Villegas-Diaz Date: Fri, 20 Dec 2019 12:22:41 -0600 Subject: [PATCH 1/6] Converting print statements to Python 3 standard --- lmp_processing | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/lmp_processing b/lmp_processing index d5958aa..71eaad1 100755 --- a/lmp_processing +++ b/lmp_processing @@ -97,21 +97,21 @@ def get_nextclip_stats(lib_prefix): if __name__ == '__main__': if len(sys.argv) != 3 or sys.argv[1] == "--help": - print "\n#### w2rap LMP processing ####\n" - print "Usage: {0} libs_list ncpus\n".format(sys.argv[0]) - print "libs_list is a text file containing a list of your FASTQ LMP read files, eg.\n" \ + print("\n#### w2rap LMP processing ####\n") + print("Usage: {0} libs_list ncpus\n".format(sys.argv[0])) + print("libs_list is a text file containing a list of your FASTQ LMP read files, eg.\n" \ "/path/to/LIB1_R1.fastq\n/path/to/LIB1_R2.fastq\n/path/to/LIB2_R1.fastq\n/path/to/LIB2_R2.fastq\n\n" \ - "FASTQ read files must be uncompressed and end in _R1.fastq or _R2.fastq\n" + "FASTQ read files must be uncompressed and end in _R1.fastq or _R2.fastq\n") sys.exit() libs_list = sys.argv[1] ncpus = sys.argv[2] - print "\n#### w2rap LMP processing ####\n" + print("\n#### w2rap LMP processing ####\n") # can we find the input file and does it look ok if not os.path.exists(libs_list): - print "Cannot find libraries file {0}.\n".format(libs_list) + print("Cannot find libraries file {0}.\n".format(libs_list)) sys.exit() # get the directory where this script is running @@ -126,7 +126,7 @@ if __name__ == '__main__': # read env var and add to path bin_dir = os.environ['W2RAP_PATH'] if bin_dir == None: - print "No path to binaries, please set W2RAP_PATH environment variable" + print("No path to binaries, please set W2RAP_PATH environment variable") sys.exit() else: os.environ["PATH"] += os.pathsep + bin_dir @@ -134,22 +134,22 @@ if __name__ == '__main__': # check the required executables exist in the path FLASH_PATH = which("flash") if FLASH_PATH == None: - print "ERROR: Cannot find FLASH in PATH.\n" + print("ERROR: Cannot find FLASH in PATH.\n") sys.exit() DEDUP_PATH = which("dedup_fastq") if DEDUP_PATH == None: - print "ERROR: Cannot find dedup_fastq in PATH.\n" + print("ERROR: Cannot find dedup_fastq in PATH.\n") sys.exit() NXCLIP_PATH = which("nextclip") if NXCLIP_PATH == None: - print "ERROR: Cannot find Nextclip in PATH.\n" + print("ERROR: Cannot find Nextclip in PATH.\n") sys.exit() - print "FLASH found: {0}".format(FLASH_PATH) - print "dedup_fastq found: {0}".format(DEDUP_PATH) - print "Nextclip found: {0}".format(NXCLIP_PATH) + print("FLASH found: {0}".format(FLASH_PATH)) + print("dedup_fastq found: {0}".format(DEDUP_PATH)) + print("Nextclip found: {0}".format(NXCLIP_PATH)) cwd = os.getcwd() @@ -162,15 +162,15 @@ if __name__ == '__main__': r1 = os.path.abspath(r1_in) r2 = os.path.abspath(r2_in) if r1 == r2: - print "Read 1 and read 2 files are the same - {0}.".format(r1) + print("Read 1 and read 2 files are the same - {0}.".format(r1)) sys.exit() if not os.path.exists(r1): - print "Read file {0} does not exist.".format(r1) + print("Read file {0} does not exist.".format(r1)) sys.exit() if not os.path.exists(r2): - print "Read file {0} does not exist.".format(r2) + print("Read file {0} does not exist.".format(r2)) sys.exit() # get the read length from r1 (required for flash) @@ -188,11 +188,12 @@ if __name__ == '__main__': libraries.append({"r1": r1, "r2": r2, "read_length": read_length, "prefix": prefix}) else: break # EOF - print "Number of libraries to process: {0}".format(len(libraries)) + print("Number of libraries to process: {0}".format(len(libraries))) for lib in libraries: - print lib["r1"], lib["r2"] + print(lib["r1"]) + print(lib["r2"]) - print "\nRunning FLASH and de-duplicating combined reads..." + print("\nRunning FLASH and de-duplicating combined reads...") if not os.path.exists("flash"): os.makedirs("flash") @@ -226,9 +227,9 @@ if __name__ == '__main__': # for each library, get the stats from flash and dedup for lib in libraries: - print get_flash_stats(lib["prefix"]) + print(get_flash_stats(lib["prefix"])) - print "Running Nextclip..." + print("Running Nextclip...") if not os.path.exists("nextclip"): os.makedirs("nextclip") @@ -273,7 +274,7 @@ if __name__ == '__main__': os.chdir(cwd) for lib in libraries: - print get_nextclip_stats(lib["prefix"]) + print(get_nextclip_stats(lib["prefix"])) # get rid of the temporary flash dir and extra bits in the nextclip dir shutil.rmtree(os.path.join(cwd, "flash")) @@ -282,4 +283,4 @@ if __name__ == '__main__': for lib in libraries: os.remove(os.path.join(cwd, "nextclip", "{0}.nc_counts".format(lib["prefix"]))) -print "DONE." +print("DONE.") From a517f42c59ebd9ac751224bb20f2136bb6906a09 Mon Sep 17 00:00:00 2001 From: Roberto Villegas-Diaz Date: Fri, 20 Dec 2019 12:27:56 -0600 Subject: [PATCH 2/6] Fixing error with tab --- lmp_processing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lmp_processing b/lmp_processing index 71eaad1..c9e39ec 100755 --- a/lmp_processing +++ b/lmp_processing @@ -183,7 +183,7 @@ if __name__ == '__main__': # get the library prefix base=os.path.basename(r1) - prefix = os.path.splitext(base)[0].replace("_R1", "") + prefix = os.path.splitext(base)[0].replace("_R1", "") libraries.append({"r1": r1, "r2": r2, "read_length": read_length, "prefix": prefix}) else: break # EOF From 52237e437ea13099712a1c55c06ec74b03e8602c Mon Sep 17 00:00:00 2001 From: Roberto Villegas-Diaz Date: Fri, 20 Dec 2019 12:30:15 -0600 Subject: [PATCH 3/6] Fixing error with missing indentation --- lmp_processing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lmp_processing b/lmp_processing index c9e39ec..07ea5a2 100755 --- a/lmp_processing +++ b/lmp_processing @@ -183,7 +183,7 @@ if __name__ == '__main__': # get the library prefix base=os.path.basename(r1) - prefix = os.path.splitext(base)[0].replace("_R1", "") + prefix = os.path.splitext(base)[0].replace("_R1", "") libraries.append({"r1": r1, "r2": r2, "read_length": read_length, "prefix": prefix}) else: break # EOF From 353dd144b39abd1aa003da088340fce396662f26 Mon Sep 17 00:00:00 2001 From: Roberto Villegas-Diaz Date: Fri, 20 Dec 2019 12:31:30 -0600 Subject: [PATCH 4/6] Fixing error with tab --- lmp_processing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lmp_processing b/lmp_processing index 07ea5a2..525a89b 100755 --- a/lmp_processing +++ b/lmp_processing @@ -183,7 +183,7 @@ if __name__ == '__main__': # get the library prefix base=os.path.basename(r1) - prefix = os.path.splitext(base)[0].replace("_R1", "") + prefix = os.path.splitext(base)[0].replace("_R1", "") libraries.append({"r1": r1, "r2": r2, "read_length": read_length, "prefix": prefix}) else: break # EOF From 5a6a216afcfa05cd92ffbac7737c7ec1d57b84d0 Mon Sep 17 00:00:00 2001 From: Roberto Villegas-Diaz Date: Fri, 20 Dec 2019 12:32:33 -0600 Subject: [PATCH 5/6] Fixing error with tab --- lmp_processing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lmp_processing b/lmp_processing index 525a89b..29aac12 100755 --- a/lmp_processing +++ b/lmp_processing @@ -191,7 +191,7 @@ if __name__ == '__main__': print("Number of libraries to process: {0}".format(len(libraries))) for lib in libraries: print(lib["r1"]) - print(lib["r2"]) + print(lib["r2"]) print("\nRunning FLASH and de-duplicating combined reads...") if not os.path.exists("flash"): From 9f02f928cd5a8b1725a2dce153e338e6796807d3 Mon Sep 17 00:00:00 2001 From: Roberto Villegas-Diaz Date: Fri, 20 Dec 2019 12:51:52 -0600 Subject: [PATCH 6/6] Fixing get_flash_stats function --- lmp_processing | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lmp_processing b/lmp_processing index 29aac12..bbe71d3 100755 --- a/lmp_processing +++ b/lmp_processing @@ -65,8 +65,8 @@ def get_flash_stats(lib_prefix): flash_text, err = p.communicate() if p.returncode != 0: raise IOError(err) - - f_fields = flash_text.replace("[FLASH]", "").split("\n") + + f_fields = str(flash_text).replace("[FLASH]", "").split("\\n") with open(dedup_log, 'r') as f: lines = f.readlines()