4
|
1 #!/usr/bin/python
|
|
2
|
|
3 __author__ = 'Abdelrahman Hosny'
|
|
4
|
|
5 import os.path
|
|
6 import datetime
|
|
7 import argparse
|
|
8 import shutil
|
|
9
|
|
10 from cnvsim.fileio import *
|
|
11 from cnvsim.exome_simulator import *
|
|
12 from cnvsim.genome_simulator import *
|
|
13
|
13
|
14 class CapitalisedHelpFormatter(argparse.HelpFormatter):
|
|
15 def add_usage(self, usage, actions, groups, prefix=None):
|
|
16 if prefix is None:
|
|
17 prefix = 'Usage: '
|
|
18 return super(CapitalisedHelpFormatter, self).add_usage(usage, actions, groups, prefix)
|
|
19
|
4
|
20 def log(message):
|
|
21 print '[CNV SIM {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) + "] " + message
|
|
22
|
13
|
23
|
4
|
24 def main():
|
13
|
25 parser = argparse.ArgumentParser(add_help=True, formatter_class=CapitalisedHelpFormatter, \
|
|
26 description='Generates NGS short reads that encompass copy number variations in whole genome and targeted exome sequencing')
|
|
27 parser._positionals.title = 'Positional arguments'
|
|
28 parser._optionals.title = 'Optional arguments'
|
|
29 parser.add_argument('-v', '--version', action='version', version = 'CNV-Sim v0.9.2', help = "Show program's version number and exit.")
|
|
30
|
4
|
31 parser.add_argument("simulation_type", type=str, choices=['genome', 'exome'], \
|
|
32 help="simulate copy number variations in whole genome or exome regions")
|
|
33 parser.add_argument("genome", type=file, \
|
|
34 help="path to the referece genome file in FASTA format ")
|
|
35 parser.add_argument("target", type=file, nargs='?', default=None, \
|
|
36 help="path to the target regions file in BED format (if using exome)")
|
|
37
|
13
|
38 parser.add_argument("-o", "--output_dir_name",type=str, default="simulation_output", \
|
4
|
39 help="a name to be used to create the output directory (overrides existing directory with the same name).")
|
|
40 parser.add_argument("-n", "--n_reads", type=int, default=10000, \
|
|
41 help="total number of reads without variations")
|
|
42 parser.add_argument("-l", "--read_length", type=int, default=100, \
|
|
43 help="read length (bp)")
|
|
44 parser.add_argument("--cnv_list", type=file, default=None, \
|
|
45 help="path to a CNV list file in BED format chr | start | end | variation. If not passed, it is randomly generated using CNV list parameters below")
|
|
46
|
|
47 cnv_sim_group = parser.add_argument_group('CNV list parameters', "parameters to be used if CNV list is not passed")
|
13
|
48 cnv_sim_group.add_argument("-g", "--regions_count", type=int, default=20, \
|
|
49 help="number of CNV regions to be generated randomly")
|
|
50 cnv_sim_group.add_argument("-r_min", "--region_minimum_length", type=int, default=1000, \
|
|
51 help="minimum length of each CNV region")
|
|
52 cnv_sim_group.add_argument("-r_max", "--region_maximum_length", type=int, default=100000, \
|
|
53 help="maximum length of each CNV region")
|
|
54 cnv_sim_group.add_argument("-a", "--amplifications", type=float, default=0.50, \
|
4
|
55 help="percentage of amplifications in range [0.0: 1.0].")
|
13
|
56 cnv_sim_group.add_argument("-d", "--deletions", type=float, default=0.50, \
|
4
|
57 help="percentage of deletions in range [0.0: 1.0].")
|
13
|
58 cnv_sim_group.add_argument("-cn_min", "--copy_number_minimum", type=float, default=3, \
|
|
59 help="minimum level of variations (copy number) introduced")
|
|
60 cnv_sim_group.add_argument("-cn_max", "--copy_number_maximum", type=float, default=10, \
|
|
61 help="maximum level of variation (copy number) introduced")
|
4
|
62
|
|
63 args = parser.parse_args()
|
|
64
|
|
65 simulation_parameters = {}
|
|
66 simulation_parameters['type'] = args.simulation_type
|
|
67 simulation_parameters['genome_file'] = args.genome.name
|
|
68 if args.target is not None:
|
|
69 simulation_parameters['target_file'] = args.target.name
|
|
70 else:
|
|
71 simulation_parameters['target_file'] = None
|
|
72 simulation_parameters['output_dir'] = os.path.join(os.getcwd(), args.output_dir_name)
|
|
73 simulation_parameters['number_of_reads'] = args.n_reads
|
|
74 simulation_parameters['read_length'] = args.read_length
|
|
75 if args.cnv_list is not None:
|
|
76 simulation_parameters['cnv_list_file'] = args.cnv_list.name
|
|
77 else:
|
|
78 simulation_parameters['cnv_list_file'] = None
|
|
79 simulation_parameters['tmp_dir'] = os.path.join(os.getcwd(), args.output_dir_name , "tmp")
|
|
80
|
|
81 cnv_list_parameters = {}
|
|
82 cnv_list_parameters['regions_count'] = args.regions_count
|
13
|
83 cnv_list_parameters['minimum_length'] = args.region_minimum_length
|
|
84 cnv_list_parameters['maximum_length'] = args.region_maximum_length
|
4
|
85 cnv_list_parameters['amplifications'] = args.amplifications
|
|
86 cnv_list_parameters['deletions'] = args.deletions
|
13
|
87 cnv_list_parameters['minimum_variations'] = args.copy_number_minimum
|
|
88 cnv_list_parameters['maximum_variations'] = args.copy_number_maximum
|
|
89
|
|
90 if cnv_list_parameters['amplifications'] + cnv_list_parameters['deletions'] != 1.0:
|
|
91 log("ERROR: percentage of amplifications + percentage of deletions must be equal to 1.0")
|
|
92 exit()
|
4
|
93
|
|
94 if simulation_parameters['type'] == 'genome':
|
|
95 simulate_genome_cnv(simulation_parameters, cnv_list_parameters)
|
|
96 else:
|
|
97 simulate_exome_cnv(simulation_parameters, cnv_list_parameters)
|
|
98
|
|
99
|
|
100 if __name__ == '__main__':
|
|
101 main() |