Skip to content

Commit 110f3f1

Browse files
Fixed many bugs related to the absence of declared bed files
1 parent ff6e539 commit 110f3f1

1 file changed

Lines changed: 68 additions & 60 deletions

File tree

manticore

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ from itertools import combinations
3333
import subprocess
3434
from math import floor, ceil
3535
from Bio import SeqIO
36-
import resource
3736

3837
start_time = time.time()
3938

@@ -51,22 +50,13 @@ if sys.argv[1] in ["-h", "--help", "-help", "getopt", "usage"]:
5150
5251
5352
Usage:
54-
manticore \
55-
--species-name STRING \
56-
--reads-type PE \
57-
--reads PATH1,PATH2 PATH3,PATH4 \
58-
(parentA) (parentB)
59-
--names STRING STRING \
60-
(A) (B)
61-
--reference PATH \
62-
--output-dir PATH \
63-
[ ... other options ... ]
53+
manticore --threads <N> --species-name <str> --reads <A1>,<A2> <B1>,<B2> --names <str> <str> --reference <path> --output-dir <path> [options]
6454
6555
6656
[INPUT OPTIONS]
6757
--species-name Label for output files and plot titles [required]
6858
--reads FASTQ read files, see --help for how to structure [required]
69-
--reads-typ Type of the input reads (PE|SE) [PE]
59+
--reads-type Type of the input reads (PE|SE) [PE]
7060
--names Names of read files, see --help for how to structure [required]
7161
--reference Hybrid genome in FASTA format [required]
7262
--output-dir Output directory [required]
@@ -87,8 +77,8 @@ manticore \
8777
--max-plot-cov Upper limit for coverage plot [100]
8878
8979
[MISCELLANEOUS]
90-
--max-mem Gigabytes of RAM allowed [4G]
9180
--threads Number of parallel threads [1]
81+
--max-mem Gigabytes of RAM allowed [768M]
9282
--cleanup Delete heavy intermediate files at the end [off]
9383
--filter-reference Don't process sequences shorter than --window-size [off]
9484
--isize-read-num Read pairs to use in insert size distribution [10000]
@@ -117,8 +107,8 @@ p.add_argument("--reads-type", choices=["SE", "PE"], default="PE", type=str)
117107
p.add_argument("--version", action="store_true", default=False)
118108
p.add_argument("--restart", action="store_true", default=False)
119109
p.add_argument("--filter-reference", action="store_true", default=False)
120-
p.add_argument("--max-mem", type=str, default="4G")
121110
p.add_argument("--threads", type=int, default=4)
111+
p.add_argument("--max-mem", type=str, default="4G")
122112
p.add_argument("--cleanup", action="store_true", default=False)
123113
# mapping
124114
p.add_argument("--hisat2-map-pars", default="-k 5 --score-min L,0.0,-0.6 --mp 6,2 --rdg 5,3 --rfg 5,3 --no-softclip --no-spliced-alignment")
@@ -145,12 +135,6 @@ args = p.parse_args()
145135

146136
### functions ###
147137

148-
def memory_limit(user_limit):
149-
soft, hard = resource.getrlimit(resource.RLIMIT_AS)
150-
hard_limit = min(float(hard), float(user_limit))
151-
resource.setrlimit(resource.RLIMIT_AS, (get_memory() * 1024 / 2, hard_limit))
152-
153-
154138
def get_memory():
155139
with open('/proc/meminfo', 'r') as mem:
156140
free_memory = 0
@@ -558,41 +542,48 @@ def filter_coverage_file(cov_dir, Names, Beds, min_cov):
558542

559543
code = 0
560544
if int(min_cov) > 1:
561-
562545
for name in Names:
563-
for region in Beds.keys():
564-
code = 0
565-
try:
566-
raw_cov_file = "{0}/{1}.{2}.depth".format(cov_dir, name, region)
567-
dest_cov_file = "{0}/{1}.{2}.{3}x.depth".format(cov_dir, name, region, min_cov)
568-
569-
INPUT = open(raw_cov_file, "r")
570-
OUTPUT = open(dest_cov_file, "w")
571-
572-
for line in INPUT:
573-
lst = line.rstrip("\b\r\n").split("\t")
574-
if int(lst[2]) >= int(min_cov):
575-
OUTPUT.write(line)
576-
INPUT.close()
577-
OUTPUT.close()
578-
except:
579-
code = 1
546+
if len(Beds) > 0:
547+
Regions = Beds.keys()
548+
else:
549+
Regions = ["whole"]
550+
for region in Regions:
551+
code = 0
552+
try:
553+
raw_cov_file = "{0}/{1}.{2}.depth".format(cov_dir, name, region)
554+
dest_cov_file = "{0}/{1}.{2}.{3}x.depth".format(cov_dir, name, region, min_cov)
555+
556+
INPUT = open(raw_cov_file, "r")
557+
OUTPUT = open(dest_cov_file, "w")
558+
559+
for line in INPUT:
560+
lst = line.rstrip("\b\r\n").split("\t")
561+
if int(lst[2]) >= int(min_cov):
562+
OUTPUT.write(line)
563+
INPUT.close()
564+
OUTPUT.close()
565+
except:
566+
code = 1
567+
break
568+
if code != 0:
580569
break
581-
if code != 0:
582-
break
583570
else:
584571
for name in Names:
585-
for region in Beds.keys():
586-
code = 0
587-
try:
588-
raw_cov_file = "{0}/{1}.{2}.depth".format(cov_dir, name, region)
589-
dest_cov_file = "{0}/{1}.{2}.{3}x.depth".format(cov_dir, name, region, min_cov)
590-
os.rename(raw_cov_file, dest_cov_file)
591-
except:
592-
code = 1
572+
if len(Beds) > 0:
573+
Regions = Beds.keys()
574+
else:
575+
Regions = ["whole"]
576+
for region in Regions:
577+
code = 0
578+
try:
579+
raw_cov_file = "{0}/{1}.{2}.depth".format(cov_dir, name, region)
580+
dest_cov_file = "{0}/{1}.{2}.{3}x.depth".format(cov_dir, name, region, min_cov)
581+
os.rename(raw_cov_file, dest_cov_file)
582+
except:
583+
code = 1
584+
break
585+
if code != 0:
593586
break
594-
if code != 0:
595-
break
596587
if code == 0:
597588
return True
598589
else:
@@ -696,14 +687,25 @@ def filter_tables(species_name, tables_dir, Regions, Names, Excluded_sequences):
696687
x = x[~x["Sequence"].isin(Excluded_sequences)]
697688
x.to_csv(outfile, sep="\t", index=False)
698689

