annotate median_size.py @ 20:9c5e62562c87 draft

Deleted selected files
author estrain
date Thu, 18 Jan 2024 20:20:40 +0000
parents a53acd38d77e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a53acd38d77e Uploaded
estrain
parents:
diff changeset
1 #!/usr/bin/env
a53acd38d77e Uploaded
estrain
parents:
diff changeset
2
a53acd38d77e Uploaded
estrain
parents:
diff changeset
3 ## Errol Strain (estrain@gmail.com)
a53acd38d77e Uploaded
estrain
parents:
diff changeset
4 ## calculate median insert size from sam file
a53acd38d77e Uploaded
estrain
parents:
diff changeset
5
a53acd38d77e Uploaded
estrain
parents:
diff changeset
6 import numpy as np
a53acd38d77e Uploaded
estrain
parents:
diff changeset
7
a53acd38d77e Uploaded
estrain
parents:
diff changeset
8 def get_data(infile):
a53acd38d77e Uploaded
estrain
parents:
diff changeset
9 lengths = []
a53acd38d77e Uploaded
estrain
parents:
diff changeset
10 for line in infile:
a53acd38d77e Uploaded
estrain
parents:
diff changeset
11 if line.startswith('@'):
a53acd38d77e Uploaded
estrain
parents:
diff changeset
12 pass
a53acd38d77e Uploaded
estrain
parents:
diff changeset
13 else:
a53acd38d77e Uploaded
estrain
parents:
diff changeset
14 line = line.rsplit()
a53acd38d77e Uploaded
estrain
parents:
diff changeset
15 length = int(line[8])
a53acd38d77e Uploaded
estrain
parents:
diff changeset
16 if length > 0:
a53acd38d77e Uploaded
estrain
parents:
diff changeset
17 lengths.append(length)
a53acd38d77e Uploaded
estrain
parents:
diff changeset
18 else:
a53acd38d77e Uploaded
estrain
parents:
diff changeset
19 pass
a53acd38d77e Uploaded
estrain
parents:
diff changeset
20 return lengths
a53acd38d77e Uploaded
estrain
parents:
diff changeset
21
a53acd38d77e Uploaded
estrain
parents:
diff changeset
22 if __name__ == "__main__":
a53acd38d77e Uploaded
estrain
parents:
diff changeset
23 import sys
a53acd38d77e Uploaded
estrain
parents:
diff changeset
24 lengths = get_data(sys.stdin)
a53acd38d77e Uploaded
estrain
parents:
diff changeset
25 md = int(np.median(lengths))
a53acd38d77e Uploaded
estrain
parents:
diff changeset
26 print(md)