Exemplo n.º 1
0
def run_multi_round(puzzle_path):
    # Look for multiround links and read those in
    # Assuming that the puzzle will only be part of a single multiround
    found_multi_round = False
    multi_round_paths = []
    links = []
    with open('../json/links.json') as f:
        json_data = json.load(f)
        links = json_data['links']
    for link in links:
        if puzzle_path in link['paths']:
            found_multi_round = True
            multi_round_paths = link['paths']

    # Read the build option list
    split_path = puzzle_path.split('/')
    dir_path = ''
    for path_part in split_path[:-1]:
        dir_path += path_part+'/'
    options_path = dir_path+'build_options.json'

    build_options = []
    with open(options_path) as f:
        build_options = json.load(f)

    # Produce network JSON files for each param combination for multiround
    if found_multi_round:
        multi_round_designs = []
        for path in multi_round_paths:
            with open(path) as f:
                json_data = json.load(f)
                multi_round_designs.append(json_data['designs'])

        phylo_obj = build_phylogeny(multi_round_designs)

        for build in build_options['options']:
            direction_type = build['direction']
            cluster_type = build['clustering']
            score_type = build['scoring']
            threshold = build['threshold']
            maxCluster = build['maxCluster']

            print 'Build options: Direction='+direction_type+' Cluster='+cluster_type+' Score='+score_type+' Threshold='+str(threshold)+' MaxCluster='+str(maxCluster)
            
            # Assigning proper scoring function
            scoreFunc = lambda a,b: 50
            if score_type == 'Levenshtein':
                scoreFunc = scoreLevenshtein
            elif score_type == 'MotifBased':
                scoreFunc = scoreByMotif
            elif score_type == 'Naive':
                scoreFunc = scoreNaive
            else:
                print 'Not found score_type option'
                exit()

            # Running proper clustering method and direction
            if cluster_type == 'MaxForwards':
                phylo_obj.buildMaxForwards(threshold,scoreFunc)

            elif cluster_type == 'MaxBackwards':
                phylo_obj.buildMaxBackwards(threshold,scoreFunc)

            elif direction_type == 'Forwards':
                if cluster_type == 'Threshold':
                    phylo_obj.buildForwardsThreshold(threshold,scoreFunc)
                elif cluster_type == 'Hierarchical':
                    phylo_obj.buildForwardsHierarchical(threshold,maxCluster,scoreFunc)

            elif direction_type == 'Backwards':
                if cluster_type == 'Threshold':
                    phylo_obj.buildBackwardsThreshold(threshold,scoreFunc)
                elif cluster_type == 'Hierarchical':
                    phylo_obj.buildBackwardsHierarchical(threshold,maxCluster,scoreFunc)

            elif direction_type == 'NoDirection':
                if cluster_type == 'Threshold':
                    phylo_obj.buildNoDirectionThreshold(threshold,scoreFunc)
                elif cluster_type == 'Hierarchical':
                    phylo_obj.buildNoDirectionHierarchical(maxCluster,scoreFunc)

            out_name = 'Direction:'+direction_type+'_Clustering:'+cluster_type+'_Scoring:'+score_type+'_Threshold:'+str(threshold)+'_MaxClusters:'+str(maxCluster)+'.json'
            phylo_obj.findAverageChildren()
            phylo_obj.buildEdges()
            phylo_obj.saveNetworkToJSON('../json/Rounds/Multirounds/test/'+out_name)
            phylo_obj.clearNodeConnections()
Exemplo n.º 2
0
def run_single_round(puzzle_path):
    # Read just this puzzle round into json
    single_round_designs = []
    with open(puzzle_path) as f:
        json_data = json.load(f)
        single_round_designs = json_data['designs']

    # Read the build option list
    split_path = puzzle_path.split('/')
    dir_path = ''
    for path_part in split_path[:-1]:
        dir_path += path_part+'/'
    options_path = dir_path+'build_options.json'

    build_options = []
    with open(options_path) as f:
        build_options = json.load(f)
        
    network_file_paths = []
    phylo_obj = build_phylogeny([single_round_designs])
    # Produce network JSON files for each parameter combination
    for build in build_options['options']:
        direction_type = build['direction']
        cluster_type = build['clustering']
        score_type = build['scoring']
        threshold = build['threshold']
        maxCluster = build['maxCluster']

        # 'Build options single: Direction='+direction_type+' Cluster='+cluster_type+' Score='+score_type+' Threshold='+str(threshold)
        
        # Assigning proper scoring function
        scoreFunc = lambda a,b: 50
        if score_type == 'Levenshtein':
            scoreFunc = scoreLevenshtein
        elif score_type == 'MotifBased':
            scoreFunc = scoreByMotif
        elif score_type == 'Naive':
            scoreFunc = scoreNaive
        else:
            print 'Not found score_type option'

        # Running proper clustering method and direction
        if cluster_type == 'MaxForwards':
            # Skipping Building MaxForwards Since Only 1 Round
            continue

        elif cluster_type == 'MaxBackwards':
            # Skipping Building MaxBackwards Since Only 1 Round
            continue

        elif direction_type == 'Forwards':
            if cluster_type == 'Threshold':
                # Skipping Building Forwards Threshold Since Only 1 Round
                continue
            elif cluster_type == 'Hierarchical':
                # Skipping Building Forwards Hierarchical Since Only 1 Round
                continue

        elif direction_type == 'Backwards':
            if cluster_type == 'Threshold':
                # Skipping Building Backwards Threshold Since Only 1 Round
                continue
            elif cluster_type == 'Hierarchical':
                # Skipping Building Backwards Hierarchical Since Only 1 Round
                continue

        elif direction_type == 'NoDirection':
            if cluster_type == 'Threshold':
                # Building NoDirection Threshold'
                phylo_obj.buildNoDirectionThreshold(threshold,scoreFunc)
            elif cluster_type == 'Hierarchical':
                # Building NoDirection Hierarchical
                phylo_obj.buildNoDirectionHierarchical(maxCluster,scoreFunc)

        out_name = 'Direction:'+direction_type+'_Clustering:'+cluster_type+'_Scoring:'+score_type+'_Threshold:'+str(threshold)+'_MaxClusters:'+str(maxCluster)+'.json'
        phylo_obj.findAverageChildren()
        phylo_obj.buildEdges()
        phylo_obj.saveNetworkToJSON(dir_path+'networks/'+out_name)
        phylo_obj.clearNodeConnections()
        network_file_paths.append(dir_path+'networks/'+out_name)
    return network_file_paths