__init__.py 4.03 KB
Newer Older
Claire Kuchly's avatar
Claire Kuchly committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#
# 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 logging
Maxime Manno's avatar
Maxime Manno committed
18
import os
Maxime Manno's avatar
Maxime Manno committed
19
20
from glob import glob
from subprocess import Popen, PIPE
Claire Kuchly's avatar
Claire Kuchly committed
21
22
from ng6.ng6workflow import NG6Workflow
from ng6.utils import Utils
Maxime Manno's avatar
Maxime Manno committed
23
from _codecs import encode
Claire Kuchly's avatar
Claire Kuchly committed
24
25
26

class OntQualityCheck (NG6Workflow):
    
Maxime Manno's avatar
Maxime Manno committed
27
28
29
30
    def __init__(self, args={}, id=None, function= "process"):
        NG6Workflow.__init__(self, args, id, function)
        self.log_files = []
        
Claire Kuchly's avatar
Claire Kuchly committed
31
32
33
34
35
36
37
38
    def get_name(self):
        return 'ont_qc'
    
    def get_description(self):
        return "ONT data loading and quality check"
    
    def define_parameters(self, function="process"):
        logging.getLogger("jflow").debug("Begin OntQualityCheck.define_parameters! ont_qc")
39
        self.add_parameter("compression", "How should the data be compressed once archived", choices= [ "none", "gz", "bz2"], default = "gz")
40
        self.add_parameter("trimming", "use trimming with porechop or not",choices= [ "yes", "no"], default = "no")
Maxime Manno's avatar
Maxime Manno committed
41
        self.add_input_file("summary_file", "Input summary basecalling file", default=None)
42
        self.add_parameter("barcoded", "If barcoded run : yes", default = "no")
Maxime Manno's avatar
Maxime Manno committed
43
        self.add_parameter("fast5dir", "path of the fast5 directory", default = None)
Claire Kuchly's avatar
Claire Kuchly committed
44
45
46
47
48
49
50
51
52
        
    def process(self):
        logging.getLogger("jflow").debug("Begin OntQualityCheck.process! test ont_qc")
        sample_names = []
        infiles = []
        for sample in self.samples :
            sample_names.append( sample.name )
            infiles.append(sample.reads1[0])
        # add raw
Maxime Manno's avatar
Maxime Manno committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
        logging.getLogger("jflow").debug("OntQualityCheck.process! get_all_reads : "+",".join(self.get_all_reads()))
        logging.getLogger("jflow").debug("OntQualityCheck.process! sample_name : "+str(sample_names))
        logging.getLogger("jflow").debug("OntQualityCheck.process! summary_file : "+str(self.summary_file))
        
        ### check for log file
        # get current path
        cmd = [self.get_exec_path("pwd")]
        p = Popen(cmd, stdout=PIPE, stderr=PIPE)
        stdout, stderr = p.communicate()
        exec_path = stdout.decode("utf-8").rsplit()[0]
        logging.getLogger("jflow").debug("OntQualityCheck._process.logfile pwd = " + str(exec_path))
        # find .log files
        for file in glob(exec_path+"/*.log"):
            self.log_files.append(file)
67
68
        for file in glob(exec_path+"/*.pdf"):
            self.log_files.append(file)
Maxime Manno's avatar
Maxime Manno committed
69
70
71
72
73
74
        logging.getLogger("jflow").debug("OntQualityCheck._process.logfile self.log_files = " + ",".join(self.log_files))
        logging.getLogger("jflow").debug("OntQualityCheck._process.logfile exiting")
        
        # add logs
        if len(self.log_files) > 0 :
            add_log = self.add_component("BasicAnalysis", [self.log_files,"Log Files","Log files generated during primary analysis","-","-","-","gz", "","log.gz"])
75
        
Claire Kuchly's avatar
Claire Kuchly committed
76
        addrawfiles = self.add_component("AddRawFiles", [self.runobj, self.get_all_reads(), self.compression])
77
        ontstat = self.add_component("Run_stats", [self.summary_file, sample_names[0]])
78
        if (self.barcoded != None) or (self.barcoded != "no") :
79
            demultiplexont = self.add_component("Demultiplex_ONT", [self.get_all_reads() , self.barcoded])
80
        if self.trimming == "yes":
81
            trim_porechop = self.add_component("Trim_porechop", [self.get_all_reads() , "discard_middle"])
Maxime Manno's avatar
Maxime Manno committed
82
        if self.fast5dir != None:
83
            fast5archive = self.add_component("Fast5archive", [self.fast5dir, "fast5archive.tar"])
Maxime Manno's avatar
Maxime Manno committed
84