Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SPIN
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Andrea Mancini
SPIN
Commits
74c44899
Commit
74c44899
authored
Feb 22, 2026
by
Andrea Mancini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update create_dataset.py
parent
6f18e6f3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
12 deletions
+17
-12
create_dataset.py
create_dataset.py
+17
-12
No files found.
create_dataset.py
View file @
74c44899
...
...
@@ -8,14 +8,11 @@ from pathlib import Path
def
get_sequences_from_fasta
(
header_list
,
fasta_path
):
f
=
open
(
fasta_path
,
'r'
)
with
open
(
fasta_path
,
'r'
)
as
f
:
fasta_txt
=
f
.
read
()
data
=
[(
seq
.
split
()[
0
],
""
.
join
(
seq
.
split
(
'
\n
'
)[
1
:]))
for
seq
in
fasta_txt
.
split
(
'>'
)[
1
:]]
f
.
close
()
founded_seqs
=
([],[])
founded_seqs
=
[[],[]]
for
head_in_file
,
seq
in
data
:
if
head_in_file
in
header_list
:
...
...
@@ -24,7 +21,10 @@ def get_sequences_from_fasta(header_list, fasta_path):
return
founded_seqs
def
get_nodes_at_depth
(
node
,
level
,
node_list
=
[],
curr_level
=
0
):
def
get_nodes_at_depth
(
node
,
level
,
node_list
=
None
,
curr_level
=
0
):
if
node_list
is
None
:
node_list
=
[]
if
(
curr_level
==
level
):
node_list
.
append
(
node
)
...
...
@@ -52,7 +52,12 @@ def define_classes_at_depth(fasta_path, tree: Tree, depth):
def
define_classes_from_list
(
fasta_path
,
tree
:
Tree
,
node_ids_list
,
class_ids
=
None
):
node_list
=
[
tree
.
search_nodes
(
name
=
id
)[
0
]
for
id
in
node_ids_list
]
node_list
=
[]
for
id
in
node_ids_list
:
nodes
=
tree
.
search_nodes
(
name
=
id
)
if
not
nodes
:
raise
ValueError
(
f
"Node {id} not found in tree"
)
node_list
.
append
(
nodes
[
0
])
len_nodes
=
len
(
node_list
)
...
...
@@ -98,7 +103,7 @@ def main(args):
if
depth
is
None
and
len
(
node_list
)
==
0
:
raise
Exception
(
"
Please one between depth and node list is requir
ed"
)
raise
Exception
(
"
Either depth or node_list must be provid
ed"
)
elif
depth
and
len
(
node_list
)
>
0
:
...
...
@@ -107,13 +112,13 @@ def main(args):
tree
=
Tree
(
args
.
tree
)
if
depth
:
if
depth
i
is
not
None
:
class2seqs
=
define_classes_at_depth
(
args
.
ifpath
,
tree
,
depth
)
elif
len
(
node_list
)
>
0
:
class2seqs
=
define_classes_from_list
(
args
.
ifpath
,
tree
,
depth
,
args
.
node_list
,
args
.
class_ids
)
class2seqs
=
define_classes_from_list
(
args
.
ifpath
,
tree
,
node_list
,
args
.
class_ids
)
save_to_csv
(
class2seqs
,
args
.
ofpath
)
...
...
@@ -135,10 +140,10 @@ if __name__ == "__main__":
"--depth"
,
dest
=
"depth"
,
type
=
int
,
default
=
None
,
help
=
"Depth where cutting subtree (clusters) - defining class"
)
parser
.
add_argument
(
"--nodes"
,
dest
=
"node_list"
,
type
=
str
,
default
=
[],
help
=
"Internal Node IDs list of subtrees"
"--nodes"
,
dest
=
"node_list"
,
nargs
=
"+"
,
default
=
[],
help
=
"Internal Node IDs list of subtrees"
)
parser
.
add_argument
(
"--class"
,
dest
=
"class_ids"
,
type
=
str
,
default
=
None
,
help
=
"Class ids associated at same order with nodes (only if passing a node list)"
"--class"
,
dest
=
"class_ids"
,
nargs
=
"+"
,
default
=
None
,
help
=
"Class ids associated at same order with nodes (only if passing a node list)"
)
options
=
parser
.
parse_args
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment