"""Are st and end in capture?
   Are st and end in the same exon?"""
import sys, csv, os
import mkSnvBedFile
sys.path.append('/home/evansj/me/projects/diskin/target_indels/code/')
import bed_tools

if __name__ == '__main__':
    title, fileToAnnotate, captureBed, outFile = sys.argv[1:]
    with open('tmp.bed', 'w') as fout, open(captureBed) as f:
        print('chrom\tstart\tend', file=fout)
        for line in f:
            if line.split('\t')[1] != 'chromStart':
                print(line[3:].strip(), file=fout)
    
    captureDataStrict = bed_tools.load_nb222_exome_capture_driver('tmp.bed', 0)
    captureDataRelaxed = bed_tools.load_nb222_exome_capture_driver('tmp.bed', 100)
    with open(fileToAnnotate) as f, open(outFile, 'w') as fout:
        reader = csv.DictReader(f, delimiter='\t')
        print('\t'.join(reader.fieldnames) + '\t'
              + '\t'.join(['CAPTURE_STRICT_' + title,
                           'CAPTURE_RELAXED_' + title,
                           ]),
              file=fout)
        for row in reader:
            chrom = row['chrom']
            st,end = mkSnvBedFile.fixCoords(row)
            st = int(st)

            status = {}
            for captureData, label in ( (captureDataStrict, 'STRICT'),
"""Are st and end in capture?
   Are st and end in the same exon?"""
import sys, csv
import mkSnvBedFile
sys.path.append('/home/evansj/me/projects/diskin/target_indels/code/')
import bed_tools

if __name__ == '__main__':
    fileToAnnotate, captureBed, outFile = sys.argv[1:]
    captureDataStrict = bed_tools.load_nb222_exome_capture_driver(captureBed, 0)
    captureDataRelaxed = bed_tools.load_nb222_exome_capture_driver(captureBed, 100)
    with open(fileToAnnotate) as f, open(outFile, 'w') as fout:
        reader = csv.DictReader(f, delimiter='\t')
        print('\t'.join(reader.fieldnames) + '\t'
              + '\t'.join(['CAPTURE_STRICT',
                           'CAPTURE_RELAXED',
                           ]),
              file=fout)
        for row in reader:
            chrom = row['chrom']
            st,end = mkSnvBedFile.fixCoords(row)
            st = int(st)
            status = {}
            for captureData, label in ( (captureDataStrict, 'STRICT'),
                                        (captureDataRelaxed, 'RELAXED') ):
                captureStatusSt = bed_tools.find_location_in_bed("chr" + chrom, st, captureData[1], captureData[0])
                if captureStatusSt:
                    status[label] = 'CAP_%s_TRUE' % (label,)
                else:
                    status[label] = 'CAP_%s_FALSE' % (label,)