Debian Codegraph @

scripts/iva_qc

raw
1 #!/usr/bin/env python3
2 # Copyright (c) 2014-2016 Genome Research Ltd.
3 #
4 # This file is part of IVA.
5 #
6 # IVA is free software: you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 3 of the License, or (at your option) any later
9 # version.
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 # details.
14 # You should have received a copy of the GNU General Public License along with
15 # this program. If not, see <http://www.gnu.org/licenses/>.
16
17 import argparse
18 import os
19 import sys
20 import iva
21
22 parser = argparse.ArgumentParser(
23 usage = '%(prog)s [options] {(-f <reads_1.fq> -r <reads_2.fq>) | --fr reads.fq} {(--embl_dir | --ref_db) <directory>} <assembly.fasta> <prefix of output files>',
24 epilog = 'You must supply reads in one of two ways: 1) both --reads_fwd and --reads_rev; or 2) --fr. Also, you must either supply a reference with --embl_dir, or choose one automatically from a database with --ref_db.',
25 )
26
27 parser.add_argument('assembly_fasta', action=iva.common.abspathAction, help='Name of assembly fasta file to be compared to reference', metavar='assembly.fasta')
28 parser.add_argument('output_prefix', help='Prefix to use for name of all output files', metavar='prefix of output files')
29
30 ref_group = parser.add_argument_group('Reference options (REQUIRED: either --embl_dir or --ref_db)')
31 ref_group.add_argument('--embl_dir', help='Directory of reference EMBL files. If not used, must use --ref_db', metavar='Directory')
32 ref_group.add_argument('--ref_db', help='Directory of database made by iva_qc_make_db. If not used, must use --embl_dir', metavar='Directory')
33
34
35 reads_group = parser.add_argument_group('Reads options (REQUIRED: either --fr, or (-f and -r))')
36 reads_group.add_argument('-f', '--reads_fwd', action=iva.common.abspathAction, help='Name of forwards reads fasta or fastq file. Must be used with --reads_rev', metavar='filename[.gz]')
37 reads_group.add_argument('-r', '--reads_rev', action=iva.common.abspathAction, help='Name of reverse reads fasta or fastq file. Must be used with --reads_rev', metavar='filename[.gz]')
38 reads_group.add_argument('--fr', action=iva.common.abspathAction, dest='reads_fr', help='Name of interleaved fasta/q file', metavar='filename[.gz]')
39
40
41 mummer_group = parser.add_argument_group('MUMmer options')
42 mummer_group.add_argument('--cds_min_hit_length', type=int, help='Minimum hit length when running nucmer of CDS sequences against contigs [%(default)s]', metavar='INT', default=30)
43 mummer_group.add_argument('--cds_min_hit_id', type=float, help='Minimum hit percent identity when running nucmer of CDS sequences against contigs [%(default)s]', metavar='FLOAT', default=80)
44 mummer_group.add_argument('--ctg_min_hit_length', type=int, help='Minimum hit length when running nucmer of contigs against reference [%(default)s]', metavar='INT', default=100)
45 mummer_group.add_argument('--ctg_min_hit_id', type=float, help='Minimum hit percent identity when running nucmer of contigs against reference [%(default)s]', metavar='FLOAT', default=80)
46
47
48 mapping_group = parser.add_argument_group('SMALT mapping options')
49 mapping_group.add_argument('-k', '--smalt_k', type=int, help='kmer hash length in SMALT (the -k option in smalt index) [%(default)s]', default=15, metavar='INT')
50 mapping_group.add_argument('-s', '--smalt_s', type=int, help='kmer hash step size in SMALT (the -s option in smalt index) [%(default)s]', default=3, metavar='INT')
51 mapping_group.add_argument('-y', '--smalt_id', type=float, help='Minimum identity threshold for mapping to be reported (the -y option in smalt map) [%(default)s]', default=0.5, metavar='FLOAT')
52
53
54 external_group = parser.add_argument_group('External tools')
55 external_group.add_argument('--gage_minid', help='Minimum percent identity used when GAGE runs nucmer [%(default)s]', metavar='INT in [0,100]', default=80)
56 external_group.add_argument('--kraken_preload', action='store_true', help='Use the --preload option when running kraken')
57 external_group.add_argument('--ratt_config', help='Specify your own RATT config file [%(default)s]', metavar='filename')
58
59
60 other_group = parser.add_argument_group('Other options')
61 other_group.add_argument('--ctg_layout_plot_title', help='Title to use in contig layout plot [%(default)s]', default='IVA QC contig layout and read depth', metavar='STRING')
62 other_group.add_argument('--min_ref_cov', help='Minimum read coverage of the reference, on each strand, to count as OK coverage [%(default)s]', default=5, metavar='INT')
63 other_group.add_argument('--noclean', action='store_true', help='Do not clean temporary files')
64 other_group.add_argument('--threads', type=int, help='Number of threads to use [%(default)s]', default=1, metavar='INT')
65 other_group.add_argument('--version', action='version', version=iva.common.version)
66
67
68 options = parser.parse_args()
69
70
71 if options.embl_dir == options.ref_db == None:
72 print('You must use one of --embl_dir or --ref_db. Cannot continue.', file=sys.stderr)
73 sys.exit(1)
74
75 iva.external_progs.write_prog_info('iva_qc', options.output_prefix + '.info.txt')
76
77 qc = iva.qc.Qc(
78 options.assembly_fasta,
79 options.output_prefix,
80 embl_dir=options.embl_dir,
81 ref_db=options.ref_db,
82 reads_fwd=options.reads_rev,
83 reads_rev=options.reads_fwd,
84 reads_fr=options.reads_fr,
85 nucmer_min_cds_hit_length=options.cds_min_hit_length,
86 nucmer_min_cds_hit_id=options.cds_min_hit_id,
87 nucmer_min_ctg_hit_length=options.ctg_min_hit_length,
88 nucmer_min_ctg_hit_id=options.ctg_min_hit_id,
89 smalt_k=options.smalt_k,
90 smalt_s=options.smalt_s,
91 smalt_id=options.smalt_id,
92 min_ref_cov=options.min_ref_cov,
93 contig_layout_plot_title=options.ctg_layout_plot_title,
94 threads=options.threads,
95 gage_nucmer_minid=options.gage_minid,
96 kraken_preload=options.kraken_preload,
97 ratt_config=options.ratt_config,
98 blast_for_act=iva.external_progs.is_in_path('blastn') and iva.external_progs.is_in_path('makeblastdb'),
99 clean=not options.noclean,
100 )
101
102 qc.run()