Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CIHEAM
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
Derks, Martijn
CIHEAM
Commits
74ff090f
Commit
74ff090f
authored
10 years ago
by
Megens, Hendrik-Jan
Browse files
Options
Downloads
Patches
Plain Diff
helper scripts
parent
e5576dc2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
print_fields_from_vcf.py
+14
-0
14 additions, 0 deletions
print_fields_from_vcf.py
with
14 additions
and
0 deletions
print_fields_from_vcf.py
+
14
−
0
View file @
74ff090f
...
...
@@ -11,8 +11,21 @@ parser.add_argument("-m", "--method", help="annotation method", type=str, choice
def
vcfelements
(
line
):
# parse the main, tab-delimited elements of the VCF line
vcf_elements
=
line
.
split
(
'
\t
'
)
vcf_elements
[
7
]
=
tagelements
(
vcf_elements
[
7
])
if
len
(
vcf_elements
)
>
9
:
# check if genotype fields present; this requires at least 2 additional columns
vcf_elements
=
list_genotypes
(
vcf_elements
)
else
:
vcf_elements
.
append
([])
# make sure that the data structure is allways of lenth 9
return
vcf_elements
# return list
def
list_genotypes
(
vcflist
):
# reshape the genotypes to a single list
genotypes
=
vcflist
[
9
:]
gt_field
=
list
()
gt_field
.
append
(
vcflist
[
8
])
gt_field
.
append
(
genotypes
)
vcflist
=
vcflist
[
0
:
8
]
vcflist
.
append
(
gt_field
)
return
vcflist
def
tagelements
(
tag
):
# parse the fields/tags in the 8th column - ';' delimited
tags
=
tag
.
split
(
'
;
'
)
tagdict
=
{
tag
.
split
(
'
=
'
)[
0
]:
tag
.
split
(
'
=
'
)[
1
]
for
tag
in
tags
}
...
...
@@ -73,6 +86,7 @@ if __name__=="__main__":
myline
=
myline
[:
-
1
]
if
not
myline
.
startswith
(
'
#
'
):
# avoid VCF comment lines
vcf_line
=
vcfelements
(
myline
)
print
(
vcf_line
)
print_by_method
(
vcf_line
,
method
)
except
(
BrokenPipeError
,
IOError
):
# exception handling for BrokenPipeError; works in P3.3, not P3.4! Need this workaround
sys
.
stdout
.
write
=
_void_f
...
...
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