comparison gene_family_classifier.py @ 0:f8603464bea7 draft

Uploaded
author greg
date Thu, 08 Jun 2017 12:48:23 -0400
parents
children 3e10a2683769
comparison
equal deleted inserted replaced
-1:000000000000 0:f8603464bea7
1 #!/usr/bin/env python
2 import argparse
3 import os
4 import shutil
5
6 import utils
7
8
9 BUFF_SIZE = 1048576
10 OUTPUT_DIR = 'geneFamilyClassification_dir'
11
12 parser = argparse.ArgumentParser()
13 parser.add_argument('--input', dest='input', help='Input dataset')
14 parser.add_argument('--scaffold', dest='scaffold', help='Orthogroups or gene families proteins scaffold')
15 parser.add_argument('--method', dest='method', help='Protein clustering method')
16 parser.add_argument('--classifier', dest='classifier', help='Protein classification method')
17 parser.add_argument('--config_dir', dest='config_dir', help='Directory containing default configuration files')
18 parser.add_argument('--num_threads', dest='num_threads', type=int, help='Number of threads to use for execution')
19 parser.add_argument('--super_orthogroups', dest='super_orthogroups', default=None, help='Super orthogroups clustering specification')
20 parser.add_argument('--single_copy_custom', dest='single_copy_custom', default=None, help='Custom single copy orthogroup configuration')
21 parser.add_argument('--single_copy_taxa', dest='single_copy_taxa', type=int, default=0, help='Minimum single copy taxa required in orthogroup')
22 parser.add_argument('--taxa_present', dest='taxa_present', type=int, default=0, help='Minimum taxa required in single copy orthogroup')
23 parser.add_argument('--orthogroup_fasta', dest='orthogroup_fasta', default=None, help='Flag to create orthogroup sequences')
24 parser.add_argument('--coding_sequences', dest='coding_sequences', default=None, help='Flag to create orthogroup coding sequences')
25 parser.add_argument('--save_hmmscan_log', dest='save_hmmscan_log', default=None, help='Flag to save the hmmscan log')
26 parser.add_argument('--hmmscan_log', dest='hmmscan_log', default=None, help='hmmscan log file')
27 parser.add_argument('--output_ptortho', dest='output_ptortho', default=None, help='Output for orthogroups')
28 parser.add_argument('--output_ptortho_dir', dest='output_ptortho_dir', default=None, help='output_ptortho.files_path')
29 parser.add_argument('--output_ptorthocs', dest='output_ptorthocs', default=None, help='Output for orthogroups with corresponding coding sequences')
30 parser.add_argument('--output_ptorthocs_dir', dest='output_ptorthocs_dir', default=None, help='output_ptorthocs.files_path')
31 parser.add_argument('--output_ptsco', dest='output_ptsco', default=None, help='Output for single copy orthogroups')
32 parser.add_argument('--output_ptsco_dir', dest='output_ptsco_dir', default=None, help='output_ptsco.files_path')
33
34 args = parser.parse_args()
35
36 # Build the command line.
37 cmd = 'GeneFamilyClassifier'
38 cmd += ' --proteins %s' % args.input
39 cmd += ' --scaffold %s' % args.scaffold
40 cmd += ' --method %s' % args.method
41 cmd += ' --classifier %s' % args.classifier
42 cmd += ' --config_dir %s' % args.config_dir
43 cmd += ' --num_threads %d' % args.num_threads
44 if args.super_orthogroups is not None:
45 cmd += ' --super_orthogroups %s' % args.super_orthogroups
46 if args.single_copy_custom is not None:
47 cmd += ' --single_copy_custom %s' % args.single_copy_custom
48 if args.single_copy_taxa > 0:
49 cmd += ' --single_copy_taxa %d' % args.single_copy_taxa
50 if args.taxa_present > 0:
51 cmd += ' --taxa_present %d' % args.taxa_present
52 if args.orthogroup_fasta is None:
53 create_ortho_sequences = False
54 else:
55 create_ortho_sequences = True
56 cmd += ' --orthogroup_fasta'
57 if args.coding_sequences is None:
58 create_corresponding_coding_sequences = False
59 else:
60 create_corresponding_coding_sequences = True
61 cmd += ' --coding_sequences %s' % args.coding_sequences
62
63 # Run the command.
64 utils.run_command(cmd)
65
66 # Handle hmmscan.log output.
67 if args.classifier in ['hmmscan', 'both']:
68 src_hmmscan_log = os.path.join(OUTPUT_DIR, 'hmmscan.log')
69 if os.path.exists(src_hmmscan_log):
70 if args.save_hmmscan_log is None:
71 os.remove(src_hmmscan_log)
72 else:
73 shutil.move(src_hmmscan_log, args.hmmscan_log)
74
75 # Handle orthogroups outputs.
76 if create_ortho_sequences:
77 if create_corresponding_coding_sequences:
78 out_file = args.output_ptorthocs
79 orthogroups_fasta_dest_dir = args.output_ptorthocs_dir
80 title = 'Orthogroups and corresponding coding sequences files'
81 else:
82 out_file = args.output_ptortho
83 orthogroups_fasta_dest_dir = args.output_ptortho_dir
84 title = 'Orthogroups files'
85 orthogroups_fasta_src_dir = os.path.join(OUTPUT_DIR, 'orthogroups_fasta')
86 utils.move_directory_files(orthogroups_fasta_src_dir, orthogroups_fasta_dest_dir)
87 utils.write_html_output(out_file, title, orthogroups_fasta_dest_dir)
88
89 # Handle single copy orthogroup outputs.
90 if args.output_ptsco is not None:
91 single_copy_fasta_src_dir = os.path.join(OUTPUT_DIR, 'single_copy_fasta')
92 single_copy_fasta_dest_dir = args.output_ptsco_dir
93 title = 'Single copy orthogroups files'
94 utils.move_directory_files(single_copy_fasta_src_dir, single_copy_fasta_dest_dir)
95 utils.write_html_output(args.output_ptsco, title, single_copy_fasta_dest_dir)