Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert coverage file to read_count dict #270

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions iss/abundance.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,20 @@ def expand_draft_abundance(abundance_dic, draft, mode="abundance"):
elif mode == "coverage":
draft_dic[record.id] = abundance
return draft_dic


def to_readcount(coverage_dic, read_length, genome_file):
logger = logging.getLogger(__name__)
readcount_dic = {}
f = open(genome_file, "r") # re-opens the file
with f:
fasta_file = SeqIO.parse(f, "fasta")
for record in fasta_file:
try:
record_coverage = coverage_dic[record.id]
except KeyError as e:
logger.warning("Fasta record not found in coverage file: %s" % e)
continue
n_reads = int((record_coverage * len(record.seq)) / read_length)
readcount_dic[record.id] = n_reads
return readcount_dic
6 changes: 4 additions & 2 deletions iss/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,11 @@ def load_readcount_or_abundance(
coverage_dic = abundance.parse_abundance_file(coverage_file)
complete_genomes_dic = {k: v for k, v in coverage_dic.items() if k not in draft}
draft_dic = abundance.expand_draft_abundance(coverage_dic, draft, mode="coverage")
abundance_dic = {**complete_genomes_dic, **draft_dic}
coverage_dic = {**complete_genomes_dic, **draft_dic}
else:
abundance_dic = abundance.parse_abundance_file(coverage_file)
coverage_dic = abundance.parse_abundance_file(coverage_file)
# generate n_reads for each genome from coverage
readcount_dic = abundance.to_readcount(coverage_dic, error_model.read_length, genome_file)
elif coverage in abundance_dispatch:
# todo coverage distribution with --draft
logger.info("Using %s coverage distribution" % coverage)
Expand Down
Loading