Exemplo n.º 1
0
def generate_SW_exon_alignments2 (protein_id, species_list = None, referenced_species = "Homo_sapiens"):
    
    # utilities
    alignment_generator = AlignmentTargetGenerator()
    crawler             = DirectoryCrawler()
    command_generator   = CommandGenerator()
    
    logger              = Logger.Instance()
    alignment_logger    = logger.get_logger('alignment')
    
    exon_container      = ExonContainer.Instance()
    
    tmp_fasta_target_path   = "tmp_target.fa"
    ref_exons_fasta = "%s/%s.fa" % (crawler.get_database_path(protein_id), referenced_species)
    
    #ref_exons = exon_container.get((protein_id, referenced_species, "ensembl"))
    #ref_exons.export_coding_exons_to_fasta(tmp_ref_exons_fasta_path)
    
    failed_species_list = []
    
    if (not species_list):
        species_list    = alignment_generator.get_SW_exon_targets(protein_id)
        
    try:
        (proteins_known, proteins_abinitio) = DescriptionParser().parse_descr_file(protein_id)
    except IOError, e:
        alignment_logger.error("{0}, , SW cDNA_EXONS, {2}".format(protein_id, e))
        return False
Exemplo n.º 2
0
def generate_blastn_alignments(protein_id, species_list = None, referenced_species = "Homo_sapiens"):
    '''
        Runs the blastn program for a specified protein and list of species
        @param protein_id
        @param species_list: if provided, runs blastn for this list of species, \
                             otherwise runs for species that are missing the blastn output \
                             who are determined by .status file in the blastn folder.
    '''
    logger              = Logger.Instance()
    alignment_logger    = logger.get_logger('alignment')
    
    crawler             = DirectoryCrawler()
    
    command_generator   = CommandGenerator()
    alignment_generator = AlignmentTargetGenerator()
    
    failed_species_list = []
    
    # retrieve the blastn targets
    if (not species_list):
        species_list    = alignment_generator.get_blastn_targets(protein_id)

    for species in species_list:
        
        ############# MOVE TO ANOTHER FNC
        output_file     = "{0}/{1}.blastout".format(crawler.get_blastn_path(protein_id), species.strip())
        input_file      = "{0}/{1}.fa".format(crawler.get_expanded_gene_path(protein_id), species.strip())
        database        = "{0}/{1}.fa".format(crawler.get_database_path(protein_id), referenced_species)
        
        command         = command_generator.generate_blastn_command(database, input_file, output_file)
        command_return  = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
        output          = command_return.stdout.read()
        if output != "":
            #LOGGING
            os.remove(output_file)
            alignment_logger.warning("{0}, {1}, BLASTN, {2}".format(protein_id, species.strip(), output.strip()))
            failed_species_list.append(species.strip())
            
    if failed_species_list:
        alignment_generator.set_failed_blastn_targets(protein_id, failed_species_list)
        return False
    return True
Exemplo n.º 3
0
def generate_SW_gene_alignments(protein_id, species_list = None, referenced_species = "Homo_sapiens"):
    '''
        Runs the SW program for a specified protein and list of species, using the expanded gene region.
        @param protein_id
        @param species_list: if provided, runs SW for this list of species, \
                             otherwise runs for species that are missing the SW output \
                             who are determined by .status file in the /SW/gene folder.
    '''       
    logger                   = Logger.Instance()
    alignment_logger         = logger.get_logger('alignment')
     
    alignment_generator      = AlignmentTargetGenerator()
    crawler                  = DirectoryCrawler()
    command_generator        = CommandGenerator()
    
    if (not species_list):
        species_list         = alignment_generator.get_SW_gene_targets(protein_id)

    failed_species_list = []
    for species in species_list:
        
        ########### MOVE
        output_file          = "{0}/{1}.swout".format(crawler.get_SW_gene_path(protein_id), species.strip())
        query_sequence_file  = "{0}/{1}.fa".format(crawler.get_expanded_gene_path(protein_id), species.strip())
        target_fasta_db_file = "{0}/{1}.fa".format(crawler.get_database_path(protein_id), referenced_species)
        
        command              = command_generator.generate_SW_command(query_sequence_file, target_fasta_db_file, output_file)
        command_return       = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
        output               = command_return.stdout.read()
        if output != "":
            #LOGGING
            alignment_logger.warning("{0}, {1}, SW GENE, {2}".format(protein_id, species.strip(), output.strip()))
            failed_species_list.append(species.strip())
    os.remove(".sw_stdout_supressed")
    
    if failed_species_list: 
        alignment_generator.set_failed_SW_gene_targets(protein_id, failed_species_list)
        return False
    return True