Skip to content

Instantly share code, notes, and snippets.

@brantfaircloth
Created May 9, 2024 20:04
Show Gist options
  • Save brantfaircloth/acd5dc19b3b65c716f132b510a914ea7 to your computer and use it in GitHub Desktop.
Save brantfaircloth/acd5dc19b3b65c716f132b510a914ea7 to your computer and use it in GitHub Desktop.
Contig coverage from PB.cov
#!/usr/bin/env python
# encoding: utf-8
"""
Created by Brant Faircloth on May 9, 2024 at 14:00:38 CDT
Copyright (c) 2024 Brant C. Faircloth. All rights reserved.
Description:
"""
#import pdb
import numpy
from collections import defaultdict
values = defaultdict(list)
with open("PB.base.cov") as infile:
for line in infile:
ls = line.strip()
if line.startswith(">"):
curr_contig = line.lstrip(">").split("\t")[0]
else:
cov =ls.split("\t")[2]
values[curr_contig].append(int(cov))
for k,v in values.items():
print(k,numpy.mean(v))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment