Skip to content

Commit 9899006

Browse files
authored
Merge pull request #13 from galaxy-genome-annotation/dbxrefs
Add dbxrefs methods
2 parents cdcee82 + 130a701 commit 9899006

File tree

6 files changed

+252
-26
lines changed

6 files changed

+252
-26
lines changed

apollo/annotations/__init__.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,134 @@ def update_attribute(self, feature_id, attribute_key, old_value, new_value, orga
338338
data = self._update_data(data, organism, sequence)
339339
return self.post('deleteAttribute', data)
340340

341+
def add_dbxref(self, feature_id, db, accession, organism=None, sequence=None):
342+
"""
343+
Add a dbxref to a feature
344+
345+
:type feature_id: str
346+
:param feature_id: Feature UUID
347+
348+
:type db: str
349+
:param db: DB Name (e.g. PMID)
350+
351+
:type accession: str
352+
:param accession: Accession Value
353+
354+
:type organism: str
355+
:param organism: Organism Common Name
356+
357+
:type sequence: str
358+
:param sequence: Sequence Name
359+
360+
This seems to show two attributes being added, but it behaves like those two are one.
361+
362+
:rtype: dict
363+
:return: A standard apollo feature dictionary ({"features": [{...}]})
364+
"""
365+
data = {
366+
'features': [
367+
{
368+
'uniquename': feature_id,
369+
'dbxrefs': [
370+
{
371+
'db': db,
372+
'accession': accession,
373+
}
374+
]
375+
}
376+
]
377+
}
378+
data = self._update_data(data, organism, sequence)
379+
return self.post('addDbxref', data)
380+
381+
def delete_dbxref(self, feature_id, db, accession, organism=None, sequence=None):
382+
"""
383+
Delete a dbxref from a feature
384+
385+
:type feature_id: str
386+
:param feature_id: Feature UUID
387+
388+
:type db: str
389+
:param db: DB Name (e.g. PMID)
390+
391+
:type accession: str
392+
:param accession: Accession Value
393+
394+
:type organism: str
395+
:param organism: Organism Common Name
396+
397+
:type sequence: str
398+
:param sequence: Sequence Name
399+
400+
:rtype: dict
401+
:return: A standard apollo feature dictionary ({"features": [{...}]})
402+
"""
403+
data = {
404+
'features': [
405+
{
406+
'uniquename': feature_id,
407+
'dbxrefs': [
408+
{
409+
'db': db,
410+
'accession': accession,
411+
}
412+
]
413+
}
414+
]
415+
}
416+
data = self._update_data(data, organism, sequence)
417+
return self.post('deleteDbxref', data)
418+
419+
def update_dbxref(self, feature_id, old_db, old_accession, new_db, new_accession, organism=None, sequence=None):
420+
"""
421+
Delete a dbxref from a feature
422+
423+
:type feature_id: str
424+
:param feature_id: Feature UUID
425+
426+
:type old_db: str
427+
:param old_db: Old DB Name (e.g. PMID)
428+
429+
:type old_accession: str
430+
:param old_accession: Old accession Value
431+
432+
:type new_db: str
433+
:param new_db: New DB Name (e.g. PMID)
434+
435+
:type new_accession: str
436+
:param new_accession: New accession Value
437+
438+
:type organism: str
439+
:param organism: Organism Common Name
440+
441+
:type sequence: str
442+
:param sequence: Sequence Name
443+
444+
:rtype: dict
445+
:return: A standard apollo feature dictionary ({"features": [{...}]})
446+
"""
447+
data = {
448+
'features': [
449+
{
450+
'uniquename': feature_id,
451+
'old_dbxrefs': [
452+
{
453+
'db': old_db,
454+
'accession': old_accession,
455+
}
456+
],
457+
'new_dbxrefs': [
458+
{
459+
'db': new_db,
460+
'accession': new_accession,
461+
}
462+
]
463+
}
464+
]
465+
}
466+
data = self._update_data(data, organism, sequence)
467+
return self.post('deleteDbxref', data)
468+
341469
def get_features(self, organism=None, sequence=None):
342470
"""
343471
Get the features for an organism / sequence
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import click
2+
from arrow.cli import pass_context
3+
from arrow.decorators import custom_exception, dict_output
4+
5+
6+
@click.command('add_dbxref')
7+
@click.argument("feature_id", type=str)
8+
@click.argument("db", type=str)
9+
@click.argument("accession", type=str)
10+
@click.option(
11+
"--organism",
12+
help="Organism Common Name",
13+
type=str
14+
)
15+
@click.option(
16+
"--sequence",
17+
help="Sequence Name",
18+
type=str
19+
)
20+
@pass_context
21+
@custom_exception
22+
@dict_output
23+
def cli(ctx, feature_id, db, accession, organism="", sequence=""):
24+
"""Add a dbxref to a feature
25+
26+
Output:
27+
28+
A standard apollo feature dictionary ({"features": [{...}]})
29+
"""
30+
return ctx.gi.annotations.add_dbxref(feature_id, db, accession, organism=organism, sequence=sequence)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import click
2+
from arrow.cli import pass_context
3+
from arrow.decorators import custom_exception, dict_output
4+
5+
6+
@click.command('delete_dbxref')
7+
@click.argument("feature_id", type=str)
8+
@click.argument("db", type=str)
9+
@click.argument("accession", type=str)
10+
@click.option(
11+
"--organism",
12+
help="Organism Common Name",
13+
type=str
14+
)
15+
@click.option(
16+
"--sequence",
17+
help="Sequence Name",
18+
type=str
19+
)
20+
@pass_context
21+
@custom_exception
22+
@dict_output
23+
def cli(ctx, feature_id, db, accession, organism="", sequence=""):
24+
"""Delete a dbxref from a feature
25+
26+
Output:
27+
28+
A standard apollo feature dictionary ({"features": [{...}]})
29+
"""
30+
return ctx.gi.annotations.delete_dbxref(feature_id, db, accession, organism=organism, sequence=sequence)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import click
2+
from arrow.cli import pass_context
3+
from arrow.decorators import custom_exception, dict_output
4+
5+
6+
@click.command('update_dbxref')
7+
@click.argument("feature_id", type=str)
8+
@click.argument("old_db", type=str)
9+
@click.argument("old_accession", type=str)
10+
@click.argument("new_db", type=str)
11+
@click.argument("new_accession", type=str)
12+
@click.option(
13+
"--organism",
14+
help="Organism Common Name",
15+
type=str
16+
)
17+
@click.option(
18+
"--sequence",
19+
help="Sequence Name",
20+
type=str
21+
)
22+
@pass_context
23+
@custom_exception
24+
@dict_output
25+
def cli(ctx, feature_id, old_db, old_accession, new_db, new_accession, organism="", sequence=""):
26+
"""Delete a dbxref from a feature
27+
28+
Output:
29+
30+
A standard apollo feature dictionary ({"features": [{...}]})
31+
"""
32+
return ctx.gi.annotations.update_dbxref(feature_id, old_db, old_accession, new_db, new_accession, organism=organism, sequence=sequence)

arrow/commands/cmd_annotations.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
import click
22
from arrow.commands.annotations.add_attribute import cli as func0
33
from arrow.commands.annotations.add_comment import cli as func1
4-
from arrow.commands.annotations.add_feature import cli as func2
5-
from arrow.commands.annotations.add_transcript import cli as func3
6-
from arrow.commands.annotations.delete_attribute import cli as func4
7-
from arrow.commands.annotations.delete_feature import cli as func5
8-
from arrow.commands.annotations.delete_sequence_alteration import cli as func6
9-
from arrow.commands.annotations.duplicate_transcript import cli as func7
10-
from arrow.commands.annotations.flip_strand import cli as func8
11-
from arrow.commands.annotations.get_comments import cli as func9
12-
from arrow.commands.annotations.get_feature_sequence import cli as func10
13-
from arrow.commands.annotations.get_features import cli as func11
14-
from arrow.commands.annotations.get_gff3 import cli as func12
15-
from arrow.commands.annotations.get_search_tools import cli as func13
16-
from arrow.commands.annotations.get_sequence_alterations import cli as func14
17-
from arrow.commands.annotations.merge_exons import cli as func15
18-
from arrow.commands.annotations.set_boundaries import cli as func16
19-
from arrow.commands.annotations.set_description import cli as func17
20-
from arrow.commands.annotations.set_longest_orf import cli as func18
21-
from arrow.commands.annotations.set_name import cli as func19
22-
from arrow.commands.annotations.set_readthrough_stop_codon import cli as func20
23-
from arrow.commands.annotations.set_sequence import cli as func21
24-
from arrow.commands.annotations.set_status import cli as func22
25-
from arrow.commands.annotations.set_symbol import cli as func23
26-
from arrow.commands.annotations.set_translation_end import cli as func24
27-
from arrow.commands.annotations.set_translation_start import cli as func25
28-
from arrow.commands.annotations.update_attribute import cli as func26
4+
from arrow.commands.annotations.add_dbxref import cli as func2
5+
from arrow.commands.annotations.add_feature import cli as func3
6+
from arrow.commands.annotations.add_transcript import cli as func4
7+
from arrow.commands.annotations.delete_attribute import cli as func5
8+
from arrow.commands.annotations.delete_dbxref import cli as func6
9+
from arrow.commands.annotations.delete_feature import cli as func7
10+
from arrow.commands.annotations.delete_sequence_alteration import cli as func8
11+
from arrow.commands.annotations.duplicate_transcript import cli as func9
12+
from arrow.commands.annotations.flip_strand import cli as func10
13+
from arrow.commands.annotations.get_comments import cli as func11
14+
from arrow.commands.annotations.get_feature_sequence import cli as func12
15+
from arrow.commands.annotations.get_features import cli as func13
16+
from arrow.commands.annotations.get_gff3 import cli as func14
17+
from arrow.commands.annotations.get_search_tools import cli as func15
18+
from arrow.commands.annotations.get_sequence_alterations import cli as func16
19+
from arrow.commands.annotations.merge_exons import cli as func17
20+
from arrow.commands.annotations.set_boundaries import cli as func18
21+
from arrow.commands.annotations.set_description import cli as func19
22+
from arrow.commands.annotations.set_longest_orf import cli as func20
23+
from arrow.commands.annotations.set_name import cli as func21
24+
from arrow.commands.annotations.set_readthrough_stop_codon import cli as func22
25+
from arrow.commands.annotations.set_sequence import cli as func23
26+
from arrow.commands.annotations.set_status import cli as func24
27+
from arrow.commands.annotations.set_symbol import cli as func25
28+
from arrow.commands.annotations.set_translation_end import cli as func26
29+
from arrow.commands.annotations.set_translation_start import cli as func27
30+
from arrow.commands.annotations.update_attribute import cli as func28
31+
from arrow.commands.annotations.update_dbxref import cli as func29
2932

3033

3134
@click.group()
@@ -60,3 +63,6 @@ def cli():
6063
cli.add_command(func24)
6164
cli.add_command(func25)
6265
cli.add_command(func26)
66+
cli.add_command(func27)
67+
cli.add_command(func28)
68+
cli.add_command(func29)

0 commit comments

Comments
 (0)