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

Remove deduplication on strain #33

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
2 changes: 1 addition & 1 deletion ingest/bin/gene-coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def G_and_F_coverage(alignment, indices_G, indices_F):
F_coverage[accession].append(coverages_F.get(accession, 0.00))
genome_coverage[accession].append(coverage_genome.get(accession, 0.00))

metadata_files = ["data/b/metadata_no_covg.tsv", "data/a/metadata_no_covg.tsv"]
metadata_files = ["data/b/metadata_sorted.tsv", "data/a/metadata_sorted.tsv"]
outputs = ["data/b/metadata.tsv", "data/a/metadata.tsv"]

# this part of the script reads the already separated a and b metadata and adds the F and G covg values to the correct row based on accession
Expand Down
8 changes: 4 additions & 4 deletions ingest/bin/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def get_similarity(alignment, reference):
elif a_or_b[record.id]=='B':
b_sequences.append(record)

SeqIO.write(a_sequences, "data/a/sequences_notdedup.fasta","fasta")
SeqIO.write(b_sequences, "data/b/sequences_notdedup.fasta", "fasta")
SeqIO.write(a_sequences, "data/a/sequences.fasta","fasta")
SeqIO.write(b_sequences, "data/b/sequences.fasta", "fasta")

metadata = pd.read_csv("data/metadata.tsv", sep="\t", index_col='accession')
original_columns = metadata.columns
Expand All @@ -71,5 +71,5 @@ def get_similarity(alignment, reference):
columns=original_columns)
b_metadata = pd.DataFrame(data=metadata.loc[metadata['type']=='B'],
columns=original_columns)
a_metadata.to_csv('data/a/metadata_notdedup.tsv', sep="\t")
b_metadata.to_csv('data/b/metadata_notdedup.tsv', sep="\t")
a_metadata.to_csv('data/a/metadata_sorted.tsv', sep="\t")
b_metadata.to_csv('data/b/metadata_sorted.tsv', sep="\t")
37 changes: 6 additions & 31 deletions ingest/workflow/snakemake_rules/sort.smk
Original file line number Diff line number Diff line change
Expand Up @@ -57,48 +57,23 @@ rule sort:
metadata_b = expand("data/b/{time}_metadata.tsv", time=TIME),
metadata_a = expand("data/a/{time}_metadata.tsv", time=TIME)
output:
sequences_a = "data/a/sequences_notdedup.fasta",
metadata_a = "data/a/metadata_notdedup.tsv",
sequences_b = "data/b/sequences_notdedup.fasta",
metadata_b = "data/b/metadata_notdedup.tsv"
sequences_a = "data/a/sequences.fasta",
metadata_a = "data/a/metadata_sorted.tsv",
sequences_b = "data/b/sequences.fasta",
metadata_b = "data/b/metadata_sorted.tsv"
shell:
"""
python bin/sort.py
"""

rule deduplication:
input:
sequences_a = rules.sort.output.sequences_a,
metadata_a = rules.sort.output.metadata_a,
sequences_b = rules.sort.output.sequences_b,
metadata_b = rules.sort.output.metadata_b
output:
dedup_seq_a = "data/a/sequences.fasta",
dedup_metadata_a = "data/a/metadata_no_covg.tsv",
dedup_seq_b = "data/b/sequences.fasta",
dedup_metadata_b = "data/b/metadata_no_covg.tsv"
shell:
"""
seqkit rmdup < {input.sequences_a} > {output.dedup_seq_a}
seqkit rmdup < {input.sequences_b} > {output.dedup_seq_b}

python bin/metadata_dedup.py \
--metadata-original {input.metadata_a} \
--metadata-output {output.dedup_metadata_a}

python bin/metadata_dedup.py \
--metadata-original {input.metadata_b} \
--metadata-output {output.dedup_metadata_b}
"""

rule coverage:
input:
alignment_a = expand("data/a/{time}_sequences.aligned.fasta", time=TIME),
alignment_b = expand("data/b/{time}_sequences.aligned.fasta", time=TIME),
metadata_b = expand("data/b/{time}_metadata.tsv", time=TIME),
metadata_a = expand("data/a/{time}_metadata.tsv", time=TIME),
dedup_metadata_a = rules.deduplication.output.dedup_metadata_a,
dedup_metadata_b = rules.deduplication.output.dedup_metadata_b
sorted_metadata_a = "data/a/metadata_sorted.tsv",
sorted_metadata_b = "data/b/metadata_sorted.tsv"
output:
metadata_a = "data/a/metadata.tsv",
metadata_b = "data/b/metadata.tsv"
Expand Down