<s> __author__ = '<STR_LIT>' <EOL> import pdb <EOL> import os , sys , subprocess <EOL> import numpy <EOL> from pbtools . pbtranscript . io . BLASRRecord import BLASRRecord <EOL> from pbtools . pbtranscript . ice . IceUtils import HitItem , eval_blasr_alignment , alignment_has_large_nonmatch <EOL> from pbtools . pbtranscript . ice . c_IceAlign import get_ece_arr_from_alignment <EOL> class LAshowAlignReader : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , las_out_filename ) : <EOL> self . las_out_filename = las_out_filename <EOL> self . f = open ( las_out_filename ) <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> """<STR_LIT>""" <EOL> raw = self . f . readline ( ) . strip ( ) . split ( ) <EOL> if raw [ <NUM_LIT:0> ] == '<STR_LIT:+>' and raw [ <NUM_LIT:1> ] == '<STR_LIT:+>' : <EOL> raise StopIteration <EOL> qID = int ( raw [ <NUM_LIT:0> ] ) + <NUM_LIT:1> <EOL> sID = int ( raw [ <NUM_LIT:1> ] ) + <NUM_LIT:1> <EOL> score = int ( raw [ <NUM_LIT:2> ] ) <EOL> iden = float ( raw [ <NUM_LIT:3> ] ) <EOL> qStrand = int ( raw [ <NUM_LIT:4> ] ) <EOL> qStart = int ( raw [ <NUM_LIT:5> ] ) <EOL> qEnd = int ( raw [ <NUM_LIT:6> ] ) <EOL> qLen = int ( raw [ <NUM_LIT:7> ] ) <EOL> sStrand = int ( raw [ <NUM_LIT:8> ] ) <EOL> sStart = int ( raw [ <NUM_LIT:9> ] ) <EOL> sEnd = int ( raw [ <NUM_LIT:10> ] ) <EOL> sLen = int ( raw [ <NUM_LIT:11> ] ) <EOL> self . f . readline ( ) <EOL> _qStart , qAln = self . f . readline ( ) . strip ( ) . split ( ) <EOL> assert ( qStrand == <NUM_LIT:0> and int ( _qStart ) - <NUM_LIT:1> == qStart ) or ( qStrand == <NUM_LIT:1> and int ( _qStart ) - <NUM_LIT:1> == qLen - qEnd ) <EOL> alnStr = self . f . readline ( ) . strip ( ) <EOL> _sStart , sAln = self . f . readline ( ) . strip ( ) . split ( ) [ : <NUM_LIT:2> ] <EOL> assert ( sStrand == <NUM_LIT:0> and int ( _sStart ) - <NUM_LIT:1> == sStart ) or ( sStrand == <NUM_LIT:1> and int ( _sStart ) - <NUM_LIT:1> == sLen - sEnd ) <EOL> return BLASRRecord ( qID , qLen , qStart , qEnd , qStrand , sID , sLen , sStart , sEnd , sStrand , score , None , qAln = qAln , alnStr = alnStr , sAln = sAln , identity = iden , strand = '<STR_LIT:+>' if qStrand == sStrand else '<STR_LIT:->' ) <EOL> def dalign_against_ref ( dazz_query_obj , dazz_db_obj , las_out_filename , is_FL , sID_starts_with_c , <EOL> qver_get_func , qvmean_get_func , qv_prob_threshold = <NUM_LIT> , <EOL> ece_penalty = <NUM_LIT:1> , ece_min_len = <NUM_LIT:20> , same_strand_only = True , no_qv_or_aln_checking = False , <EOL> max_missed_start = <NUM_LIT:200> , max_missed_end = <NUM_LIT:50> ) : <EOL> """<STR_LIT>""" <EOL> for r in LAshowAlignReader ( las_out_filename ) : <EOL> missed_q = r . qStart + r . qLength - r . qEnd <EOL> missed_t = r . sStart + r . sLength - r . sEnd <EOL> r . qID = dazz_query_obj [ r . qID ] <EOL> r . sID = dazz_db_obj [ r . sID ] <EOL> if sID_starts_with_c : <EOL> assert r . sID . startswith ( '<STR_LIT:c>' ) <EOL> if r . sID . find ( '<STR_LIT:/>' ) > <NUM_LIT:0> : <EOL> r . sID = r . sID . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] <EOL> if r . sID . endswith ( '<STR_LIT>' ) : <EOL> cID = int ( r . sID [ <NUM_LIT:1> : - <NUM_LIT:4> ] ) <EOL> else : <EOL> cID = int ( r . sID [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> cID = r . sID <EOL> if ( cID == r . qID or <EOL> ( r . strand == '<STR_LIT:->' and same_strand_only ) ) : <EOL> yield HitItem ( qID = r . qID , cID = cID ) <EOL> continue <EOL> if no_qv_or_aln_checking : <EOL> yield HitItem ( qID = r . qID , cID = cID , <EOL> qStart = r . qStart , qEnd = r . qEnd , <EOL> missed_q = missed_q * <NUM_LIT:1.> / r . qLength , <EOL> missed_t = missed_t * <NUM_LIT:1.> / r . sLength , <EOL> fakecigar = <NUM_LIT:1> , <EOL> ece_arr = <NUM_LIT:1> ) <EOL> continue <EOL> if ( is_FL and ( r . sStart > max_missed_start or r . qStart > max_missed_start or <EOL> ( r . sLength - r . sEnd > max_missed_end ) or <EOL> ( r . qLength - r . qEnd > max_missed_end ) ) ) : <EOL> yield HitItem ( qID = r . qID , cID = cID ) <EOL> else : <EOL> cigar_str , ece_arr = eval_blasr_alignment ( <EOL> record = r , <EOL> qver_get_func = qver_get_func , <EOL> sID_starts_with_c = sID_starts_with_c , <EOL> qv_prob_threshold = qv_prob_threshold , <EOL> qvmean_get_func = qvmean_get_func ) <EOL> if alignment_has_large_nonmatch ( ece_arr , <EOL> ece_penalty , ece_min_len ) : <EOL> yield HitItem ( qID = r . qID , cID = cID ) <EOL> else : <EOL> yield HitItem ( qID = r . qID , cID = cID , <EOL> qStart = r . qStart , qEnd = r . qEnd , <EOL> missed_q = missed_q * <NUM_LIT:1.> / r . qLength , <EOL> missed_t = missed_t * <NUM_LIT:1.> / r . sLength , <EOL> fakecigar = cigar_str , <EOL> ece_arr = ece_arr ) </s>
