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

updated rule filter (in merge_samples) #64

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
25 changes: 18 additions & 7 deletions Snakemake/workflow/rules/merge_samples_vcf.smk
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,29 @@ if len(allFiles) != 1:
expand('/{{chromosome}}/{{chromosome}}_{file}.filtered.vcf.{ext}', file=allFiles, ext=['gz', 'gz.csi'])])
params:
duplicated = '{chromosome}.ids'
# conda: 'bcftools'
resources: cpus=1, mem_mb=64000, time_min=60
run:
import os

for file in input:
shell("wc -l {file} >> files_len.txt")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sorts by the number of lines - which is SNPs, not samples. Is this ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is about the number of individuals, correct @gmafrafortuna ? We could probably extract the number of individuals using vcf/bcftools. I also found this awk one-liner: awk '{if ($1 == "#CHROM"){print NF-9; exit}}' input_vcf_file.vcf This looks at the #CHROM line in the vcf file which is the line of the column header (which includes individual names).


shell("sort -s -nr -k 1,1 files_len.txt | cut -d' ' -f 2 > files_reorderd.txt")

with open('files_reorderd.txt', 'r') as file:
files_reord = []
for line in file:
line = line.strip()
files_reord.append(line)

filtered = []

for i in range(len(input)):
for i in range(len(files_reord)):
print(i)
for j, file in enumerate(input):
if file != input[i] and j > i:
file1 = input[i]
file2 = input[j]
for j, file in enumerate(files_reord):
if file != files_reord[i] and j > i:
file1 = files_reord[i]
file2 = files_reord[j]
print(file1, file2)

shell("comm -12 <(sort {file1}) <(sort {file2}) > {params.duplicated}")
Expand All @@ -57,7 +68,7 @@ if len(allFiles) != 1:
shell('bcftools index -f {file2}.filtered.vcf.gz')
shell('rm {params.duplicated}')

for file in input:
for file in files_reord:
if file not in filtered:
file1 = file.split('.')[0]
print(f'file {file1} not filtered')
Expand Down