# Path: nucio.py
# def getNucmerAlignmentIterator(fh):
#     '''Get nucmer alignments from show-coords output
#     (Deprecated legacy)
#     '''
#     return lineRecordIterator(fh, NucRecord, NucRecordTypes)
# 
# def nucRecordToString(nuc_record):
#     fields = nuc_record._fields
#     return "\t".join(
#         imap( lambda x : str(getattr(nuc_record, x)), fields))
# 
# Path: misc.py
# def append_str(s):
#     '''returns a function that appends s'''
#     return lambda x: concat(x,s)


import sys
from nucio import getNucmerAlignmentIterator, nucRecordToString
from itertools import groupby, imap, izip, starmap
from operator import attrgetter, eq
from misc import append_str
#!/usr/bin/env python

#If the illumina unitigs are very long,
#ie. the average unitig is longer than the
#average pb read, might want to shred the unitigs
#and filter out pb reads that are contained in
#those long unitigs.

#This script probably does that.
#It takes the show-coords output and
#marks which pb reads should be kept



if not len(sys.argv) > 1:
    print "pb_filter_for_shred.py all.sc [significant_alignment_length(int)(default:200)]"
    sys.exit(1)

#length of alignment to label "significant"
SIG_ALN_LEN = 200
if len(sys.argv) > 2:
    SIG_ALN_LEN = int(sys.argv[2])

afh = open(sys.argv[1])
alignment_it = getNucmerAlignmentIterator(afh)


# Path: nucio.py
# def getNucmerAlignmentIterator(fh):
#     '''Get nucmer alignments from show-coords output
#     (Deprecated legacy)
#     '''
#     return lineRecordIterator(fh, NucRecord, NucRecordTypes)
# 
# def nucRecordToString(nuc_record):
#     fields = nuc_record._fields
#     return "\t".join(
#         imap( lambda x : str(getattr(nuc_record, x)), fields))
# 
# Path: misc.py
# def append_str(s):
#     '''returns a function that appends s'''
#     return lambda x: concat(x,s)


# Path: pb_filter_for_shred.py
import sys
from nucio import getNucmerAlignmentIterator, nucRecordToString
from itertools import groupby, imap, izip, starmap
from operator import attrgetter, eq
from misc import append_str

#!/usr/bin/env python

#If the illumina unitigs are very long,
#ie. the average unitig is longer than the
#average pb read, might want to shred the unitigs
#and filter out pb reads that are contained in
#those long unitigs.

#This script probably does that.
#It takes the show-coords output and
#marks which pb reads should be kept



if not len(sys.argv) > 1:
    print "pb_filter_for_shred.py all.sc [significant_alignment_length(int)(default:200)]"
    sys.exit(1)

#length of alignment to label "significant"
SIG_ALN_LEN = 200
if len(sys.argv) > 2:
    SIG_ALN_LEN = int(sys.argv[2])

afh = open(sys.argv[1])
alignment_it = getNucmerAlignmentIterator(afh)


for pbname, alignment in groupby(alignment_it, lambda x : x.sname):