#!/usr/bin/env python
"""Kurt Schwehr -- kdschwehr@ucsd.edu -- http://schwehr.org Feb 2005 -- GPL License"""
import os	# os.remove()
import sys	# sys.exit()
import string
import sqlite	# pysqlite

def make_set (db_cx, table, field, where):
    """ Build a set and return it from a table/field"""
    cu = db_cx.cursor()
    cu.execute("SELECT "+field+" FROM "+table+" "+where+";")
    s = set()
    for row in cu.fetchall():
        s.add(row[field])
    return s

if __name__ == '__main__':
    print "Starting list-missing"
    dbFileName="bpsio04.db"

    cx = sqlite.connect (dbFileName);
    #coreset = make_set(cx,"coreloc","corenum","")
    weight_samples = make_set(cx,"weights","samplename","")
    ams_samples = make_set(cx,"ams","samplename","")
    wa_missing = weight_samples.symmetric_difference(ams_samples)
    for sample in wa_missing:
        if sample in weight_samples: print "Missing from ams:     ",sample
        else:                        print "Missing from weight:  ",sample

    # FIX: add to where that is has to be afdmag or nrm
    # Need to exclude ODP
    nrm_samples = make_set(cx,"mag","samplename"," WHERE treatment=0")
    wn_missing = weight_samples.symmetric_difference(nrm_samples)
    for sample in wn_missing:
        if sample in weight_samples: print "Missing from mag/nrm: ",sample
        else:                        print "Missing from weight:  ",sample


syntax highlighted by Code2HTML, v. 0.9.1