Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hecaton
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Wijfjes, Raul
hecaton
Commits
37f542fe
Commit
37f542fe
authored
6 years ago
by
Wijfjes, Raul
Browse files
Options
Downloads
Patches
Plain Diff
Created script that generates site-only vcf
parent
712adaff
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/convert/vcf_to_site_only_vcf.py
+54
-0
54 additions, 0 deletions
scripts/convert/vcf_to_site_only_vcf.py
scripts/filter/filter_ref_sites_vcf.py
+11
-6
11 additions, 6 deletions
scripts/filter/filter_ref_sites_vcf.py
with
65 additions
and
6 deletions
scripts/convert/vcf_to_site_only_vcf.py
0 → 100755
+
54
−
0
View file @
37f542fe
#!/usr/bin/env python3
"""
Convert VCF files to site-only VCF, removing all genotype information
"""
import
argparse
import
sys
from
xopen
import
xopen
def
parse_cl_args
(
in_args
):
"""
Parse command line arguments
:param in_args: All command line arguments
:return: None
"""
description
=
"
Convert VCF file to tabular file
"
parser
=
argparse
.
ArgumentParser
(
description
=
description
)
parser
.
add_argument
(
"
-v
"
,
"
--vcf_fn
"
,
type
=
str
,
help
=
"
File containing path to VCF file
"
)
parser
.
add_argument
(
"
-o
"
,
"
--output_fn
"
,
type
=
str
,
help
=
"
Name of VCF output file
"
)
args
=
parser
.
parse_args
(
in_args
)
return
args
def
vcf_to_site_only_vcf
(
input_fn
,
output_fn
):
"""
Convert VCF files to site-only VCF, removing all genotype information
:param input_fn: Path to VCF file
:param output_fn: Name of VCF output file
:return: 0 (integer)
"""
with
xopen
(
input_fn
)
as
input_file
,
xopen
(
output_fn
,
"
w
"
)
as
output_file
:
for
line
in
input_file
:
# write initial header lines to output file
if
line
.
startswith
(
"
##
"
):
output_file
.
write
(
line
)
else
:
# strip samples from line
output_line
=
'
\t
'
.
join
(
line
.
strip
().
split
()[
0
:
9
])
output_file
.
write
(
output_line
)
output_file
.
write
(
"
\n
"
)
return
0
def
main
():
args
=
parse_cl_args
(
sys
.
argv
[
1
:])
# write VCF fields to tabular output
vcf_to_site_only_vcf
(
args
.
vcf_fn
,
args
.
output_fn
)
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
scripts/filter/filter_ref_sites_vcf.py
+
11
−
6
View file @
37f542fe
#!/usr/bin/env python3
"""
Filter sites in a VCF file for which no variant alleles were found in the samples
Filter sites in a VCF file for which the number of samples carrying a
variant allele goes beyond a user-chosen threshold
"""
import
argparse
...
...
@@ -16,20 +17,24 @@ def parse_cl_args(in_args):
:param in_args: All command line arguments
:return: None
"""
description
=
"
Filter sites in a VCF file for which
no variant alleles were found in the samples
"
description
=
"
Filter sites in a VCF file for which
a minimum number of samples were found carrying a variant allele
"
parser
=
argparse
.
ArgumentParser
(
description
=
description
)
parser
.
add_argument
(
"
-v
"
,
"
--vcf_fn
"
,
type
=
str
,
help
=
"
File containing path to VCF file
"
)
parser
.
add_argument
(
"
-n
"
,
"
--minimum_samples
"
,
type
=
int
,
help
=
"
Minimum number of samples that should carry a variant allele
"
)
parser
.
add_argument
(
"
-o
"
,
"
--output_fn
"
,
type
=
str
,
help
=
"
Name of output file
"
)
args
=
parser
.
parse_args
(
in_args
)
return
args
def
filter_ref_sites
(
input_fn
,
output_fn
):
def
filter_ref_sites
(
input_fn
,
min_samples
,
output_fn
):
"""
Filter sites in a VCF file for which only reference alleles were found in the samples
Filter sites in a VCF file for which the number of samples carrying a
variant allele goes beyond a user-chosen threshold
:param input_fn: Path to VCF file
:param min_samples: Minimum number of samples carrying a variant allele
:param output_fn: Name of VCF output file
:return: 0 (integer)
"""
...
...
@@ -52,14 +57,14 @@ def filter_ref_sites(input_fn, output_fn):
if
genotype
not
in
non_variants
:
var_calls
+=
1
# write record to output if it has variant calls
if
var_calls
>
0
:
if
var_calls
>
min_samples
:
output_file
.
write
(
str
(
record
))
return
0
def
main
():
args
=
parse_cl_args
(
sys
.
argv
[
1
:])
# filter ref sites from input file
filter_ref_sites
(
args
.
vcf_fn
,
args
.
output_fn
)
filter_ref_sites
(
args
.
vcf_fn
,
args
.
minimum_samples
,
args
.
output_fn
)
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment