Source code for procars.procars_steps

#!/usr/bin/env python
# -*- coding: utf-8 -*-:

"""
Copyright © Bonsai - LIFL (Université Lille 1, CNRS UMR 8022) and Inria-Lille Nord Europe

contact: aida.ouangraoua@inria.fr, amandine.perrin@inria.fr

This software is a computer program whose purpose is to progressively reconstruct ancestral
gene orders.

This software is governed by the CeCILL-B license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/or redistribute the software under the terms of the CeCILL-B
license as circulated by CEA, CNRS and Inria at the following URL
http://www.cecill.info, or in the LICENCE file at the root directory of this program.

The fact that you are presently reading this means that you have had
knowledge of the CeCILL-B license and that you accept its terms.

---------------------------------------------------

``procars_steps`` **module description**:

This module contains all steps of the whole ProCARs pipeline, which are:

    - step a) : Adding non-conflicting adjacencies
    - step b) : Resolving conflicts between adjacencies
    - step c) : Detecting DCJ-reliable adjacencies

These steps are called from the whole pipeline, in the main script : bin/procars_main

.. moduleauthor:: Aïda Ouangraoua, Amandine PERRIN

June 2014

"""


from procars.step_modules import compute_conserved_adjacencies
from procars.step_modules import compute_resolved_conflicts
from procars.step_modules import compute_dcj_adjacencies
from procars.step_modules import compute_pqtree


[docs]def run_step_a(pqtree_file, adjacency_file, step, tree_bin, blocks_bin, car_bin, car_neigh_bin, nb_blocks, last_pqtree): """ Run step a) : Adding non-conflicting adjacencies Parameters ---------- pqtree_file : string Prefix of PQtree file name adjacency_file : string Prefix of adjacencies file name step : int Current step of ProCARs method tree_bin : string Name of binary file in which information about species tree is saved blocks_bin : string Name of binary file in which information about blocks is saved car_bin : string Name of binary file in which information about cars is saved car_neigh_bin : string Name of binary file in which information about car neighbors is saved nb_blocks : int Total number of blocks last_pqtree : string Name of the last PQtree file saved Returns ------- tuple *step:* current step of ProCARs method *donextstep:* boolean to indicate if we must run a new step a) or go to a step b) or c) *nb_discarded:* number of discarded adjacencies found in this step a) *last_pqtree:* name of last PQtree file saved (changed if we found non-conflicting adjacencies in this step) """ step += 1 print("Step " + str(step) + " : Computing conserved adjacencies...") adjs = compute_conserved_adjacencies.main(pqtree_file, adjacency_file, step, tree_bin, blocks_bin, car_bin, car_neigh_bin) nb_nc_adjs, nb_discarded = adjs[0: 2] # If there were conserved adjs, compute the new set of cars if nb_nc_adjs > 0: print("Computing new set of cars...") compute_pqtree.main(nb_blocks, adjacency_file, pqtree_file, step) last_pqtree = pqtree_file + "_" + str(step) + ".txt" # If no conserved adjacency, search for conflicts or DCJ-reliable adjacencies # -> donextstep = False donextstep = nb_nc_adjs != 0 return step, donextstep, nb_discarded, last_pqtree
[docs]def run_step_b(pqtree_file, adjacency_file, step, tree_bin, nb_blocks): """ Run step b): Resolving conflicts between adjacencies. Occurs after a step a) where the set of non-conflicting conserved adjacencies was empty, but the set of conflicting conserved adjacencies was not empty. Parameters ---------- pqtree_file : string Prefix of PQtree file name adjacency_file : string Prefix of adjacencies file name step : int Current step of ProCARs method tree_bin : string Name of binary file in which information about species tree is saved nb_blocks : int Total number of blocks Returns ------- tuple *donextstep:* boolean to indicate if a new step a) must be run or not *last_pqtree:* name of last PQtree file saved """ print("Resolving conflicts between conserved adjacencies...") compute_resolved_conflicts.main(adjacency_file, step, tree_bin) print("Computing new set of cars...") compute_pqtree.main(nb_blocks, adjacency_file, pqtree_file, step) last_pqtree = pqtree_file + "_" + str(step) + ".txt" donextstep = True return donextstep, last_pqtree
[docs]def run_step_c(pqtree_file, adjacency_file, step, tree_bin, blocks_bin, car_bin, car_neigh_bin, nb_blocks, last_pqtree, donextstep): """ Run step c): Detecting DCJ-reliable adjacencies This step comes after a step a) that ended up with empty sets of conflicting and non-conflicting conserved adjacencies. Parameters ---------- pqtree_file : string Prefix of PQtree file name adjacency_file : string Prefix of adjacencies file name step : int Current step of ProCARs method tree_bin : string Name of binary file in which information about species tree is saved blocks_bin : string Name of binary file in which information about blocks is saved car_bin : string Name of binary file in which information about cars is saved car_neigh_bin : string Name of binary file in which information about car neighbors is saved nb_blocks : int Total number of blocks last_pqtree : string Name of the last PQtree file saved donextstep : boolean If a next step must be run after this one or not Returns ------- tuple *donextstep:* boolean to indicate if we must run a new step a) (if we added new adjs) or not *last_pqtree:* name of last PQtree file saved (changed if we found DCJ-reliable adjacencies to add in this step) """ print "Computing dcj reliable adjacencies..." dcj_adjs = compute_dcj_adjacencies.main(adjacency_file, step, car_bin, car_neigh_bin, tree_bin, blocks_bin)[0] nb_dcj = len(dcj_adjs) # If DCJ-reliable adjs found, compute the new set of cars if(nb_dcj != 0): print "Computing new set of cars..." compute_pqtree.main(nb_blocks, adjacency_file, pqtree_file, step) last_pqtree = pqtree_file + "_" + str(step) + ".txt" donextstep = True return donextstep, last_pqtree