Ejemplo n.º 1
0
def prefix(s):
    ndb = []
    print("\nPermuting Bits...")
    perm_bits = permute(s)
    m = len(perm_bits)
    print("Generating Negative Database...")
    for i in range(m - 1, 1, -1):
        x = list(create_sequence_of_symbol(m))
        x[i] = to_symbol(comp(perm_bits[i]))

        j = random.randint(0, i - 1)
        while True:
            k = random.randint(0, i - 1)
            if j != k:
                break
        x[j] = to_symbol(perm_bits[j])
        x[k] = to_symbol(perm_bits[k])
        ndb.append(inv_permute(x))

    x = list(create_sequence_of_symbol(m))
    x[0] = to_symbol(perm_bits[0])
    x[1] = to_symbol(comp(perm_bits[1]))
    j = random.randint(2, m - 1)
    x[j] = '0'
    ndb.append(inv_permute(x))
    x[j] = '1'
    ndb.append(inv_permute(x))

    x = list(create_sequence_of_symbol(m))
    x[0] = to_symbol(comp(perm_bits[0]))
    j = random.randint(1, m - 1)
    while True:
        k = random.randint(1, m - 1)
        if j != k:
            break
    x[j] = '0'
    x[k] = '0'
    ndb.append(inv_permute(x))

    x[k] = '1'
    ndb.append(inv_permute(x))

    x[k] = '*'
    while True:
        k = random.randint(1, m - 1)
        if j != k:
            break
    x[j] = '1'
    x[k] = '0'
    ndb.append(inv_permute(x))

    x[k] = '1'
    ndb.append(inv_permute(x))
    print("Negative Database Generated")
    return ndb
Ejemplo n.º 2
0
def compare(features, distance="cos"):
    """ generate the similarity measures for patch-pair combinations """

    start_time = time()

    results = {}

    for tissue in features:

        dyes = list(features[tissue].keys())
        dyes_pair = list(combinations(dyes, 2 if len(dyes) > 1 else 1))

        results[tissue] = {}

        for dye1, dye2 in dyes_pair:

            nb_annot = features[tissue][dye1].shape[0]
            result_pair = np.ones((nb_annot, nb_annot))

            features_dye1 = features[tissue][dye1]
            features_dye2 = features[tissue][dye2]

            result_pair = comp(features_dye1, features_dye2, distance)
            results[tissue][(dye1, dye2)] = result_pair

    print(f"==> Time to compare : {time() - start_time} sec")
    return results
Ejemplo n.º 3
0
def main():

    for i in range(m):
        # print(number_of_sp(np[i]))
        if number_of_sp(np[i]) != 3:
            return True
    # print(number_of_ds(np[m-1],np[m]))
    if number_of_ds(np[m - 1], np[m]) != 1 or number_of_ds(
            np[m + 1], np[m + 2]) != 1 or number_of_ds(np[m + 3],
                                                       np[m + 4]) != 1:
        return False
    else:
        np[m - 1] = merge(np[m - 1], np[m])
        np[m + 1] = merge(np[m + 1], np[m + 2])
        np[m + 3] = merge(np[m + 3], np[m + 4])

    if number_of_ds(np[m + 1], np[m + 3]) != 1:
        return False
    else:
        np[m] = merge(np[m + 1], np[m + 3])

    for i in range(m - 1, -1, -1):
        if number_of_sp(np[i]) != 1:
            return False

        k = index_of_sp(np[i])
        x[k] = comp(to_bit(np[i][k]))
        for j in range(i - 2, -1, -1):
            if np[j][k] != to_symbol(x[k]) or np[j][k] != '*':
                return False

            np[j][k] = '*'

    if x == hashP:
        return True
    else:
        return False
