Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ChIA-PET_network
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
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
LBMC
ReGArDS
ChIA-PET_network
Commits
9c206182
Verified
Commit
9c206182
authored
4 months ago
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
script to merge the communities together
parent
426b2bca
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
src/location_pp/merge_nr_communities.py
+48
-0
48 additions, 0 deletions
src/location_pp/merge_nr_communities.py
with
48 additions
and
0 deletions
src/location_pp/merge_nr_communities.py
0 → 100644
+
48
−
0
View file @
9c206182
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Description: The goal of this script is to merge multiple
communities file together and remove redundant clusters, cluster
with the same genes
"""
from
pathlib
import
Path
from
typing
import
List
import
lazyparser
as
lp
import
polars
as
pl
from
loguru
import
logger
from
src.location_pp.config
import
ConfigLocation
def
load_communities
(
files
:
list
[
Path
])
->
pl
.
DataFrame
:
"""
Load communities from files.
"""
df
=
pl
.
concat
(
[
pl
.
read_csv
(
file
,
separator
=
"
\t
"
).
select
(
[
"
community
"
,
"
nodes
"
,
"
genes
"
]
)
for
file
in
files
]
)
row
=
df
.
shape
[
0
]
df
=
df
.
unique
(
subset
=
[
"
genes
"
],
keep
=
"
first
"
)
final
=
df
.
shape
[
0
]
logger
.
info
(
f
"
{
row
-
final
}
/
{
row
}
communities were duplicated and removed
"
)
return
df
@lp.parse
(
files
=
"
file
"
)
def
main_merge
(
files
:
List
[
str
],
outname
:
str
)
->
pl
.
DataFrame
:
"""
Merge communities from files.
"""
df
=
load_communities
([
Path
(
f
)
for
f
in
files
])
df
.
write_csv
(
ConfigLocation
.
output
/
f
"
{
outname
}
.txt
"
,
separator
=
"
\t
"
)
if
__name__
==
"
__main__
"
:
main_merge
()
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