Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
a4a7dd43
Commit
a4a7dd43
authored
13 years ago
by
kohleman
Browse files
Options
Downloads
Patches
Plain Diff
added percentage calculation
SVN: 21826
parent
4bda36e0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
deep_sequencing_unit/source/Python/filterOnQualityForFastqGzip.py
+17
-10
17 additions, 10 deletions
...uencing_unit/source/Python/filterOnQualityForFastqGzip.py
with
17 additions
and
10 deletions
deep_sequencing_unit/source/Python/filterOnQualityForFastqGzip.py
+
17
−
10
View file @
a4a7dd43
#!/usr/
bin
/python
#!/usr/
local/dsu/Python-3.2
/python
'''
Usage: python filter
OnQ
uality
ForFastqG
zip.py <fastqfile
.gz
>
Usage: python filter
_on_q
uality
_for_g
zip.py <fastqfile>
o
Reqires bcltofastq converted gzipped fastq file which are generated
by the Illumina pipeline Casava 1.8+
Calculates the amount of chastity filtered reads in a gzipped fastq file
@author: Manuel Kohler
@copyright: ETH Zurich
@precondition: gzip
, python 3.2
@precondition: gzip
'''
import
gzip
...
...
@@ -18,8 +17,12 @@ import argparse
def
parseCommandLine
():
parser
=
argparse
.
ArgumentParser
(
description
=
'
Counts the filtered and
'
+
'
non-filtered read of a gzipped fastq file
'
)
parser
.
add_argument
(
'
-
f
'
,
'
--file
'
,
dest
=
'
fastq_file
'
,
action
=
'
store
'
,
parser
.
add_argument
(
'
-
i
'
,
'
--
input_
file
'
,
dest
=
'
fastq_file
'
,
action
=
'
store
'
,
required
=
True
,
help
=
'
Which fastq.gz file you want to process?
'
)
parser
.
add_argument
(
'
-o
'
,
'
--output
'
,
dest
=
'
output
'
,
action
=
'
store
'
,
default
=
'
fastq_stats
'
,
type
=
str
,
help
=
'
Output file name
'
)
parser
.
add_argument
(
'
-f
'
,
'
--format
'
,
dest
=
'
format
'
,
action
=
'
store
'
,
default
=
'
txt
'
,
type
=
str
,
choices
=
[
'
txt
'
,
'
json
'
,
'
both
'
],
help
=
'
Output format
'
)
args
=
parser
.
parse_args
()
return
(
args
)
...
...
@@ -27,11 +30,13 @@ def parseCommandLine():
line_number
=
1
new_line
=
1
is_filtered
=
0
width
=
20
def
formatNumber
(
n
):
return
(
'
{:>20}
'
.
format
(
'
{:,}
'
.
format
(
n
)))
def
calulatePercentage
(
v1
,
v2
):
return
round
(
100
*
(
v1
/
(
v1
+
v2
)),
2
)
args
=
parseCommandLine
()
with
gzip
.
open
(
args
.
fastq_file
,
'
rb
'
)
as
file
:
...
...
@@ -40,12 +45,14 @@ with gzip.open(args.fastq_file, 'rb') as file:
# fastq quadruples
new_line
=
line_number
+
4
l
=
line
.
decode
(
'
utf8
'
)
#print(l.split(':')[7])
if
(
l
.
split
(
'
:
'
)[
7
]
==
'
Y
'
):
is_filtered
+=
1
line_number
+=
1
print
(
'
File:
'
+
args
.
fastq_file
)
unfiltered
=
((
line_number
-
1
)
/
4
)
-
is_filtered
print
(
str
(
formatNumber
(
is_filtered
))
+
'
Number of filtered reads (BAD)
'
)
print
(
str
(
formatNumber
(
int
(
unfiltered
)))
+
'
Number of non-filtered reads (GOOD)
'
)
print
(
'
\n
'
)
print
(
'
File:
'
+
args
.
fastq_file
)
print
(
str
(
formatNumber
(
int
(
unfiltered
)))
+
'
number of non-filtered reads (GOOD)
'
)
print
(
str
(
formatNumber
(
is_filtered
))
+
'
number of filtered reads (BAD)
'
)
print
(
str
(
formatNumber
(
calulatePercentage
(
unfiltered
,
is_filtered
)))
+
'
% of non-filtered reads (GOOD)
'
)
print
(
str
(
formatNumber
(
calulatePercentage
(
is_filtered
,
unfiltered
)))
+
'
% of filtered reads (BAD)
'
)
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