Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mutalyzer
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
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
Mirrors
mutalyzer
Commits
61ddd6b7
Commit
61ddd6b7
authored
10 years ago
by
Laros
Committed by
Vermaat
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Some more refactoring.
parent
08ecdc5c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mutalyzer/describe.py
+87
-78
87 additions, 78 deletions
mutalyzer/describe.py
mutalyzer/entrypoints/mutalyzer.py
+11
-11
11 additions, 11 deletions
mutalyzer/entrypoints/mutalyzer.py
with
98 additions
and
89 deletions
mutalyzer/describe.py
+
87
−
78
View file @
61ddd6b7
...
...
@@ -212,15 +212,14 @@ class Seq(object):
class
SeqList
(
list
):
def
__str__
(
self
):
representation
=
'
;
'
.
join
(
map
(
str
,
self
))
if
len
(
self
)
>
1
:
return
"
[{}]
"
.
format
(
representation
)
return
representation
return
"
[{}]
"
.
format
(
'
;
'
.
join
(
map
(
str
,
self
))
)
return
str
(
self
[
0
])
#__str__
#SeqList
class
HGVSVar
(
object
):
# NOTE: This may be obsolete, but check the JSON generation.
def
update
(
self
):
self
.
hgvs
=
str
(
self
)
self
.
hgvs_length
=
len
(
self
)
...
...
@@ -321,6 +320,7 @@ class DNAVar(models.DNAVar, HGVSVar):
variant stored in this class.
:rtype: int
"""
# NOTE: Obsolete?
if
self
.
type
in
(
"
none
"
,
"
unknown
"
):
# `=' or `?'
return
1
...
...
@@ -434,6 +434,7 @@ class ProteinVar(models.ProteinVar, HGVSVar):
variant stored in this class.
:rtype: int
"""
# NOTE: Obsolete?
if
not
self
.
start
:
# =
return
1
...
...
@@ -477,6 +478,7 @@ class Allele(list):
:rtype: int
"""
# NOTE: Do we need to count the ; and [] ?
# NOTE: Obsolete?
return
sum
(
map
(
lambda
x
:
x
.
hgvs_length
,
self
))
#length
#Allele
...
...
@@ -571,7 +573,7 @@ def var_to_rawvar(s1, s2, var, seq_list=[], container=DNAVar):
sample_end
=
var
.
sample_end
)
#var_to_rawvar
def
describe
(
s1
,
s2
,
dna
=
True
):
def
describe
_dna
(
s1
,
s2
):
"""
Give an allele description of the change from {s1} to {s2}.
...
...
@@ -584,84 +586,91 @@ def describe(s1, s2, dna=True):
:rtype: list(RawVar)
"""
description
=
Allele
()
in_transposition
=
0
for
variant
in
extractor
.
extract
(
str
(
s1
),
len
(
s1
),
str
(
s2
),
len
(
s2
),
0
):
print
(
variant
.
type
,
variant
.
reference_start
,
variant
.
reference_end
,
variant
.
sample_start
,
variant
.
sample_end
,
variant
.
transposition_start
,
variant
.
transposition_end
)
print
(
variant
.
type
&
extractor
.
TRANSPOSITION_OPEN
,
variant
.
type
&
extractor
.
TRANSPOSITION_CLOSE
)
if
variant
.
type
&
extractor
.
TRANSPOSITION_OPEN
:
if
not
in_transposition
:
seq_list
=
SeqList
()
in_transposition
+=
1
#if
if
not
dna
:
fs1
,
fs2
=
make_fs_tables
(
1
)
longest_fs_f
=
max
(
find_fs
(
s1
,
s2
,
fs1
),
find_fs
(
s1
,
s2
,
fs2
))
longest_fs_r
=
max
(
find_fs
(
s2
,
s1
,
fs1
),
find_fs
(
s2
,
s1
,
fs2
))
if
longest_fs_f
>
longest_fs_r
:
print
s1
[:
longest_fs_f
[
1
]],
s1
[
longest_fs_f
[
1
]:]
print
s2
[:
len
(
s2
)
-
longest_fs_f
[
0
]],
\
s2
[
len
(
s2
)
-
longest_fs_f
[
0
]:]
s1_part
=
s1
[:
longest_fs_f
[
1
]]
s2_part
=
s2
[:
len
(
s2
)
-
longest_fs_f
[
0
]]
term
=
longest_fs_f
[
0
]
if
in_transposition
:
if
variant
.
type
&
extractor
.
IDENTITY
:
seq_list
.
append
(
Seq
(
start
=
variant
.
transposition_start
+
1
,
end
=
variant
.
transposition_end
,
reverse
=
False
))
elif
variant
.
type
&
extractor
.
REVERSE_COMPLEMENT
:
seq_list
.
append
(
Seq
(
start
=
variant
.
transposition_start
+
1
,
end
=
variant
.
transposition_end
,
reverse
=
True
))
else
:
seq_list
.
append
(
Seq
(
sequence
=
s2
[
variant
.
sample_start
:
variant
.
sample_end
]))
#if
else
:
print
s1
[:
len
(
s1
)
-
longest_fs_r
[
0
]],
\
s1
[
len
(
s1
)
-
longest_fs_r
[
0
]:]
print
s2
[:
longest_fs_r
[
1
]],
s2
[
longest_fs_r
[
1
]:]
s1_part
=
s1
[:
len
(
s1
)
-
longest_fs_r
[
0
]]
s2_part
=
s2
[:
longest_fs_r
[
1
]]
term
=
len
(
s2
)
-
longest_fs_r
[
1
]
#else
s1_part
=
s1
s2_part
=
s2
for
variant
in
extractor
.
extract
(
unicode
(
s1_part
),
len
(
s1_part
),
unicode
(
s2_part
),
len
(
s2_part
),
1
):
description
.
append
(
var_to_rawvar
(
s1
,
s2
,
variant
,
container
=
ProteinVar
))
if
description
:
description
[
-
1
].
term
=
term
+
2
description
[
-
1
].
update
()
elif
not
(
variant
.
type
&
extractor
.
IDENTITY
):
description
.
append
(
var_to_rawvar
(
s1
,
s2
,
variant
))
if
variant
.
type
&
extractor
.
TRANSPOSITION_CLOSE
:
in_transposition
-=
1
if
not
in_transposition
:
description
.
append
(
var_to_rawvar
(
s1
,
s2
,
variant
,
seq_list
))
#if
#for
return
description
#describe_dna
def
describe_protein
(
s1
,
s2
):
"""
Give an allele description of the change from {s1} to {s2}.
:arg s1: Sequence 1.
:type s1: str
:arg s2: Sequence 2.
:type s2: str
:returns: A list of RawVar objects, representing the allele.
:rtype: list(RawVar)
"""
description
=
Allele
()
fs1
,
fs2
=
make_fs_tables
(
1
)
longest_fs_f
=
max
(
find_fs
(
s1
,
s2
,
fs1
),
find_fs
(
s1
,
s2
,
fs2
))
longest_fs_r
=
max
(
find_fs
(
s2
,
s1
,
fs1
),
find_fs
(
s2
,
s1
,
fs2
))
if
longest_fs_f
>
longest_fs_r
:
print
s1
[:
longest_fs_f
[
1
]],
s1
[
longest_fs_f
[
1
]:]
print
s2
[:
len
(
s2
)
-
longest_fs_f
[
0
]],
s2
[
len
(
s2
)
-
longest_fs_f
[
0
]:]
s1_part
=
s1
[:
longest_fs_f
[
1
]]
s2_part
=
s2
[:
len
(
s2
)
-
longest_fs_f
[
0
]]
term
=
longest_fs_f
[
0
]
#if
else
:
# DNA description extraction, the only thing that `works'.
in_transposition
=
0
for
variant
in
extractor
.
extract
(
unicode
(
s1
),
len
(
s1
),
unicode
(
s2
),
len
(
s2
),
0
):
print
variant
.
type
,
variant
.
reference_start
,
variant
.
reference_end
,
variant
.
sample_start
,
variant
.
sample_end
,
variant
.
transposition_start
,
variant
.
transposition_end
print
variant
.
type
&
extractor
.
TRANSPOSITION_OPEN
,
variant
.
type
&
extractor
.
TRANSPOSITION_CLOSE
if
variant
.
type
&
extractor
.
TRANSPOSITION_OPEN
:
if
not
in_transposition
:
seq_list
=
SeqList
()
in_transposition
+=
1
#if
if
in_transposition
:
if
variant
.
type
&
extractor
.
IDENTITY
:
seq_list
.
append
(
Seq
(
#reference=s1,
start
=
variant
.
transposition_start
+
1
,
end
=
variant
.
transposition_end
,
reverse
=
False
))
elif
variant
.
type
&
extractor
.
REVERSE_COMPLEMENT
:
seq_list
.
append
(
Seq
(
#reference=s1,
start
=
variant
.
transposition_start
+
1
,
end
=
variant
.
transposition_end
,
reverse
=
True
))
else
:
seq_list
.
append
(
Seq
(
sequence
=
s2
[
variant
.
sample_start
:
variant
.
sample_end
]))
#if
elif
not
(
variant
.
type
&
extractor
.
IDENTITY
):
description
.
append
(
var_to_rawvar
(
s1
,
s2
,
variant
))
if
variant
.
type
&
extractor
.
TRANSPOSITION_CLOSE
:
in_transposition
-=
1
if
not
in_transposition
:
description
.
append
(
var_to_rawvar
(
s1
,
s2
,
variant
,
seq_list
))
#for i in seq_list:
# print i.dump()
#if
#for
else
:
print
s1
[:
len
(
s1
)
-
longest_fs_r
[
0
]],
s1
[
len
(
s1
)
-
longest_fs_r
[
0
]:]
print
s2
[:
longest_fs_r
[
1
]],
s2
[
longest_fs_r
[
1
]:]
s1_part
=
s1
[:
len
(
s1
)
-
longest_fs_r
[
0
]]
s2_part
=
s2
[:
longest_fs_r
[
1
]]
term
=
len
(
s2
)
-
longest_fs_r
[
1
]
#else
# Nothing happened.
if
not
description
:
return
Allele
(
RawVar
())
s1_part
=
s1
s2_part
=
s2
for
variant
in
extractor
.
extract
(
str
(
s1_part
),
len
(
s1_part
),
str
(
s2_part
),
len
(
s2_part
),
1
):
description
.
append
(
var_to_rawvar
(
s1
,
s2
,
variant
,
container
=
ProteinVar
))
if
description
:
description
[
-
1
].
term
=
term
+
2
description
[
-
1
].
update
()
#if
return
description
#describe
#describe
_protein
This diff is collapsed.
Click to expand it.
mutalyzer/entrypoints/mutalyzer.py
+
11
−
11
View file @
61ddd6b7
...
...
@@ -100,28 +100,28 @@ def check_name(description):
reference_sequence
=
O
.
getIndexedOutput
(
"
original
"
,
0
)
sample_sequence
=
O
.
getIndexedOutput
(
"
mutated
"
,
0
)
extract
ed_allele
=
describe
.
describe
(
reference_sequence
,
describ
ed_allele
=
describe
.
describe
_dna
(
reference_sequence
,
sample_sequence
)
#
extract
ed_protein_allele = describe.describe(
#
describ
ed_protein_allele = describe.describe(
# O.getIndexedOutput("oldprotein", 0),
# O.getIndexedOutput("newprotein", 0, default=""),
# DNA=False)
extract
ed_protein_allele
=
""
describ
ed_protein_allele
=
""
extracted
=
extract
ed_protein
=
'
(skipped)
'
described
=
describ
ed_protein
=
'
(skipped)
'
if
extract
ed_allele
:
extracted
=
extract
ed_allele
if
extract
ed_protein_allele
:
extract
ed_protein
=
extract
ed_protein_allele
if
describ
ed_allele
:
described
=
describ
ed_allele
if
describ
ed_protein_allele
:
describ
ed_protein
=
describ
ed_protein_allele
print
"
\n
Experimental services:
"
print
extract
ed
print
extract
ed_protein
print
describ
ed
print
describ
ed_protein
#print "+++ %s" % O.getOutput("myTranscriptDescription")
print
json
.
dumps
({
"
reference_sequence
"
:
reference_sequence
,
"
sample_sequence
"
:
sample_sequence
,
"
allele_description
"
:
extract
ed_allele
},
cls
=
MyEncoder
)
describ
ed_allele
},
cls
=
MyEncoder
)
def
main
():
...
...
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