Commit 5c598d30 authored by Theo Serralta's avatar Theo Serralta

Program to calculate depth

parent f6409abf
import pysam
def calcul_depth(bamfile, seq, window_size=100):
samfile = pysam.AlignmentFile(bamfile, "rb")
seq_length = samfile.lengths[samfile.references.index(seq)]
for pos_start in range(0, seq_length, window_size):
pos_end = min(pos_start + window_size, seq_length)
window_depths = []
for pileupcolumn in samfile.pileup(seq, start=pos_start, stop=pos_end):
window_depths.append(pileupcolumn.n)
if window_depths:
avg_depth = sum(window_depths) / len(window_depths)
print(f"Profondeur moyenne pour la fenêtre {seq}:{pos_start}-{pos_end}: {avg_depth}")
samfile.close()
bamfile_path = "/home/theo/dev/git/cnvCallerGPU/align.bam"
sequence_of_interest = "chr21"
calcul_depth(bamfile_path, sequence_of_interest, window_size=1000)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment