Source code for hylite.bowtie2_wrapper

#!/usr/bin/env python3

#    (c) Copyright 2013-2018 Murray Cox, Wandrille Duchemin, Pierre-Yves Dupont.
#
#
#    This file is part of HyLiTE.
#
#    HyLiTE is a free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License version 3 as published by
#    the Free Software Foundation.
#
#    HyLiTE 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 HyLiTE.  If not, see <http://www.gnu.org/licenses/>


#===============================#
# author: Wandrille Duchemin    #
#         Murray Cox            #
# last modified: 9 January 2018 #
#===============================#


from .Parameters import Parameters
from .Generic_wrapper import Generic_wrapper #import os too
import sys


[docs]class bowtie2_wrapper(Generic_wrapper): '''This class is a wrapper for bowtie2 inheriting from Generic_wrapper Attributes: - commandline (str): commandline used ''' def __init__(self): '''Wrapper for bowtie2 It takes no arguments ''' param = Parameters() Generic_wrapper.__init__(self, param.get_param('BOWTIE2_PATH'), {'build_index':param.get_param('BOWTIE2_NAME_BUILD'),'align':param.get_param('BOWTIE2_NAME_ALIGN')},\ {'base':param.get_param('BOWTIE2_OPTION_BASE'),'unpaired':param.get_param('BOWTIE2_OPTION_UNPAIRED'),'paired1':param.get_param('BOWTIE2_OPTION_PAIRED_1'),'paired2':param.get_param('BOWTIE2_OPTION_PAIRED_2'),\ 'mismatch':param.get_param('BOWTIE2_OPTION_MISMATCH'),\ 'out':param.get_param('BOWTIE2_OPTION_OUT'), 'phred64':param.get_param('BOWTIE2_OPTION_PHRED64'), 'thread':param.get_param('BOWTIE2_OPTION_THREAD'),\ 'build_ref':param.get_param('BOWTIE2_BUILD_OPTION_REF'), 'build_out':param.get_param('BOWTIE2_BUILD_OPTION_OUT')\ }) #this should provide a flexible framework. if an option change, just modify the according variable in params.py #should you wish to add a new option, add an option to the params.py and add it to the options dictionnary return
[docs] def build_index(self, reffile, outname): '''Function used to build the .bt2 index from a reffile fasta file Args: - reffile (str): a reference file name (file is fasta) - outname (str): the name of the .bt2 base to create ''' basename = 'build_index' order = ['build_ref', 'build_out'] options_value = {'build_ref':reffile,'build_out':outname} self.commandline = self.build_command_line(basename, options_value, order) if Parameters().get_param('VERBOSE'): self.print_command_line() p=self.run() if Parameters().get_param('VERBOSE'): sys.stdout.write(p.stdout.read().decode('utf8')+'\n') sys.stderr.write(p.stderr.read().decode('utf8')+'\n') else: # have to read it to execute the code p.stdout.read().decode('utf8') p.stderr.read().decode('utf8') return
[docs] def mappe_versus(self, base, lfile, paired, mismatch, thread, quality64, outfile): '''Function used to map reads against a base using bowtie2. Args: - base (str): the name of the .bt2 base - lfile (list): a list of the name of the file containing the reads - paired (bool): a boolean set to True of the data are paired end reads - mismatch (bool): a boolean set to True of you want to allow mismatch in the seed - thread(int): an int specifying the number of thread to use (1 is authorized) - quality64 (bool): a boolean set to True if the quality of the reads is in phred64 format - outfile (str): a string specifying the name of the .sam out file to write ''' basename = 'align' option_value = dict() order=list() if max(1, thread)>1: option_value['thread']=str(thread) order.append('thread') if quality64 is True: option_value['phred64']=True order.append('phred64') if mismatch is True: option_value['mismatch']=True order.append('mismatch') option_value['base'] = base order.append('base') if paired is True: option_value['paired1']=lfile[0] option_value['paired2']=lfile[1] order.append('paired1') order.append('paired2') else: option_value['unpaired']=lfile[0] order.append('unpaired') option_value['out'] = outfile order.append('out') self.commandline = self.build_command_line(basename, option_value, order) if Parameters().get_param('VERBOSE'): self.print_command_line() p=self.run() if Parameters().get_param('VERBOSE'): sys.stdout.write(p.stdout.read().decode('utf8')+'\n') sys.stderr.write(p.stderr.read().decode('utf8')+'\n') else: # have to read it to execute the code p.stdout.read().decode('utf8') p.stderr.read().decode('utf8') return