Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nested
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Matej Lexa
nested
Commits
c600325b
There was an error fetching the commit references. Please try again later.
Commit
c600325b
authored
7 years ago
by
rlapar
Browse files
Options
Downloads
Patches
Plain Diff
generator
parent
38027b64
No related branches found
No related tags found
1 merge request
!8
Generator
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
nested/core/generator.py
+59
-0
59 additions, 0 deletions
nested/core/generator.py
nested/core/te.py
+1
-1
1 addition, 1 deletion
nested/core/te.py
nested/utils/intervals.py
+6
-6
6 additions, 6 deletions
nested/utils/intervals.py
with
67 additions
and
7 deletions
.gitignore
+
1
−
0
View file @
c600325b
*.pyc
python/*.pyc
data
tmp
This diff is collapsed.
Click to expand it.
nested/core/generator.py
0 → 100644
+
59
−
0
View file @
c600325b
#!/usr/bin/env python3
import
random
from
Bio
import
SeqIO
from
Bio.SeqRecord
import
SeqRecord
from
nested.core.te
import
TE
from
nested.core.nested_element
import
NestedElement
from
nested.utils
import
intervals
class
Generator
(
object
):
"""
Class used to generate artificial nested elements for testing purposes
Attributes:
sourceFile (str): path to source database of TE
'
s in fasta format
"""
def
__init__
(
self
,
source_db
):
self
.
_source_db
=
source_db
self
.
elements
=
[]
def
generate_random_nested_element
(
self
,
baselength
=
0
,
number_of_iterations
=
1
,
filter_string
=
'
LTR
'
):
sequences
=
list
(
SeqIO
.
parse
(
open
(
self
.
_source_db
),
'
fasta
'
))
sequences
=
list
(
filter
(
lambda
x
:
filter_string
in
x
.
id
,
sequences
))
#random initial sequence
element_sequence
=
''
.
join
([
random
.
choice
(
'
atgc
'
)
for
x
in
range
(
baselength
)])
nested_intervals
=
[[
0
,
len
(
element_sequence
)
-
1
]]
for
i
in
range
(
number_of_iterations
):
chosen_id
=
random
.
randint
(
0
,
len
(
sequences
)
-
1
)
chosen_seq
=
sequences
[
chosen_id
].
seq
#print('Chosen sequence ({}) with length {}'.format(sequences[chosen_id].id, len(chosen_seq)))
insert_position
=
random
.
randint
(
0
,
len
(
element_sequence
)
-
1
)
nested_intervals
=
[[
insert_position
,
insert_position
+
len
(
chosen_seq
)
-
1
]]
+
nested_intervals
element_sequence
=
element_sequence
[:
insert_position
]
+
chosen_seq
+
element_sequence
[
insert_position
:]
#expand intervals
nested_intervals
=
intervals
.
expand_list
(
nested_intervals
)
nested_tes
=
[]
for
interval
in
nested_intervals
:
nested_tes
.
append
(
TE
(
location
=
interval
))
element_id
=
'
GENERATED_{}
'
.
format
(
len
(
self
.
elements
)
+
1
)
element
=
NestedElement
(
element_id
,
element_sequence
,
nested_tes
)
self
.
elements
.
append
(
element
)
def
generate_random_nested_elements
(
self
,
number_of_elements
=
1
,
baselength
=
0
,
number_of_iterations
=
1
,
filter_string
=
'
LTR
'
):
for
i
in
range
(
number_of_elements
):
self
.
generate_random_nested_element
(
baselength
=
baselength
,
number_of_iterations
=
number_of_iterations
,
filter_string
=
filter_string
)
def
save_elements_to_fasta
(
self
,
filepath
):
sequences
=
[
SeqRecord
(
x
.
sequence
,
id
=
x
.
id
,
description
=
''
)
for
x
in
self
.
elements
]
with
open
(
filepath
,
'
w
'
)
as
output_handle
:
SeqIO
.
write
(
sequences
,
output_handle
,
'
fasta
'
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
nested/core/te.py
+
1
−
1
View file @
c600325b
...
...
@@ -20,7 +20,7 @@ class TE(object):
features (dict): dictionary of features assigned to TE (i.e. list of domains on the optimal path in graph)
score (float): evaluated score of TE
"""
def
__init__
(
self
,
ppt
=
None
,
pbs
=
None
,
location
=
None
,
ltr_left_location
=
None
,
ltr_right_location
=
None
,
features
=
None
,
score
=
None
):
def
__init__
(
self
,
ppt
=
None
,
pbs
=
None
,
location
=
None
,
ltr_left_location
=
None
,
ltr_right_location
=
None
,
features
=
{}
,
score
=
None
):
self
.
ppt
=
ppt
self
.
pbs
=
pbs
self
.
location
=
location
...
...
This diff is collapsed.
Click to expand it.
nested/utils/intervals.py
+
6
−
6
View file @
c600325b
...
...
@@ -77,13 +77,13 @@ def expand(source, target):
target
[
1
]
+=
length
return
target
def
expand
L
ist
(
interval
L
ist
):
def
expand
_l
ist
(
interval
_l
ist
):
"""
Expand intervals by the prevoius ones starting from the end
Arguments:
interval
L
ist(list): list of intervals to expand
interval
_l
ist(list): list of intervals to expand
"""
for
i
in
reversed
(
range
(
len
(
intervalList
)
-
1
)):
for
j
in
range
(
i
+
1
,
len
(
intervalList
)):
intervalList
[
j
]
=
expand
(
intervalList
[
i
],
intervalList
[
j
])
return
intervalList
\ No newline at end of file
for
i
in
reversed
(
range
(
len
(
interval_list
)
-
1
)):
for
j
in
range
(
i
+
1
,
len
(
interval_list
)):
interval_list
[
j
]
=
expand
(
interval_list
[
i
],
interval_list
[
j
])
return
interval_list
\ 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