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