Mercurial > repos > estrain > microrunqc
comparison median_size.py @ 0:4e629e82c5b1 draft default tip
planemo upload commit a820b38dea9a409c11e220ba904da232fdbc4c05
| author | estrain |
|---|---|
| date | Fri, 13 Mar 2026 12:51:10 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4e629e82c5b1 |
|---|---|
| 1 #!/usr/bin/env | |
| 2 | |
| 3 ## Errol Strain (estrain@gmail.com) | |
| 4 ## calculate median insert size from sam file | |
| 5 | |
| 6 import numpy as np | |
| 7 | |
| 8 def get_data(infile): | |
| 9 lengths = [] | |
| 10 for line in infile: | |
| 11 if line.startswith('@'): | |
| 12 pass | |
| 13 else: | |
| 14 line = line.rsplit() | |
| 15 length = int(line[8]) | |
| 16 if length > 0: | |
| 17 lengths.append(length) | |
| 18 else: | |
| 19 pass | |
| 20 return lengths | |
| 21 | |
| 22 if __name__ == "__main__": | |
| 23 import sys | |
| 24 lengths = get_data(sys.stdin) | |
| 25 md = int(np.median(lengths)) | |
| 26 print(md) |
