annotate gene_family_classifier.py @ 0:f8603464bea7 draft

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