# Path: nucio.py
# def getDeltaAlignmentIterator(fh):
# 
#     itembuf = []    
#     while True:
#         line = fh.readline()
#         if line.startswith(">") or not line:
#             record = prepareDeltaRecord(itembuf)
#             if not None == record:
#                 yield record
#             itembuf = []
#             if not line:
#                 break
#         for i in line.strip().split():
#             itembuf.append(i)
# 
# def deltaRecordToOriginalFormat(dr):
# 
#     final_str = deltaRecordHeaderToString(dr)
#     
#     for alignment in dr.alignments:
#         final_str += "\n" + deltaAlignmentHeaderToString(alignment)
#         p = "\n".join(map(str, alignment.positions))
#         final_str += "\n"+p
#         
#     return final_str
# 
# Path: nucio.py
# def deltaRecordHeaderToString(dr):
#     a = map(lambda x : str(getattr(dr, x)), dr._fields[:-1])
#     a[0] = ">"+a[0]
#     return " ".join(a)
# 
# def deltaAlignmentHeaderToString(alignment):
#     a = map(lambda x : str(getattr(alignment,x)), 
#             alignment._fields[:-1])    
#     return " ".join(a)


import sys
from collections import namedtuple
from math import fabs
from nucio import getDeltaAlignmentIterator, deltaRecordToOriginalFormat
from nucio import deltaRecordHeaderToString, deltaAlignmentHeaderToString
          record.slen > record.qlen):
        return True

    #else proper overlap off end of pb read
    if( (a.sstart == arange.start or arange.end == a.send) and
          (a.qstart < qury_wiggle or a.qend < qury_wiggle or
           (record.qlen - a.qstart) < qury_wiggle or (record.qlen - a.qend) < qury_wiggle)):
        return True
    
    return False


AlignmentRange = namedtuple('AlignmentRange',["start","end"])

WIGGLE_PCT = float(sys.argv[2])
CONTAINED_PCT = float(sys.argv[3])
MIN_ALIGNMENT_SIZE = int(sys.argv[4])

outfilename = sys.argv[5]

fh = open(sys.argv[1])

delta_header = fh.readline() + fh.readline().strip()

#read all alignments into memory,
#could be bad for large delta files
deltaHash={}
for record in getDeltaAlignmentIterator(fh):
    if not deltaHash.has_key(record.sname):
        deltaHash[record.sname] = []

# Path: nucio.py
# def getDeltaAlignmentIterator(fh):
# 
#     itembuf = []    
#     while True:
#         line = fh.readline()
#         if line.startswith(">") or not line:
#             record = prepareDeltaRecord(itembuf)
#             if not None == record:
#                 yield record
#             itembuf = []
#             if not line:
#                 break
#         for i in line.strip().split():
#             itembuf.append(i)
# 
# def deltaRecordToOriginalFormat(dr):
# 
#     final_str = deltaRecordHeaderToString(dr)
#     
#     for alignment in dr.alignments:
#         final_str += "\n" + deltaAlignmentHeaderToString(alignment)
#         p = "\n".join(map(str, alignment.positions))
#         final_str += "\n"+p
#         
#     return final_str
# 
# Path: nucio.py
# def deltaRecordHeaderToString(dr):
#     a = map(lambda x : str(getattr(dr, x)), dr._fields[:-1])
#     a[0] = ">"+a[0]
#     return " ".join(a)
# 
# def deltaAlignmentHeaderToString(alignment):
#     a = map(lambda x : str(getattr(alignment,x)), 
#             alignment._fields[:-1])    
#     return " ".join(a)


# Path: pre_delta_filter.py
import sys
from collections import namedtuple
from math import fabs
from nucio import getDeltaAlignmentIterator, deltaRecordToOriginalFormat
from nucio import deltaRecordHeaderToString, deltaAlignmentHeaderToString

          record.slen > record.qlen):
        return True

    #else proper overlap off end of pb read
    if( (a.sstart == arange.start or arange.end == a.send) and
          (a.qstart < qury_wiggle or a.qend < qury_wiggle or
           (record.qlen - a.qstart) < qury_wiggle or (record.qlen - a.qend) < qury_wiggle)):
        return True
    
    return False


AlignmentRange = namedtuple('AlignmentRange',["start","end"])

WIGGLE_PCT = float(sys.argv[2])
CONTAINED_PCT = float(sys.argv[3])
MIN_ALIGNMENT_SIZE = int(sys.argv[4])

outfilename = sys.argv[5]

fh = open(sys.argv[1])

delta_header = fh.readline() + fh.readline().strip()

#read all alignments into memory,
#could be bad for large delta files
deltaHash={}
for record in getDeltaAlignmentIterator(fh):
    if not deltaHash.has_key(record.sname):
        deltaHash[record.sname] = []

    deltaHash[record.sname].append(record)