Ejemplo n.º 4
0
_sp = []
for i in range(FLAGS.max_iter):
    batch = mnist.train.next_batch(100)

    # Display
    if (i + 1) % FLAGS.train_display == 0:
        train_accuracy, tr_loss = sess.run([accuracy, ff_loss],
                                           feed_dict={
                                               X: batch[0],
                                               Y: batch[1],
                                               keep_prob: 1.0
                                           })
        print("step %d, lr %.4f, training accuracy %g" %
              (i + 1, sess.run(learning_rate), train_accuracy))

        ratio_w, sp = comp(S_vars)
        _sp = sess.run(sp)

        print("loss: %.4f sp: %0.4f %0.4f %0.4f %0.4f :: using param : %.4f" %
              (tr_loss, _sp[0], _sp[1], _sp[2], _sp[3], sess.run(ratio_w)))

    # Training
    opt.run(feed_dict={X: batch[0], Y: batch[1], keep_prob: 0.5})
    if FLAGS.cges:
        _ = sess.run(cges_op_list)

    # Testing
    if (i + 1) % FLAGS.test_iter == 0:
        test_acc = sess.run(accuracy,
                            feed_dict={
                                X: mnist.test.images,
Ejemplo n.º 5
0
 def subtract(value, iso_dt, unit=None, granularity=None):
     unit = unit or granularity_by_len[len(iso_dt)].lower()
     granularity = granularity or granularity_by_len[len(iso_dt)].lower()
     return comp(fromIsoToDt.to_dt,
                 [getattr(fromDtToDt, 'subtract_{}'.format(unit)), value],
                 getattr(fromDtToIso, 'to_{}'.format(granularity)))(iso_dt)
Ejemplo n.º 6
0
    def do_GET(self):
        """This method is called whenever the client invokes the GET method
        in the HTTP protocol request"""

        # Print the request line
        termcolor.cprint(self.requestline, 'green')
        termcolor.cprint(self.path, "blue")

        o = urlparse(self.path)
        path_name = o.path
        arguments = parse_qs(o.query)
        print("Resource requested:", path_name)
        print("Parameters:", arguments)

        context = {}
        if path_name == "/":
            context["n_sequences"] = len(LIST_SEQUENCES)
            context["list_genes"] = LIST_GENES
            context["list_operations"] = LIST_OPERATIONS
            contents = su.read_template_html_file("./html/index.html").render(
                context=context)
        elif path_name == "/test":
            contents = su.read_template_html_file("./html/test.html").render()
        elif path_name == "/ping":
            contents = su.read_template_html_file("./html/ping.html").render()
        elif path_name == "/get":
            number_sequence = arguments["sequence"][0]
            contents = su.get(LIST_SEQUENCES, number_sequence)
        elif path_name == "/gene":
            gene = arguments["gene"][0]
            contents = su.gene(gene)
        elif path_name == "/operation":
            try:
                sequence = arguments["sequence"][0]
            except KeyError:
                sequence = ""
            operation = arguments["calculation"][0]
            if operation == "Info":
                contents = su.calc(sequence)
            elif operation == "Rev":
                contents = su.rev(sequence)
            elif operation == "Comp":
                contents = su.comp(sequence)
        else:
            contents = su.read_template_html_file("html/error.html").render()

        # Message to send back to the client

        # Generating the response message
        self.send_response(200)  # -- Status line: OK!

        # Define the content-type header:
        self.send_header('Content-Type', 'text/html')
        self.send_header('Content-Length', len(contents.encode()))

        # The header is finished
        self.end_headers()

        # Send the response message
        self.wfile.write(contents.encode())

        return
Ejemplo n.º 7
0
    formatted_message = utils.format_command(msg)
    formatted_message = formatted_message.split(" ")
    if len(formatted_message) == 1:
        command = formatted_message[0]
    else:
        command = formatted_message[0]
        argument = formatted_message[1]
    if command == "PING":
        utils.ping()
        # -- Send a response message to the client
        response = "OK!"
        # -- The message has to be encoded into bytes
        cs.send(str(response).encode())
    elif command == "GET":
        utils.get(cs, list_sequences, argument)
    elif command == "INFO":
        utils.calc(cs)
    elif command == "COMP":
        utils.comp(cs, list_sequences, argument)
    elif command == "REV":
        utils.rev(cs, list_sequences, argument)
    elif command == "GENE":
        utils.gene(cs, argument)

    else:
        response = "Not available command"
        cs.send(str(response).encode())

    # -- Close the data socket
    cs.close()