コード例 #1
0
    def __call__(self, threshold, alphabet_len=None, use_loose=True):
        """Returns a MotifResults object containing a list of significant Motifs
        
            - When a Module is found that is less than the threshold, a new 
                Motif object is created and added to the list of significant
                motifs.
        """
        #Create new MotifResults object
        k_word_results = MotifResults()
        k_word_results.Modules = []
        k_word_results.Motifs = []
        #Add alignment to MotifResults
        k_word_results.Alignment = self.Alignment
        #Give each module a unique ID
        module_id = 0
        #For each module
        for i, module in enumerate(self.Modules):

            if use_loose:
                p_curr = self.getPValueLoose(module, alphabet_len)
            else:
                p_curr = self.getPValueStrict(module, alphabet_len)
            #If the P value is less than or equal to the threshold
            if p_curr <= threshold:
                #Add the P value to the current module
                module.Pvalue = p_curr
                module.ID = module_id
                module_id += 1
                #Append the module to the k_word_results Modules list
                k_word_results.Modules.append(module)
                #Create a Motif from the module and append to Motifs list
                k_word_results.Motifs.append(Motif(module))
        return k_word_results
コード例 #2
0
def GibbsParser(lines, truncate_len=None, strict=True):
    """Returns a MotifResults object given a Gibbs Sampler results file.
    
        - only works with results from command line version of Gibbs Sampler
    """
    try:
        #Get sequence and motif blocks
        sequence_block, motif_block = get_sequence_and_motif_blocks(lines)
    except Exception as e:
        if strict:
            raise e
        else:
            return None
    #Create MotifResults object
    gibbs_motif_results = MotifResults()

    #Get sequence map
    sequence_map = get_sequence_map(sequence_block)
    #Get motif blocks
    motif_blocks = get_motif_blocks(motif_block)
    #Get modules
    for module in motif_blocks:
        if module[1] == 'No Motifs Detected':
            print("No Modules detcted!!", module[0])
            continue
        for cur_smod in build_module_objects(module,
                                             sequence_map,
                                             truncate_len=truncate_len):
            gibbs_motif_results.Modules.append(cur_smod)
    module_ids_to_int(gibbs_motif_results.Modules)

    for ct, module in enumerate(gibbs_motif_results.Modules):
        gibbs_motif_results.Motifs.append(Motif(module))
    gibbs_motif_results.Alphabet = module.Alphabet
    return gibbs_motif_results
コード例 #3
0
ファイル: test_util.py プロジェクト: yatisht/pycogent
 def test_init(self):
     """Init should properly initialize Motif object."""
     module = Module({
                         ('a',3): ModuleInstance('guc', Location('a',3,5)),
                         ('b',3): ModuleInstance('guc', Location('b',3,5)),
                         ('c',8): ModuleInstance('guc', Location('c',8,10)),
                         })
     m = Motif(module)
     self.assertEqual(m.Modules,[module])
     self.assertEqual(m.Info,None)
コード例 #4
0
ファイル: meme.py プロジェクト: cxhernandez/pycogent
def MemeParser(lines, allowed_ids=[]):
    """Returns a MotifResults object given a MEME results file.
    """
    warnings = []
    #Create MotifResults object
    meme_motif_results = MotifResults()
    #Get main block and alphabet
    main_block, alphabet = getDataBlock(lines)
    #Add alphabet to MotifResults object
    meme_motif_results.MolType = alphabet
    #Get command line summary block and module blocks
    command_block, module_blocks = getCommandModuleBlocks(main_block)
    if command_block:
        #Extract command line data and put in dict
        parameters_list = extractCommandLineData(command_block)
        #Add parameters dict to MotifResults object parameters
        meme_motif_results.Parameters = parameters_list
    #make sure modules were found
    if len(module_blocks) > 0:
        #Get Summary of motifs block
        summary_block = getSummaryBlock(module_blocks[-1])
        #Extract summary data and get summary_dict
        summary_dict = extractSummaryData(summary_block)
        seq_names = list(summary_dict['CombinedP'].keys())
        if allowed_ids:
            remap_dict, warning = make_remap_dict(seq_names, allowed_ids)
            if warning:
                warnings.append(warning)
            sd = {}
            for k, v in list(summary_dict['CombinedP'].items()):
                sd[remap_dict[k]] = v
            summary_dict['CombinedP'] = sd
        else:
            remap_dict = dict(list(zip(seq_names, seq_names)))

        #Add summary dict to MotifResults object
        meme_motif_results.Results = summary_dict

        #Add warnings to MotifResults object
        meme_motif_results.Results['Warnings'] = warnings

        #Get blocks for each module
        module_blocks = getModuleDataBlocks(module_blocks)
        #Extract modules and put in MotifResults.Modules list
        for module in module_blocks:
            meme_motif_results.Modules.append(extractModuleData(module,\
                alphabet,remap_dict))
        for module in meme_motif_results.Modules:
            meme_motif_results.Motifs.append(Motif(module))
    return meme_motif_results
コード例 #5
0
ファイル: test_util.py プロジェクト: yatisht/pycogent
 def test_init(self):
     """Init should properly initialize MotifResults object."""
     module = Module({
                         ('a',3): ModuleInstance('guc', Location('a',3,5)),
                         ('b',3): ModuleInstance('guc', Location('b',3,5)),
                         ('c',8): ModuleInstance('guc', Location('c',8,10)),
                         })
     motif = Motif([module])
     results = {'key1':'value1','key2':'value2'}
     parameters = {'parameter1':1,'parameter2':2}
     mr = MotifResults([module],[motif],results,parameters)
     self.assertEqual(mr.Modules,[module])
     self.assertEqual(mr.Motifs,[motif])
     self.assertEqual(mr.Results,results)
     self.assertEqual(mr.parameter1,1)
     self.assertEqual(mr.parameter2,2)
コード例 #6
0
ファイル: gibbs.py プロジェクト: mikerobeson/pycogent
    sequence_map = get_sequence_map(sequence_block)
    #Get motif blocks
    motif_blocks = get_motif_blocks(motif_block)
    #Get modules
    for module in motif_blocks:
        if module[1] == 'No Motifs Detected':
            print "No Modules detcted!!", module[0]
            continue
        for cur_smod in build_module_objects(module,
                                             sequence_map,
                                             truncate_len=truncate_len):
            gibbs_motif_results.Modules.append(cur_smod)
    module_ids_to_int(gibbs_motif_results.Modules)

    for ct, module in enumerate(gibbs_motif_results.Modules):
        gibbs_motif_results.Motifs.append(Motif(module))
    gibbs_motif_results.Alphabet = module.Alphabet
    return gibbs_motif_results


if __name__ == "__main__":
    from sys import argv, exit
    print "Running..."

    if len(argv) != 2:
        print "Usage: gibbs.py <gibbs out file>"
        exit(1)
    mr = GibbsParser(open(argv[1]), 24)
    print mr
    for module in mr.Modules:
        print module.ID