def sub_sam(sam, percent, sort = True, sbuffer = False):
mapping = sort_sam(sam, sort)<EOL>pool = [<NUM_LIT:1> for i in range(<NUM_LIT:0>, percent)] + [<NUM_LIT:0> for i in range(<NUM_LIT:0>, <NUM_LIT:100> - percent)]<EOL>c = cycle([<NUM_LIT:1>, <NUM_LIT:2>])<EOL>for line in mapping:<EOL><INDENT>line = line.strip().split()<EOL>if line[<NUM_LIT:0>].startswith('<STR_LIT:@>'): <EOL><INDENT>yield line<EOL>continue<EOL><DEDENT>if int(line[<NUM_LIT:1>]) <= <NUM_LIT:20>: <EOL><INDENT>if random.choice(pool) == <NUM_LIT:1>:<EOL><INDENT>yield line<EOL><DEDENT><DEDENT>else:<EOL><INDENT>n = next(c)<EOL>if n == <NUM_LIT:1>:<EOL><INDENT>prev = line<EOL><DEDENT>if n == <NUM_LIT:2> and random.choice(pool) == <NUM_LIT:1>:<EOL><INDENT>yield prev<EOL>yield line<EOL><DEDENT><DEDENT><DEDENT>
randomly subset sam file