Skip to content

Commit

Permalink
feat!: Use only a single minimum coverage level
Browse files Browse the repository at this point in the history
  • Loading branch information
KHajji committed Apr 14, 2022
1 parent d156599 commit cdd29b7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 51 deletions.
26 changes: 13 additions & 13 deletions TrueConsense/Outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from .Sequences import BuildConsensus


def WriteGFF(gffheader, gffdict, outdir, name, cov):
with open(f"{outdir}/{name}_cov_ge_{cov}.gff", "w") as out:
def WriteGFF(gffheader, gffdict, outdir, name):
with open(f"{outdir}/{name}.gff", "w") as out:
out.write(gffheader)

for k, v in gffdict.items():
Expand All @@ -24,7 +24,7 @@ def WriteGFF(gffheader, gffdict, outdir, name, cov):


def WriteOutputs(
cov,
mincov,
iDict,
uGffDict,
inputbam,
Expand All @@ -44,16 +44,16 @@ def WriteOutputs(
today = date.today().strftime("%Y%m%d")

bam = Readbam(inputbam)
consensus, newgff = BuildConsensus(cov, iDict, uGffDict, IncludeAmbig, bam, True)
consensus_noinsert = BuildConsensus(cov, iDict, uGffDict, IncludeAmbig, bam, False)[
0
]
consensus, newgff = BuildConsensus(mincov, iDict, uGffDict, IncludeAmbig, bam, True)
consensus_noinsert = BuildConsensus(
mincov, iDict, uGffDict, IncludeAmbig, bam, False
)[0]

if gffout is not None:
WriteGFF(gffheader, newgff, gffout, name, cov)
WriteGFF(gffheader, newgff, gffout, name)

if WriteVCF is not None:
hasinserts, insertpositions = ListInserts(iDict, cov, bam)
hasinserts, insertpositions = ListInserts(iDict, mincov, bam)

q = 0
for record in SeqIO.parse(ref, "fasta"):
Expand All @@ -65,7 +65,7 @@ def WriteOutputs(

seqlist = list(consensus_noinsert.upper())

with open(f"{os.path.abspath(WriteVCF)}/{name}_cov_ge_{cov}.vcf", "w") as out:
with open(f"{os.path.abspath(WriteVCF)}/{name}.vcf", "w") as out:
out.write(
f"""##fileformat=VCFv4.3
##fileDate={today}
Expand Down Expand Up @@ -117,7 +117,7 @@ def WriteOutputs(
for lposition in insertpositions:
if i == lposition:
currentcov = GetCoverage(iDict, i + 1)
if currentcov > cov:
if currentcov > mincov:
for y in insertpositions.get(lposition):
to_insert = str(
insertpositions.get(lposition).get(y)
Expand All @@ -130,5 +130,5 @@ def WriteOutputs(
else:
continue

with open(f"{os.path.abspath(outdir)}/{name}_cov_ge_{cov}.fa", "w") as out:
out.write(f">{name}_cov_ge_{cov}\n{consensus}\n")
with open(f"{os.path.abspath(outdir)}/{name}.fa", "w") as out:
out.write(f">{name} mincov={mincov}\n{consensus}\n")
74 changes: 36 additions & 38 deletions TrueConsense/TrueConsense.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,12 @@ def currentpath():
)

reqs.add_argument(
"--coverage-levels",
"--coverage-level",
"-cov",
type=int,
nargs="+",
default=1,
metavar="1 5 10",
help="List of one or multiple 'levels' that will be used as the minimum coverage",
default=30,
metavar="100",
help="The minimum coverage level of the consensus and variant calls",
required=True,
)

Expand Down Expand Up @@ -251,9 +250,8 @@ def main():
elif args.noambiguity is True:
IncludeAmbig = False

parallel(
WriteOutputs,
args.coverage_levels,
WriteOutputs(
args.coverage_level,
indexDict,
GffDict,
args.input,
Expand All @@ -268,33 +266,33 @@ def main():
)


def parallel(
function,
covlist,
indexDict,
GffDict,
inputbam,
IncludeAmbig,
WriteVCF,
name,
ref,
gffoutdir,
gffheader,
outdir,
workers,
):
parmap.map(
function,
covlist,
indexDict,
GffDict,
inputbam,
IncludeAmbig,
WriteVCF,
name,
ref,
gffoutdir,
gffheader,
outdir,
pm_processes=workers,
)
# def parallel(
# function,
# covlist,
# indexDict,
# GffDict,
# inputbam,
# IncludeAmbig,
# WriteVCF,
# name,
# ref,
# gffoutdir,
# gffheader,
# outdir,
# workers,
# ):
# parmap.map(
# function,
# covlist,
# indexDict,
# GffDict,
# inputbam,
# IncludeAmbig,
# WriteVCF,
# name,
# ref,
# gffoutdir,
# gffheader,
# outdir,
# pm_processes=workers,
# )

0 comments on commit cdd29b7

Please sign in to comment.