Example #1
0
#    print reps

qIndex = 0
qSeqs = [74, 1, 2, 3, 4, 5, 6, 7, 8, 9]
qStarts = [0, 2, 3, 20, 1, 1, 3, 3, 1, 1]
qEnds = [95, 60, 50, 70, 80, 59, 99, 40, 77, 100]

#num_test = len(qSeqs)
num_test = 4

for i in range(num_test):
    qSeq = qSeqs[i]
    qStart = qStarts[i]
    qEnd = qEnds[i]

    dist, seq, start, end = onex.findSimilar(dbIndex, qIndex, qSeq, qStart,
                                             qEnd, 0, warp)

    print """Find subsequence in database {} that is similar to subsequence:
  qIndex = {}
  qSeq = {}
  qStart = {}
  qEnd = {}""".format(dbIndex, qIndex, qSeq, qStart, qEnd)

    print "Distance = {}  Sequence = {}  Start = {}  End = {}".format(
        dist, seq, start, end)

    querySequence = onex.getSubsequence(qIndex, qSeq, qStart, qEnd)
    matchSequence = onex.getSubsequence(dbIndex, seq, start, end)

    print "Query:\n{}".format(querySequence)
    print "Match:\n{}".format(matchSequence)
Example #2
0
def api_find_best_match():
    request_id = request.args.get('requestID', type=int)
    ds_collection_index = request.args.get('dsCollectionIndex', type=int)
    q_find_with_custom_query = request.args.get('qFindWithCustomQuery',
                                                0,
                                                type=int)
    q_seq = request.args.get('qSeq', type=int)
    q_start = request.args.get('qStart', type=int)
    q_end = request.args.get('qEnd', type=int)

    if q_start > q_end or q_start < 0 or q_end < 0:
        raise InvalidUsage('Invalid starting and ending position')

    with lock:
        if not (ds_collection_index == current_collection_index):
            raise InvalidUsage(
                'Dataset {} is not loaded yet'.format(ds_collection_index))

        # Index of the dataset containing the query, by default set to the same dataset
        # where the best match will be searched from
        q_ds_index = current_ds_index
        if q_find_with_custom_query:
            if current_q_index == -1:
                raise InvalidUsage('No custom query is loaded')
            # If find with custom query, set to the dataset containing the custom query
            q_ds_index = current_q_index

        # Get number of sequences in the database containing the query
        q_ds_length = onex.getDatasetSeqCount(q_ds_index)
        if q_seq < 0 or q_seq >= q_ds_length:
            raise InvalidUsage('Sequence index is out of bound')

        seq_length = onex.getDatasetSeqLength(q_ds_index)
        if q_start >= seq_length or q_end >= seq_length:
            raise InvalidUsage('Invalid starting and ending position')

        if q_find_with_custom_query:
            app.logger.debug(
                'Look for best match with sequence %d (%d:%d) in the custom query',
                q_seq, q_start, q_end)
        else:
            app.logger.debug(
                'Look for best match with sequence %d (%d:%d) in dataset %d',
                q_seq, q_start, q_end, current_collection_index)

        r_dist, r_seq, r_start, r_end = \
          onex.findSimilar(current_ds_index, q_ds_index, q_seq, q_start, q_end, 0, -1)

        group_index = onex.getGroupIndex(current_ds_index, r_seq, r_start,
                                         r_end)
        app.logger.debug('Result group index: (%d, %d)', group_index[0],
                         group_index[1])

        result = _to_string(
            onex.getSubsequence(current_ds_index, r_seq, r_start, r_end))
        warpingPath = onex.getWarpingPath(q_ds_index, q_seq, q_start, q_end,
                                          current_ds_index, r_seq, r_start,
                                          r_end)

        return jsonify(result=result,
                       groupIndex=group_index,
                       warpingPath=warpingPath,
                       dist=r_dist,
                       dsName=datasets[current_collection_index],
                       seq=r_seq,
                       start=r_start,
                       end=r_end,
                       requestID=request_id)