#!/usr/bin/env python

# Jacob Joseph
# 16 May 2012

# Identify errant insertions in blast_hit_symmetric_arr

from DurandDB import blastq

def get_blast_runs():
    q = "select distinct br_id from blast_hit_symmetric_arr"
    return sorted(bq.dbw.fetchcolumn( q))


if __name__ == "__main__":
    bq = blastq.blastq(cacheq=False)

    br_ids = get_blast_runs()

    for br_id in br_ids:
        print "Testing br_id:", br_id

        hitlists = bq.fetch_score_lists( br_id = br_id,
                                        stype = 'bit_score',
                                        symmetric = True,
                                        batch_size=100)
        for (seq_id_0, hit_list, bit_score) in hitlists:
            if not sorted(bit_score, reverse=True) == bit_score:
                print "Incorrect sorting.  Seq_id_0", seq_id_0
                print bit_score
                break


# 75 87 88 89 90 91 102

        
    
