Skip to content

Commit

Permalink
added rotate column in table
Browse files Browse the repository at this point in the history
  • Loading branch information
farchaab committed Oct 25, 2024
1 parent 9af1fae commit b5fa3a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions mess/workflow/scripts/calculate_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_even_dist(table):
df["tax_abundance"] = df["proportion"] / df["count"]
df["genome_bases"] = df["total_sequence_length"] * df["tax_abundance"]
df["sum_genome_bases"] = df.groupby("samplename")["genome_bases"].transform("sum")
df["cov_obtained"] = bases / df["sum_genome_bases"]
df["cov_obtained"] = bases / df["sum_genome_bases"]
df["cov_sim"] = df["tax_abundance"] * df["cov_obtained"]
df["sum_cov"] = df.groupby("samplename")["cov_sim"].transform("sum")
df["bases"] = df["cov_sim"] * df["total_sequence_length"]
Expand All @@ -117,7 +117,7 @@ def get_even_dist(table):
df["sum_genome_bases"] = df.groupby("samplename")["genome_bases"].transform(
"sum"
)
df["cov_obtained"] = bases / df["sum_genome_bases"]
df["cov_obtained"] = bases / df["sum_genome_bases"]
df["cov_sim"] = df["tax_abundance"] * df["cov_obtained"]
df["sum_cov"] = df.groupby("samplename")["cov_sim"].transform("sum")
df["bases"] = df["cov_sim"] * df["total_sequence_length"]
Expand Down Expand Up @@ -173,6 +173,8 @@ def get_even_dist(table):
"tax_abundance",
"seed",
]
if "rotate" in entry_df.columns:
cols.append("rotate")

df["reads"] = df["reads"].apply(lambda x: int(round(x)))
df["bases"] = df["bases"].apply(lambda x: int(round(x)))
Expand All @@ -182,4 +184,4 @@ def get_even_dist(table):
df = df.astype(
{"seed": int, "tax_id": int, "total_sequence_length": int, "number_of_contigs": int}
)
df[cols].set_index(["samplename", "fasta"]).to_csv(snakemake.output[0], sep="\t") # type: ignore
df[cols].to_csv(snakemake.output[0], sep="\t", index=False) # type: ignore
12 changes: 6 additions & 6 deletions mess/workflow/scripts/split_contigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ def split_fasta(fa, outdir):

cols = ["samplename", "fasta", "contig", "contig_length", "tax_id", "seed", "cov_sim"]

if snakemake.params.rotate > 1:
cols += ["n", "random_start"]
if snakemake.params.circular:
cols += ["n", "random_start", "rotate"]
if "rotate" not in df.columns:
df.loc[:, "rotate"] = [snakemake.params.rotate] * len(df)
df["random_start"] = df.apply(
lambda row: get_random_start(
row["seed"], row["contig_length"], snakemake.params.rotate
),
lambda row: get_random_start(row["seed"], row["contig_length"], row["rotate"]),
axis=1,
)
df_expanded = df.explode("random_start").reset_index(drop=True)
df_expanded["n"] = df_expanded.groupby(["samplename", "contig"]).cumcount() + 1
df = df_expanded
df["cov_sim"] = df["cov_sim"] / snakemake.params.rotate
df["cov_sim"] = df["cov_sim"] / df["rotate"]

df[cols].to_csv(snakemake.output.tsv, sep="\t", index=False)

0 comments on commit b5fa3a8

Please sign in to comment.