699-
for region in Regions:
690+
if Regions != None:
691+
for region in Regions:
692+
for name in Names:
693+
infile = "{0}/{1}.{2}.{3}.txt".format(tables_dir, species_name, name, region)
694+
outfile = "{0}/RES.{1}.{2}.{3}.txt".format(tables_dir, species_name, name, region)
695+
x = pd.read_csv(infile, sep="\t")
696+
x = x[~x["Sequence"].isin(Excluded_sequences)]
697+
x.to_csv(outfile, sep="\t", index=False)
698+
return True
699+
700+
else:
701+
region = "whole"
700702
for name in Names:
701703
infile = "{0}/{1}.{2}.{3}.txt".format(tables_dir, species_name, name, region)
702704
outfile = "{0}/RES.{1}.{2}.{3}.txt".format(tables_dir, species_name, name, region)
703705
x = pd.read_csv(infile, sep="\t")
704706
x = x[~x["Sequence"].isin(Excluded_sequences)]
705707
x.to_csv(outfile, sep="\t", index=False)
706-
return True
708+
return True
707709

708710
except:
709711
return False
@@ -712,6 +714,10 @@ def filter_tables(species_name, tables_dir, Regions, Names, Excluded_sequences):
712714
def generate_metrics_file(species_name, output_dir, tables_dir, Regions, Names, max_jacc_uniq, output_file, window_size):
713715

714716
status = False
717+
718+
if Regions == None:
719+
Regions = ["whole"]
720+
715721
Metrics = { region:{} for region in Regions }
716722

717723
for region in Regions:
@@ -1015,7 +1021,13 @@ def run_jaccard_plot(outdir, matrix, R_path, region, species_name):
10151021
def generate_plots(outdir, R_path, tables_dir, Names, Beds, species_name, maxcov, window_size):
10161022

10171023
Codes = []
1018-
for region in Beds.keys():
1024+
1025+
if len(Beds) == 0:
1026+
Regions = ["whole"]
1027+
else:
1028+
Regions = Beds.keys()
1029+
1030+
for region in Regions:
10191031
name = Names[0]
10201032
matrix = "{0}/RES.{1}.{2}.{3}.txt".format(tables_dir, species_name, name, region)
10211033
Codes.append(run_fraction_plot( outdir, matrix, R_path, region, \
@@ -1088,11 +1100,6 @@ if __name__ == "__main__":
10881100
script_dir = sys.path[0]
10891101
counter = 0
10901102

1091-
### memory limit ###
1092-
maxmem = int(str(args.max_mem).strip("G"))*1e9
1093-
memory_limit(maxmem)
1094-
sys.stderr.write("[{0}] Set memory limit to: {1}G\n".format(at(), int(maxmem / 1e9)))
1095-
10961103
try:
10971104

10981105
### create output directory ###
@@ -1293,13 +1300,14 @@ if __name__ == "__main__":
12931300
# samtools sort uses more memory than the one per thread
12941301
# so I set it to 90% of the one specified by the user
12951302
# to account for this
1296-
maxmem = args.max_mem.strip("G")
1303+
mem_size_letter=args.max_mem[-1]
1304+
maxmem = args.max_mem.strip("GMK")
12971305
adj_maxmem = float(maxmem) * 0.90
12981306
thread_mem_val = float(adj_maxmem) / float(args.threads)
12991307
if thread_mem_val < float(1):
13001308
thread_mem = "768M"
13011309
else:
1302-
thread_mem = str(floor(thread_mem_val)) + "G"
1310+
thread_mem = str(floor(thread_mem_val)) + mem_size_letter
13031311

13041312
sys.stderr.write("[{0}] Sorting with {1} threads and {2} per thread\n".format(at(), args.threads, thread_mem))
13051313

0 commit comments

Comments
 (0)