__init__.py 4.22 KB
Newer Older
Jerome Mariette's avatar
Jerome Mariette committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#
# Copyright (C) 2012 INRA
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import os
import sys

21
22
23
from ng6.ng6workflow import BasicNG6Workflow
from ng6.project import Project
from ng6.run import Run
24
from ng6.analysis import Analysis
Jerome Mariette's avatar
Jerome Mariette committed
25

26
class AddAnalysis (BasicNG6Workflow):
Jerome Mariette's avatar
Jerome Mariette committed
27
    
Penom Nom's avatar
Penom Nom committed
28
29
30
31
32
33
34
35
    def get_description(self):
        return "Add a brand new analysis to a run or a project"
    
    def define_parameters(self, function="process"):
        self.add_input_file_list("data_file", " Which data files should be added to the analysis", required = True)
        self.add_parameter("compression", "How should data be compressed once archived", choices = ['none', 'gz', 'bz2'], default = 'none')
        self.add_parameter("delete", "Should the input data be deleted once the process is over", type = bool , default = False)
        self.add_parameter("archive_name", "Give a name to the final archive", default = 'ng6_archive')
36
37
        self.add_parameter("project_id", "The project id the analysis belongs to", type = 'int', required = True)
        self.add_parameter("run_id", "The run id the run belongs to", type = 'int', required = True)
Penom Nom's avatar
Penom Nom committed
38
39
40
41
42
        self.add_parameter("analysis_name", "Give a name to your analysis", required = True)
        self.add_parameter("analysis_description", "Give a description to your analysis", required = True)
        self.add_parameter("analysis_software", "Which software was used for this analysis", required = True)
        self.add_parameter("analysis_software_options", "Which software options were used for this analysis", required = True)
        self.add_parameter("analysis_software_version", "analysis_software_version", required = True)
43
        self.add_parameter("parent_analysis", "The id of an analysis to be used as a parent analysis", type= 'int')
Penom Nom's avatar
Penom Nom committed
44
45
        self.add_exclusion_rule( "project_id", "run_id" )
    
Jerome Mariette's avatar
Jerome Mariette committed
46
    def process(self):
Penom Nom's avatar
Penom Nom committed
47
48
        self.runobj = None
        self.project = None
Jerome Mariette's avatar
Jerome Mariette committed
49
50
        # First check if files provided exists
        files_to_save = [] 
Penom Nom's avatar
Penom Nom committed
51
        for file in self.data_file:
Jerome Mariette's avatar
Jerome Mariette committed
52
53
54
55
            if os.path.isfile(file):
                files_to_save.append(file)
            else:
                sys.exit("error: %s file does not exists\n" % (file))
Penom Nom's avatar
Penom Nom committed
56
        
57
        # Check if user provided a project or a run        
Penom Nom's avatar
Penom Nom committed
58
59
60
        if self.project_id :
            self.project = Project.get_from_id(self.project_id)
            self.metadata.append("project_id="+str(self.project_id))
61
            # if user is not allowed to add data on project (is not admin)
Penom Nom's avatar
Penom Nom committed
62
63
            if self.project is not None and not self.project.is_admin(self.admin_login):
                sys.stderr.write( "The user login '" + self.admin_login + "' is not allowed to add data on project '" + self.project.name + "'.\n" )
64
                sys.exit()
Penom Nom's avatar
Penom Nom committed
65
66
67
        elif self.run_id :
            self.runobj = Run.get_from_id(self.run_id)
            self.metadata.append("run_id="+str(self.run_id))
68
        else :
Celine Noirot's avatar
Celine Noirot committed
69
70
            sys.stderr.write("One of run_id or project_id parameter is required!\n")
            sys.exit()
71
72
        
        addto = "project" if self.project else "run"
73
74
        parent = Analysis.get_from_id(self.parent_analysis) if self.parent_analysis else None
        
Penom Nom's avatar
Penom Nom committed
75
76
77
        basicanalysis = self.add_component("BasicAnalyse", [files_to_save, self.analysis_name, 
                        self.analysis_description, self.analysis_software, self.analysis_software_options, 
                        self.analysis_software_version, self.compression, self.delete, 
78
                        self.archive_name], addto=addto, parent = parent)        
Penom Nom's avatar
Penom Nom committed
79
80
81
82
83
84

    def post_process(self):
        if self.runobj:
            self.runobj.sync()
        elif self.project:
            self.project.sync()