annotate gene_family_classifier.py @ 4:79adf9087193 draft

Uploaded
author greg
date Thu, 16 Aug 2018 10:59:37 -0400
parents 3e10a2683769
children
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
f8603464bea7 Uploaded
greg
parents:
diff changeset
28 args = parser.parse_args()
f8603464bea7 Uploaded
greg
parents:
diff changeset
29
f8603464bea7 Uploaded
greg
parents:
diff changeset
30 # Build the command line.
f8603464bea7 Uploaded
greg
parents:
diff changeset
31 cmd = 'GeneFamilyClassifier'
f8603464bea7 Uploaded
greg
parents:
diff changeset
32 cmd += ' --proteins %s' % args.input
f8603464bea7 Uploaded
greg
parents:
diff changeset
33 cmd += ' --scaffold %s' % args.scaffold
f8603464bea7 Uploaded
greg
parents:
diff changeset
34 cmd += ' --method %s' % args.method
f8603464bea7 Uploaded
greg
parents:
diff changeset
35 cmd += ' --classifier %s' % args.classifier
f8603464bea7 Uploaded
greg
parents:
diff changeset
36 cmd += ' --config_dir %s' % args.config_dir
f8603464bea7 Uploaded
greg
parents:
diff changeset
37 cmd += ' --num_threads %d' % args.num_threads
f8603464bea7 Uploaded
greg
parents:
diff changeset
38 if args.super_orthogroups is not None:
f8603464bea7 Uploaded
greg
parents:
diff changeset
39 cmd += ' --super_orthogroups %s' % args.super_orthogroups
f8603464bea7 Uploaded
greg
parents:
diff changeset
40 if args.single_copy_custom is not None:
f8603464bea7 Uploaded
greg
parents:
diff changeset
41 cmd += ' --single_copy_custom %s' % args.single_copy_custom
f8603464bea7 Uploaded
greg
parents:
diff changeset
42 if args.single_copy_taxa > 0:
f8603464bea7 Uploaded
greg
parents:
diff changeset
43 cmd += ' --single_copy_taxa %d' % args.single_copy_taxa
f8603464bea7 Uploaded
greg
parents:
diff changeset
44 if args.taxa_present > 0:
f8603464bea7 Uploaded
greg
parents:
diff changeset
45 cmd += ' --taxa_present %d' % args.taxa_present
f8603464bea7 Uploaded
greg
parents:
diff changeset
46 if args.orthogroup_fasta is None:
f8603464bea7 Uploaded
greg
parents:
diff changeset
47 create_ortho_sequences = False
f8603464bea7 Uploaded
greg
parents:
diff changeset
48 else:
f8603464bea7 Uploaded
greg
parents:
diff changeset
49 create_ortho_sequences = True
f8603464bea7 Uploaded
greg
parents:
diff changeset
50 cmd += ' --orthogroup_fasta'
f8603464bea7 Uploaded
greg
parents:
diff changeset
51 if args.coding_sequences is None:
f8603464bea7 Uploaded
greg
parents:
diff changeset
52 create_corresponding_coding_sequences = False
f8603464bea7 Uploaded
greg
parents:
diff changeset
53 else:
f8603464bea7 Uploaded
greg
parents:
diff changeset
54 create_corresponding_coding_sequences = True
f8603464bea7 Uploaded
greg
parents:
diff changeset
55 cmd += ' --coding_sequences %s' % args.coding_sequences
f8603464bea7 Uploaded
greg
parents:
diff changeset
56
f8603464bea7 Uploaded
greg
parents:
diff changeset
57 # Run the command.
f8603464bea7 Uploaded
greg
parents:
diff changeset
58 utils.run_command(cmd)
f8603464bea7 Uploaded
greg
parents:
diff changeset
59
f8603464bea7 Uploaded
greg
parents:
diff changeset
60 # Handle hmmscan.log output.
f8603464bea7 Uploaded
greg
parents:
diff changeset
61 if args.classifier in ['hmmscan', 'both']:
f8603464bea7 Uploaded
greg
parents:
diff changeset
62 src_hmmscan_log = os.path.join(OUTPUT_DIR, 'hmmscan.log')
f8603464bea7 Uploaded
greg
parents:
diff changeset
63 if os.path.exists(src_hmmscan_log):
f8603464bea7 Uploaded
greg
parents:
diff changeset
64 if args.save_hmmscan_log is None:
f8603464bea7 Uploaded
greg
parents:
diff changeset
65 os.remove(src_hmmscan_log)
f8603464bea7 Uploaded
greg
parents:
diff changeset
66 else:
f8603464bea7 Uploaded
greg
parents:
diff changeset
67 shutil.move(src_hmmscan_log, args.hmmscan_log)
f8603464bea7 Uploaded
greg
parents:
diff changeset
68
f8603464bea7 Uploaded
greg
parents:
diff changeset
69 # Handle orthogroups outputs.
f8603464bea7 Uploaded
greg
parents:
diff changeset
70 if create_ortho_sequences:
f8603464bea7 Uploaded
greg
parents:
diff changeset
71 orthogroups_fasta_src_dir = os.path.join(OUTPUT_DIR, 'orthogroups_fasta')
3
3e10a2683769 Uploaded
greg
parents: 0
diff changeset
72 orthogroups_fasta_dest_dir = 'output_orthogroups_fasta_dir'
3e10a2683769 Uploaded
greg
parents: 0
diff changeset
73 if not os.path.isdir(orthogroups_fasta_dest_dir):
3e10a2683769 Uploaded
greg
parents: 0
diff changeset
74 os.makedirs(orthogroups_fasta_dest_dir)
3e10a2683769 Uploaded
greg
parents: 0
diff changeset
75 # Remove source direrctory so it won't break dataset collection handler.
3e10a2683769 Uploaded
greg
parents: 0
diff changeset
76 utils.move_directory_files(orthogroups_fasta_src_dir, orthogroups_fasta_dest_dir, remove_source_dir=True)
0
f8603464bea7 Uploaded
greg
parents:
diff changeset
77
f8603464bea7 Uploaded
greg
parents:
diff changeset
78 # Handle single copy orthogroup outputs.
3
3e10a2683769 Uploaded
greg
parents: 0
diff changeset
79 if args.single_copy_custom is not None or args.single_copy_taxa != 0:
0
f8603464bea7 Uploaded
greg
parents:
diff changeset
80 single_copy_fasta_src_dir = os.path.join(OUTPUT_DIR, 'single_copy_fasta')
3
3e10a2683769 Uploaded
greg
parents: 0
diff changeset
81 single_copy_fasta_dest_dir = 'output_single_copy_fasta_dir'
3e10a2683769 Uploaded
greg
parents: 0
diff changeset
82 if not os.path.isdir(single_copy_fasta_dest_dir):
3e10a2683769 Uploaded
greg
parents: 0
diff changeset
83 os.makedirs(single_copy_fasta_dest_dir)
3e10a2683769 Uploaded
greg
parents: 0
diff changeset
84 # Remove source direrctory so it won't break dataset collection handler.
3e10a2683769 Uploaded
greg
parents: 0
diff changeset
85 utils.move_directory_files(single_copy_fasta_src_dir, single_copy_fasta_dest_dir, remove_source_dir=True)