~ubuntu-branches/ubuntu/trusty/qiime/trusty

« back to all changes in this revision

Viewing changes to qiime/parallel/alpha_diversity.py

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2013-06-17 18:28:26 UTC
  • mfrom: (9.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20130617182826-376az5ad080a0sfe
Tags: 1.7.0+dfsg-1
Upload preparations done for BioLinux to Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
 
# Author: Greg Caporaso (gregcaporaso@gmail.com)
3
 
# alpha_diversity.py
4
 
 
 
2
# File created on 13 Jul 2012
5
3
from __future__ import division
6
 
from os.path import split, splitext
7
 
from qiime.parallel.util import get_rename_command
8
4
 
9
5
__author__ = "Greg Caporaso"
10
 
__copyright__ = "Copyright 2011, The QIIME Project"
11
 
__credits__ = ["Greg Caporaso","Justin Kuczynski"] 
 
6
__copyright__ = "Copyright 2011, The QIIME project"
 
7
__credits__ = ["Greg Caporaso"]
12
8
__license__ = "GPL"
13
 
__version__ = "1.5.0"
 
9
__version__ = "1.7.0"
14
10
__maintainer__ = "Greg Caporaso"
15
11
__email__ = "gregcaporaso@gmail.com"
16
12
__status__ = "Release"
17
13
 
18
 
def get_job_commands(python_exe_fp,alpha_diversity_fp,tree_fp,job_prefix,\
19
 
    metrics,input_fps,output_dir,working_dir,\
20
 
    command_prefix=None,command_suffix=None):
21
 
    """Generate alpha diversity commands to be submitted to cluster
22
 
    """
23
 
 
24
 
    command_prefix = command_prefix or '/bin/bash; '
25
 
    command_suffix = command_suffix or '; exit'
26
 
    
27
 
    commands = []
28
 
    result_filepaths = []
29
 
    
30
 
    for input_fp in input_fps:
31
 
        input_path, input_fn = split(input_fp)
32
 
        output_fn = 'alpha_%s' % input_fn
33
 
        rename_command, current_result_filepaths = get_rename_command(\
34
 
         [output_fn],working_dir,output_dir)
35
 
        result_filepaths += current_result_filepaths
36
 
        
37
 
        command = '%s %s %s -i %s -o %s -t %s -m %s %s %s' %\
38
 
         (command_prefix,\
39
 
          python_exe_fp,\
40
 
          alpha_diversity_fp,\
41
 
          input_fp,
42
 
          working_dir + '/' + output_fn,
43
 
          tree_fp,
44
 
          metrics,
45
 
          rename_command,
46
 
          command_suffix)
 
14
from os.path import join, split
 
15
from qiime.parallel.util import ParallelWrapper
 
16
 
 
17
class ParallelAlphaDiversity(ParallelWrapper):
 
18
    _script_name = "alpha_diversity.py"
 
19
    _job_prefix = 'ALDIV'
 
20
    _input_splitter = ParallelWrapper._input_existing_filepaths
 
21
 
 
22
    def _identify_files_to_remove(self,job_result_filepaths,params):
 
23
        """ The output of the individual jobs are the files we want to keep
 
24
        """
 
25
        return []
 
26
 
 
27
    def _get_job_commands(self,
 
28
                          input_fps,
 
29
                          output_dir,
 
30
                          params,
 
31
                          job_prefix,
 
32
                          working_dir,
 
33
                          command_prefix='/bin/bash; ',
 
34
                          command_suffix='; exit'):
 
35
        """Generate alpha diversity commands to be submitted to cluster
 
36
        """
 
37
        commands = []
 
38
        result_filepaths = []
 
39
        
 
40
        if params['tree_path']:
 
41
            tree_str = '-t %s' % params['tree_path']
 
42
        else:
 
43
            tree_str = ''
 
44
        
 
45
        for input_fp in input_fps:
 
46
            input_path, input_fn = split(input_fp)
 
47
            output_fn = 'alpha_%s' % input_fn
 
48
            output_fn = output_fn.replace('.biom','.txt')
 
49
            temp_fp = join(working_dir,output_fn)
 
50
            rename_command, current_result_filepaths =\
 
51
              self._get_rename_command([output_fn],working_dir,output_dir)
 
52
            result_filepaths += current_result_filepaths
 
53
        
 
54
            command = '%s %s -i %s -o %s %s -m %s %s %s' %\
 
55
             (command_prefix,\
 
56
              self._script_name,
 
57
              input_fp,
 
58
              temp_fp,
 
59
              tree_str,
 
60
              params['metrics'],
 
61
              rename_command,
 
62
              command_suffix)
47
63
          
48
 
        commands.append(command)
49
 
        
50
 
    return commands, result_filepaths
 
64
            commands.append(command)
 
65
        
 
66
        commands = self._merge_to_n_commands(commands,
 
67
                                             params['jobs_to_start'],
 
68
                                             command_prefix=command_prefix,
 
69
                                             command_suffix=command_suffix)
 
70
        
 
71
        return commands, result_filepaths
 
 
b'\\ No newline at end of file'