Mercurial > repos > peterjc > mira4_assembler
comparison tools/mira4_0/mira4_bait.py @ 39:bbf14bb9607b draft default tip
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
| author | peterjc |
|---|---|
| date | Mon, 03 Jun 2019 13:29:00 -0400 |
| parents | cee8f9005e43 |
| children |
comparison
equal
deleted
inserted
replaced
| 38:cee8f9005e43 | 39:bbf14bb9607b |
|---|---|
| 16 """Run MIRA to find its version number.""" | 16 """Run MIRA to find its version number.""" |
| 17 # At the commend line I would use: mira -v | head -n 1 | 17 # At the commend line I would use: mira -v | head -n 1 |
| 18 # however there is some pipe error when doing that here. | 18 # however there is some pipe error when doing that here. |
| 19 cmd = [mira_binary, "-v"] | 19 cmd = [mira_binary, "-v"] |
| 20 try: | 20 try: |
| 21 child = subprocess.Popen(cmd, universal_newlines=True, | 21 child = subprocess.Popen( |
| 22 stdout=subprocess.PIPE, | 22 cmd, |
| 23 stderr=subprocess.STDOUT) | 23 universal_newlines=True, |
| 24 stdout=subprocess.PIPE, | |
| 25 stderr=subprocess.STDOUT, | |
| 26 ) | |
| 24 except Exception as err: | 27 except Exception as err: |
| 25 sys.stderr.write("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err)) | 28 sys.stderr.write("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err)) |
| 26 sys.exit(1) | 29 sys.exit(1) |
| 27 ver, tmp = child.communicate() | 30 ver, tmp = child.communicate() |
| 28 del child | 31 del child |
| 38 | 41 |
| 39 if "MIRA4" in os.environ: | 42 if "MIRA4" in os.environ: |
| 40 mira_path = os.environ["MIRA4"] | 43 mira_path = os.environ["MIRA4"] |
| 41 mira_binary = os.path.join(mira_path, "mirabait") | 44 mira_binary = os.path.join(mira_path, "mirabait") |
| 42 if not os.path.isfile(mira_binary): | 45 if not os.path.isfile(mira_binary): |
| 43 sys.exit("Missing mirabait under $MIRA4, %r\nFolder contained: %s" | 46 sys.exit( |
| 44 % (mira_binary, ", ".join(os.listdir(mira_path)))) | 47 "Missing mirabait under $MIRA4, %r\nFolder contained: %s" |
| 48 % (mira_binary, ", ".join(os.listdir(mira_path))) | |
| 49 ) | |
| 45 else: | 50 else: |
| 46 sys.stderr.write("DEBUG: Since $MIRA4 is not set, assuming mira binaries are on $PATH.\n") | 51 sys.stderr.write( |
| 52 "DEBUG: Since $MIRA4 is not set, assuming mira binaries are on $PATH.\n" | |
| 53 ) | |
| 47 mira_path = None | 54 mira_path = None |
| 48 mira_binary = "mirabait" | 55 mira_binary = "mirabait" |
| 49 | 56 |
| 50 mira_ver = get_version(mira_binary) | 57 mira_ver = get_version(mira_binary) |
| 51 if not mira_ver.strip().startswith("4.0"): | 58 if not mira_ver.strip().startswith("4.0"): |
| 53 if "-v" in sys.argv or "--version" in sys.argv: | 60 if "-v" in sys.argv or "--version" in sys.argv: |
| 54 print("%s, MIRA wrapper version %s" % (mira_ver, WRAPPER_VER)) | 61 print("%s, MIRA wrapper version %s" % (mira_ver, WRAPPER_VER)) |
| 55 sys.exit(0) | 62 sys.exit(0) |
| 56 | 63 |
| 57 | 64 |
| 58 format, output_choice, strand_choice, kmer_length, min_occurance, bait_file, in_file, out_file = sys.argv[1:] | 65 ( |
| 66 format, | |
| 67 output_choice, | |
| 68 strand_choice, | |
| 69 kmer_length, | |
| 70 min_occurance, | |
| 71 bait_file, | |
| 72 in_file, | |
| 73 out_file, | |
| 74 ) = sys.argv[1:] | |
| 59 | 75 |
| 60 if format.startswith("fastq"): | 76 if format.startswith("fastq"): |
| 61 format = "fastq" | 77 format = "fastq" |
| 62 elif format == "mira": | 78 elif format == "mira": |
| 63 format = "maf" | 79 format = "maf" |
| 65 sys.exit("Was not expected format %r" % format) | 81 sys.exit("Was not expected format %r" % format) |
| 66 | 82 |
| 67 assert out_file.endswith(".dat") | 83 assert out_file.endswith(".dat") |
| 68 out_file_stem = out_file[:-4] | 84 out_file_stem = out_file[:-4] |
| 69 | 85 |
| 70 cmd_list = [mira_binary, "-f", format, "-t", format, | 86 cmd_list = [ |
| 71 "-k", kmer_length, "-n", min_occurance, | 87 mira_binary, |
| 72 bait_file, in_file, out_file_stem] | 88 "-f", |
| 89 format, | |
| 90 "-t", | |
| 91 format, | |
| 92 "-k", | |
| 93 kmer_length, | |
| 94 "-n", | |
| 95 min_occurance, | |
| 96 bait_file, | |
| 97 in_file, | |
| 98 out_file_stem, | |
| 99 ] | |
| 73 if output_choice == "pos": | 100 if output_choice == "pos": |
| 74 pass | 101 pass |
| 75 elif output_choice == "neg": | 102 elif output_choice == "neg": |
| 76 # Invert the selection... | 103 # Invert the selection... |
| 77 cmd_list.insert(1, "-i") | 104 cmd_list.insert(1, "-i") |
| 88 cmd = " ".join(cmd_list) | 115 cmd = " ".join(cmd_list) |
| 89 # print cmd | 116 # print cmd |
| 90 start_time = time.time() | 117 start_time = time.time() |
| 91 try: | 118 try: |
| 92 # Run MIRA | 119 # Run MIRA |
| 93 child = subprocess.Popen(cmd_list, universal_newlines=True, | 120 child = subprocess.Popen( |
| 94 stdout=subprocess.PIPE, | 121 cmd_list, |
| 95 stderr=subprocess.STDOUT) | 122 universal_newlines=True, |
| 123 stdout=subprocess.PIPE, | |
| 124 stderr=subprocess.STDOUT, | |
| 125 ) | |
| 96 except Exception as err: | 126 except Exception as err: |
| 97 sys.stderr.write("Error invoking command:\n%s\n\n%s\n" % (cmd, err)) | 127 sys.stderr.write("Error invoking command:\n%s\n\n%s\n" % (cmd, err)) |
| 98 sys.exit(1) | 128 sys.exit(1) |
| 99 # Use .communicate as can get deadlocks with .wait(), | 129 # Use .communicate as can get deadlocks with .wait(), |
| 100 stdout, stderr = child.communicate() | 130 stdout, stderr = child.communicate() |
| 103 return_code = child.returncode | 133 return_code = child.returncode |
| 104 print("mirabait took %0.2f minutes" % (run_time / 60.0)) | 134 print("mirabait took %0.2f minutes" % (run_time / 60.0)) |
| 105 | 135 |
| 106 if return_code: | 136 if return_code: |
| 107 sys.stderr.write(stdout) | 137 sys.stderr.write(stdout) |
| 108 sys.exit("Return error code %i from command:\n%s" % (return_code, cmd), | 138 sys.exit("Return error code %i from command:\n%s" % (return_code, cmd), return_code) |
| 109 return_code) | |
| 110 | 139 |
| 111 # Capture output | 140 # Capture output |
| 112 out_tmp = out_file_stem + "." + format | 141 out_tmp = out_file_stem + "." + format |
| 113 if not os.path.isfile(out_tmp): | 142 if not os.path.isfile(out_tmp): |
| 114 sys.stderr.write(stdout) | 143 sys.stderr.write(stdout) |
