This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
explorer.py
170 lines (153 loc) · 6.97 KB
/
explorer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import os
import sys
import argparse
import pandas as pd
import numpy as np
from tqdm import tqdm
from gatherer.util import runCommand
from config import *
from gatherer.pipeline import Pipeline
from gatherer.annotation_steps import *
from gatherer.tRNA_scan_se import *
from gatherer.reference_processing_steps import *
from gatherer.annotation_merging_steps import *
from gatherer.lnc_steps import *
from gatherer.final_steps import *
from gatherer.alignment_steps import *
optional_files = ["non_redundant", "rna_dbs"]
require_files(optional_files, mandatory=False)
mandatory_files = ["go_obo", "rfam_cm"]
require_files(mandatory_files)
#set configuration values
confs = {}
for conf in configs:
confs[conf] = configs[conf]
def getArgs():
ap = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("-g", "--genome", required=False,
help="Input genome")
ap.add_argument("-o", "--output", required=True,
help="Directory where the results of each pipeline step will be stored.")
ap.add_argument("-sf", "--start-from", required=False,
help="In case you already runned the entire pipeline, restart from a specific step.")
ap.add_argument("-st", "--stop-at", required=False,
help="Only run the pipeline until a specific step.")
ap.add_argument("-gff", "--reference-gff", required=False,
help=("Reference annotation for the given genome. Such reference annotations are"
+" available for several species at " + confs["coordinates_ftp"]))
ap.add_argument("-ref", "--reference-fasta", required=False,
help=("Reference sequences of ncRNA for this genome. RNA Gatherer will try to find "
+" their genomic mapping and also retrieve information about them from RNACentral and QuickGO."))
ap.add_argument("-tx", "--taxon-id", required=False,
help="Taxon ID for the species, required to retrieve annotations from QuickGo")
ap.add_argument("-tr", "--transcriptome", required=False,
help="Fasta file with transcripts that could be lncRNA molecules.")
ap.add_argument("-ol", "--orf-length", required=False, default = 150,
help = "Minimum ORF length for a sequence be considered as coding (TransDecoder.LongOrfs).")
ap.add_argument("-db", "--use-dbs", required=False, default="True",
help = ("Map transcripts from ncRNA databases, when available, to genome."
+" True (default) / False."))
ap.add_argument("-edb", "--extra-db", required=False, default=None,
help = ("Add extra ncRNA databases for this run. Sintax: -edb db_name:db_path;db_name2:db_path2"))
return vars(ap.parse_args())
#parsing arguments
cmdArgs = getArgs()
outputdir = os.path.abspath(cmdArgs["output"])
if not os.path.exists(outputdir):
runCommand("mkdir " + outputdir)
argsfile = outputdir + "/args.json"
args = {}
if os.path.exists(argsfile):
with open(argsfile, "r") as input_stream:
content = "\n".join(input_stream.readlines())
args = eval(content)
for arg in cmdArgs:
if cmdArgs[arg] is not None:
args[arg] = cmdArgs[arg]
if not "best_hits" in args:
args["best_hits"] = "False"
#if not os.path.isfile(inputFasta):
# sys.exit("Input does not exist!")
maxMem = confs["max_mem"]
if not("threads" in confs):
confs["threads"] = 1
threads = confs["threads"]
args["data_dir"] = outputdir + "/data"
if not os.path.exists(args["data_dir"]):
runCommand("mkdir " + args["data_dir"])
args["genome_link"] = args["data_dir"] + "/genome.fasta"
if "genome" in args:
runCommand("rm " + args["genome_link"])
runCommand("ln -s " + os.path.abspath(args["genome"]) + " " + args["genome_link"])
else:
if not os.path.exists(args["genome_link"]):
print("No path to genome in arguments given now or previously,"
+" please specify a genome to use.")
quit()
index_path = args["genome_link"] + ".mmi"
if not os.path.exists(index_path):
print("Indexing genome for future mappings...")
cmd = " ".join([confs["minimap2"], "-x splice:hq -uf -I 600M -d",
index_path, args["genome_link"]])
code = runCommand(cmd)
if code != 0:
print("Could not find or create minimap2 index for genome.")
quit()
args["genome_index"] = index_path
global_data = os.path.dirname(os.path.realpath(__file__)) + "/data"
confs["rfam2go"] = global_data + "/rfam2go"
if "extra_db" in cmdArgs:
if cmdArgs["extra_db"] != None:
db_pairs = [(db_str.split(":")[0], db_str.split(":")[1])
for db_str in cmdArgs["extra_db"].split(";")]
for db_name, db_path in db_pairs:
p = os.path.abspath(db_path)
if os.path.exists(p):
confs["rna_dbs"][db_name] = p
else:
print(p + " does not exist")
print("Current databases: " + str(confs["rna_dbs"]))
if cmdArgs["use_dbs"] == "False":
confs["rna_dbs"] = {}
if __name__ == '__main__':
stepFuncs = [("split_genome", split_genome),
("run_infernal", run_infernal),
("merge_infernal_outs", merge_infernal_outs),
("parse_infernal", parse_infernal),
("run_trnascan", run_trnascan),
("parse_trna", parse_trna),
("filter_small_sequences", filter_small_sequences),
("filter_long_orfs", filter_long_orfs),
("test_coding_potential", test_coding_potential),
("parse_coding_potential", parse_coding_potential),
("nr_alignment", nr_alignment),
("read_nr_alignment", read_nr_alignment),
("lnc_alignment_minimap", lnc_alignment_minimap),
("lnc_alignment_parsing", lnc_alignment_parsing),
("ncrna_alignment_minimap", ncrna_alignment_minimap),
("ncrna_alignment_parsing", ncrna_alignment_parsing),
("prepare_ref_annotation", prepare_ref_annotation),
("map_to_genome", map_to_genome),
("get_info", get_info),
("get_functional_info", get_functional_info),
("run_gffcompare", run_gffcompare),
("remove_redundancies", remove_redundancies),
("contaminant_removal", contaminant_removal),
("review_annotations", review_annotations),
("write_transcriptome", write_transcriptome),
("make_id2go", make_id2go)]
pipe = Pipeline(args, confs, stepFuncs, args["output"])
if pipe.ready:
print("Arguments file is " + argsfile)
with open(argsfile, "w") as output_stream:
args_str = str(args)
print("Writing args\n"+args_str)
output_stream.write(args_str)
if ("start_from" in args) and ("stop_at" in args):
pipe.run(start_from=args["start_from"], stop_at=args["stop_at"])
elif "start_from" in args:
pipe.run(start_from=args["start_from"])
elif "stop_at" in args:
pipe.run(stop_at=args["stop_at"])
else:
pipe.run()