annotate cnv-sim.py @ 8:31047e84cc0d draft

Uploaded
author ahosny
date Sat, 06 Aug 2016 15:30:10 -0400
parents 4a4d2b78eb55
children e0f5a71e94ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
1 #!/usr/bin/python
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
2
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
3 __author__ = 'Abdelrahman Hosny'
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
4
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
5 import os.path
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
6 import datetime
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
7 import argparse
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
8 import shutil
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
9
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
10 from cnvsim.fileio import *
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
11 from cnvsim.exome_simulator import *
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
12 from cnvsim.genome_simulator import *
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
13
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
14 def log(message):
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
15 print '[CNV SIM {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) + "] " + message
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
16
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
17 def main():
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
18 parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
19 parser.add_argument("simulation_type", type=str, choices=['genome', 'exome'], \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
20 help="simulate copy number variations in whole genome or exome regions")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
21 parser.add_argument("genome", type=file, \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
22 help="path to the referece genome file in FASTA format ")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
23 parser.add_argument("target", type=file, nargs='?', default=None, \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
24 help="path to the target regions file in BED format (if using exome)")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
25
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
26 parser.add_argument("-o", "--output_dir_name",type=str, default="test", \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
27 help="a name to be used to create the output directory (overrides existing directory with the same name).")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
28 parser.add_argument("-n", "--n_reads", type=int, default=10000, \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
29 help="total number of reads without variations")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
30 parser.add_argument("-l", "--read_length", type=int, default=100, \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
31 help="read length (bp)")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
32 parser.add_argument("--cnv_list", type=file, default=None, \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
33 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")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
34
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
35 cnv_sim_group = parser.add_argument_group('CNV list parameters', "parameters to be used if CNV list is not passed")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
36 cnv_sim_group.add_argument("-g", "--regions_count", type=int, default=30, \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
37 help="number of CNV regions to be randomly generated")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
38 cnv_sim_group.add_argument("-a", "--amplifications", type=float, default=0.30, \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
39 help="percentage of amplifications in range [0.0: 1.0].")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
40 cnv_sim_group.add_argument("-d", "--deletions", type=float, default=0.20, \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
41 help="percentage of deletions in range [0.0: 1.0].")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
42 cnv_sim_group.add_argument("-min", "--minimum", type=float, default=3, \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
43 help="minimum number of amplifications/deletions introduced")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
44 cnv_sim_group.add_argument("-max", "--maximum", type=float, default=10, \
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
45 help="maximum number of amplifications/deletions introduced")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
46
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
47 args = parser.parse_args()
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
48
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
49 simulation_parameters = {}
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
50 simulation_parameters['type'] = args.simulation_type
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
51 simulation_parameters['genome_file'] = args.genome.name
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
52 if args.target is not None:
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
53 simulation_parameters['target_file'] = args.target.name
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
54 else:
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
55 simulation_parameters['target_file'] = None
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
56 simulation_parameters['output_dir'] = os.path.join(os.getcwd(), args.output_dir_name)
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
57 simulation_parameters['number_of_reads'] = args.n_reads
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
58 simulation_parameters['read_length'] = args.read_length
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
59 if args.cnv_list is not None:
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
60 simulation_parameters['cnv_list_file'] = args.cnv_list.name
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
61 else:
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
62 simulation_parameters['cnv_list_file'] = None
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
63 simulation_parameters['tmp_dir'] = os.path.join(os.getcwd(), args.output_dir_name , "tmp")
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
64
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
65 cnv_list_parameters = {}
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
66 cnv_list_parameters['regions_count'] = args.regions_count
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
67 cnv_list_parameters['amplifications'] = args.amplifications
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
68 cnv_list_parameters['deletions'] = args.deletions
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
69 cnv_list_parameters['minimum_variations'] = args.minimum
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
70 cnv_list_parameters['maximum_variations'] = args.maximum
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
71
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
72 if simulation_parameters['type'] == 'genome':
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
73 simulate_genome_cnv(simulation_parameters, cnv_list_parameters)
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
74 else:
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
75 simulate_exome_cnv(simulation_parameters, cnv_list_parameters)
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
76
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
77
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
78 if __name__ == '__main__':
4a4d2b78eb55 Main Python Code
ahosny
parents:
diff changeset
79 main()