forked from caporaso-lab-graveyard/miMAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbiom_to_core_diversity_analyses.py
executable file
·94 lines (65 loc) · 4.11 KB
/
biom_to_core_diversity_analyses.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
from __future__ import division
__author__ = "Giorgio Casaburi and Greg Caporaso"
__copyright__ = "Copyright 2013, The miMAP project"
__credits__ = "Giorgio Casaburi", "Greg Caporaso"
__license__ = "GPL"
__version__ = "0.0.0-dev"
__maintainer__ = "Giorgio Casaburi"
__email__ = "[email protected]"
from shutil import rmtree
from os.path import join, split, splitext, exists
from glob import glob
from tempfile import gettempdir
from pyqi.util import pyqi_system_call, remove_files
from pyqi.core.command import (Command, CommandIn, CommandOut,
ParameterCollection)
class biomtocorediversityanalyses(Command):
BriefDescription = "This command allows to run core diversity analysis using as input a biom table (i.e. output from fasta_to_closed_reference_otu_picking.py script)"
LongDescription = "A command for running core diversity analyses in order to obtain the alpha and beta diversity using a miRNAs biom table as input. Alpha diversity is performed with observed species metric while the beta diversity with Bray-curtis metric. THIS CODE IS CURRENTLY UNTESTED. YOU SHOULD NOT USE THIS VERSION OF THE CODE. THIS MESSAGE WILL BE REMOVED WHEN TESTS ARE ADDED."
CommandIns = ParameterCollection([
CommandIn(Name='input_file', DataType=str,
Description='directory containing the input biom table', Required=True),
CommandIn(Name='output_dir', DataType=str,
Description='the path where the output of core diversity analysis should be written', Required=True),
CommandIn(Name='mapping_file', DataType=str,
Description='the path where the mapping file is located', Required=True),
CommandIn(Name='sampling_depth', DataType=int,
Description='Sequencing depth to use for even sub-sampling and maximum rarefaction depth. You should review the output of print_biom_table_summary.py on the miRNAs biom table to decide on this value', Required=True),
CommandIn(Name='jobs_to_start', DataType=int,
Description='the number of jobs you want to run in parallel', Default=1),
CommandIn(Name='category', DataType=str,
Description='The metadata category or categories to compare (i.e. column headers in the mapping file)', Required = False)
])
CommandOuts = ParameterCollection([
CommandOut(Name='status', DataType=str,
Description='the final result'),
CommandOut(Name='error', DataType=str,
Description='the error result')
])
# Qiime is required to be installed by the User so that every scripts can be called in the command line within the User $HOME.
# Scripts included in Qiime
core_diversity_analyses_path = "core_diversity_analyses.py"
# Temporary folder to store the files:
temp_dir = gettempdir()
verbose = True
def run(self, **kwargs):
input_fp = kwargs['input_file']
output_dir = kwargs['output_dir']
#Mapping file
mapping_file_fp = kwargs['mapping_file']
input_mapping_file_pattern = join(mapping_file_fp,'mapping_file.txt')
temp_files_to_remove = []
temp_dirs_to_remove = []
input_filename = split(input_fp)[1]
input_basename = splitext(input_filename)[0]
#Create and call the core_diversity_analysis.py command and run it using a miRNAs biom table
command = "%s -i %s -m %s -e %s -o %s -a -O %s -c %s --suppress_otu_category_significance --nonphylogenetic_diversity" % (self.core_diversity_analyses_path, input_fp, mapping_file_fp, int(kwargs["sampling_depth"]), output_dir, int(kwargs["jobs_to_start"]), str(kwargs["category"]))
if self.verbose:
print command
stdout, stderr, ret_val = pyqi_system_call(command)
if ret_val != 0:
return {"status":ret_val,
"error":stderr}
# clean up (to do)
CommandConstructor = biomtocorediversityanalyses