view median_size.py @ 20:9c5e62562c87 draft

Deleted selected files
author estrain
date Thu, 18 Jan 2024 20:20:40 +0000
parents a53acd38d77e
children
line wrap: on
line source

#!/usr/bin/env

## Errol Strain (estrain@gmail.com)
## calculate median insert size from sam file

import numpy as np

def get_data(infile):
    lengths = []
    for line in infile:
        if line.startswith('@'):
            pass
        else:
            line = line.rsplit()
            length = int(line[8])
            if length > 0:
                lengths.append(length)
            else:
                pass
    return lengths

if __name__ == "__main__":
    import sys
    lengths = get_data(sys.stdin)
    md = int(np.median(lengths))
print(md)