Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scRNA-seq-simulation
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
zavolan_group
pipelines
scRNA-seq-simulation
Commits
cd2c8690
Commit
cd2c8690
authored
3 years ago
by
Reto Tschannen
Browse files
Options
Downloads
Patches
Plain Diff
chore: removed print line
parent
58561bde
No related branches found
No related tags found
1 merge request
!13
feat: add function to calculate mean and variance
Pipeline
#13635
failed
3 years ago
Stage: qc
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mean-variance-function.py
+8
-10
8 additions, 10 deletions
src/mean-variance-function.py
with
8 additions
and
10 deletions
src/mean-variance-function.py
+
8
−
10
View file @
cd2c8690
...
...
@@ -23,29 +23,29 @@ def mean_variance(filepath):
raise
ValueError
(
'
No files in directory:
'
,
filepath
)
# Creates all required dictionaries to cinstruct the mean, variance
nog
=
{}
gene_counts
=
{}
occurence
=
{}
individual_values
=
{}
mean
=
{}
variance
=
{}
# Added together all gene counts in
nog
, and occurence in occurence
# Added together all gene counts in
gene_counts
, and occurence in occurence
for
file_name
in
files
:
with
io
.
open
(
file_name
,
'
r
'
)
as
fh
:
for
line
in
fh
:
geneid
,
copies
=
str
(
line
.
split
()[
0
]),
int
(
line
.
split
()[
1
])
if
geneid
not
in
nog
:
nog
[
geneid
]
=
copies
if
geneid
not
in
gene_counts
:
gene_counts
[
geneid
]
=
copies
occurence
[
geneid
]
=
1
individual_values
[
geneid
]
=
[
copies
]
else
:
nog
[
geneid
]
+=
copies
gene_counts
[
geneid
]
+=
copies
occurence
[
geneid
]
+=
1
individual_values
[
geneid
]
+=
[
copies
]
# Calculate mean of each gene
for
i
in
nog
:
mean
[
i
]
=
nog
[
i
]
/
occurence
[
i
]
for
i
in
gene_counts
:
mean
[
i
]
=
gene_counts
[
i
]
/
occurence
[
i
]
# Calculate the variance
for
i
in
individual_values
:
...
...
@@ -65,12 +65,10 @@ def mean_variance(filepath):
with
open
(
os
.
path
.
expanduser
(
"
~
"
)
+
'
/results_mean_var_function.csv
'
,
'
w
'
)
as
csv_file
:
filewriter
=
csv
.
writer
(
csv_file
,
delimiter
=
'
,
'
,
quotechar
=
'
|
'
,
quoting
=
csv
.
QUOTE_MINIMAL
)
filewriter
.
writerow
([
'
geneid
'
,
'
mean
'
,
'
variance
'
])
for
id
in
nog
.
keys
():
for
id
in
gene_counts
.
keys
():
filewriter
.
writerow
([
id
,
mean
[
id
],
variance
[
id
]])
return
os
.
path
.
expanduser
(
"
~
"
)
+
'
/results_mean_var_function.csv
'
print
(
mean_variance
(
'
/home/reto/2021_project_folder/2021_test/*
'
))
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