Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Data visualization in R and Python snippets
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Model registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cosmin SAVEANU
Data visualization in R and Python snippets
Commits
81008add
Commit
81008add
authored
3 years ago
by
Cosmin SAVEANU
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
5ebb1d7e
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
PolysomeRider/movingaveragefilter.py
+40
-0
40 additions, 0 deletions
PolysomeRider/movingaveragefilter.py
with
40 additions
and
0 deletions
PolysomeRider/movingaveragefilter.py
0 → 100644
+
40
−
0
View file @
81008add
"""
filter data by averaging on a number of points
input - text file with two tab delimited columns
output - filtered text file
parameter - size of the window
"""
import
sys
INTTRANSFORM
=
1000
if
len
(
sys
.
argv
)
<
4
:
print
"
Three arguments needed: input file name, output file name, window size
"
sys
.
exit
(
0
)
else
:
file_in_name
=
sys
.
argv
[
1
]
file_out_name
=
sys
.
argv
[
2
]
wsize
=
int
(
sys
.
argv
[
3
])
fin
=
open
(
file_in_name
,
"
r
"
)
data
=
[]
for
line
in
fin
:
lst
=
line
.
strip
(
'
\r\n
'
).
split
(
'
\t
'
)
data
.
append
([
int
(
float
(
lst
[
0
])),
int
(
INTTRANSFORM
*
float
(
lst
[
1
]))])
fin
.
close
()
filtdata
=
[]
sum
=
0
prevsum
=
0
for
i
in
range
(
int
(
wsize
/
2
)):
filtdata
.
append
([
data
[
i
][
0
],
data
[
i
][
1
]
/
INTTRANSFORM
])
prevsum
=
prevsum
+
data
[
i
][
1
]
for
i
in
range
(
int
(
wsize
/
2
),
len
(
data
)
-
wsize
/
2
-
1
):
sum
=
prevsum
-
data
[
i
-
wsize
/
2
-
1
][
1
]
+
data
[
i
+
wsize
/
2
][
1
]
prevsum
=
sum
#print sum
filtdata
.
append
([
data
[
i
][
0
],
sum
/
float
(
wsize
)
/
float
(
INTTRANSFORM
)])
fout
=
open
(
file_out_name
,
"
w
"
)
for
line
in
filtdata
:
fout
.
write
(
'
%d
\t
%.3f
\n
'
%
(
line
[
0
],
line
[
1
]))
\ No newline at end of file
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