cool-seq-tool 0.4.1__py3-none-any.whl → 0.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,126 +0,0 @@
1
- """Module containing default routes"""
2
-
3
- import logging
4
- import os
5
- import tempfile
6
- from pathlib import Path
7
-
8
- from fastapi import APIRouter, HTTPException, Query
9
- from fastapi.responses import FileResponse
10
- from starlette.background import BackgroundTasks
11
-
12
- from cool_seq_tool.routers import (
13
- RESP_DESCR,
14
- SERVICE_NAME,
15
- UNHANDLED_EXCEPTION_MSG,
16
- cool_seq_tool,
17
- )
18
- from cool_seq_tool.schemas import (
19
- GenomicDataResponse,
20
- GenomicRequestBody,
21
- TranscriptRequestBody,
22
- )
23
- from cool_seq_tool.utils import service_meta
24
-
25
- logger = logging.getLogger("cool_seq_tool")
26
-
27
- router = APIRouter(prefix=f"/{SERVICE_NAME}")
28
-
29
-
30
- @router.post(
31
- "/genomic_to_transcript_exon_coordinates",
32
- summary="Get transcript exon data given genomic coordinate data",
33
- response_description=RESP_DESCR,
34
- description="Return transcript exon data",
35
- response_model=GenomicDataResponse,
36
- )
37
- async def genomic_to_transcript_exon_coordinates(
38
- request_body: GenomicRequestBody,
39
- ) -> GenomicDataResponse:
40
- """Get transcript exon data given genomic coordinate data
41
-
42
- :param GenomicRequestBody request_body: Request body
43
-
44
- Returns: GenomicDataResponse with data and warnings
45
- """
46
- request_body = request_body.model_dump()
47
-
48
- response = GenomicDataResponse(
49
- genomic_data=None, warnings=[], service_meta=service_meta()
50
- )
51
-
52
- try:
53
- response = await cool_seq_tool.ex_g_coords_mapper.genomic_to_transcript_exon_coordinates(
54
- **request_body
55
- )
56
- except Exception as e:
57
- logger.error("genomic_to_transcript_exon_coordinates unhandled exception %s", e)
58
- response.warnings.append(UNHANDLED_EXCEPTION_MSG)
59
-
60
- return response
61
-
62
-
63
- @router.post(
64
- "/transcript_to_genomic_coordinates",
65
- summary="Get genomic coordinate data given transcript exon data",
66
- response_description=RESP_DESCR,
67
- description="Return genomic coordinate data",
68
- response_model=GenomicDataResponse,
69
- )
70
- async def transcript_to_genomic_coordinates(
71
- request_body: TranscriptRequestBody,
72
- ) -> GenomicDataResponse:
73
- """Get transcript exon data given genomic coordinate data
74
-
75
- :param TranscriptRequestBody request_body: Request body
76
-
77
- Returns: GenomicDataResponse with data and warnings
78
- """
79
- request_body = request_body.model_dump()
80
-
81
- response = GenomicDataResponse(
82
- genomic_data=None, warnings=[], service_meta=service_meta()
83
- )
84
-
85
- try:
86
- response = (
87
- await cool_seq_tool.ex_g_coords_mapper.transcript_to_genomic_coordinates(
88
- **request_body
89
- )
90
- )
91
- except Exception as e:
92
- logger.error("transcript_to_genomic_coordinates unhandled exception %s", e)
93
- response.warnings.append(UNHANDLED_EXCEPTION_MSG)
94
-
95
- return response
96
-
97
-
98
- @router.get(
99
- "/download_sequence",
100
- summary="Get sequence for ID",
101
- response_description=RESP_DESCR,
102
- description="Given a known accession identifier, retrieve sequence data and return"
103
- "as a FASTA file",
104
- response_class=FileResponse,
105
- )
106
- async def get_sequence(
107
- background_tasks: BackgroundTasks,
108
- sequence_id: str = Query(
109
- ..., description="ID of sequence to retrieve, sans namespace"
110
- ),
111
- ) -> FileResponse:
112
- """Get sequence for requested sequence ID.
113
- :param sequence_id: accession ID, sans namespace, eg `NM_152263.3`
114
- :param background_tasks: Starlette background tasks object. Use to clean up
115
- tempfile after get method returns.
116
- :return: FASTA file if successful, or 404 if unable to find matching resource
117
- """
118
- _, path = tempfile.mkstemp(suffix=".fasta")
119
- try:
120
- cool_seq_tool.seqrepo_access.get_fasta_file(sequence_id, Path(path))
121
- except KeyError as e:
122
- raise HTTPException(
123
- status_code=404, detail="No sequence available for requested identifier"
124
- ) from e
125
- background_tasks.add_task(lambda p: os.unlink(p), path) # noqa: PTH108
126
- return FileResponse(path)
@@ -1,98 +0,0 @@
1
- """Module containing routes related to MANE data"""
2
-
3
- import logging
4
-
5
- from fastapi import APIRouter, Query
6
-
7
- from cool_seq_tool.routers import (
8
- RESP_DESCR,
9
- SERVICE_NAME,
10
- UNHANDLED_EXCEPTION_MSG,
11
- Tags,
12
- cool_seq_tool,
13
- )
14
- from cool_seq_tool.schemas import AnnotationLayer, ManeDataService, ResidueMode
15
- from cool_seq_tool.utils import service_meta
16
-
17
- logger = logging.getLogger("cool_seq_tool")
18
-
19
- router = APIRouter(prefix=f"/{SERVICE_NAME}/mane")
20
-
21
-
22
- ref_descr = (
23
- "Reference at position given during input. When this is set, it will "
24
- "ensure that the reference sequences match for the final result."
25
- )
26
- try_longest_compatible_descr = (
27
- "`True` if should try longest compatible remaining if"
28
- " mane transcript was not compatible. `False` otherwise."
29
- )
30
-
31
-
32
- @router.get(
33
- "/get_mane_data",
34
- summary="Retrieve MANE data in inter-residue coordinates",
35
- response_description=RESP_DESCR,
36
- description="Return MANE Select, MANE Plus Clinical, or Longest Remaining "
37
- "Transcript data in inter-residue coordinates. See our docs for "
38
- "more information on transcript priority.",
39
- response_model=ManeDataService,
40
- tags=[Tags.MANE_TRANSCRIPT],
41
- )
42
- async def get_mane_data(
43
- ac: str = Query(..., description="Accession"),
44
- start_pos: int = Query(..., description="Start position"),
45
- start_annotation_layer: AnnotationLayer = Query(
46
- ..., description="Starting annotation layer for query"
47
- ),
48
- end_pos: int | None = Query(
49
- None, description="End position. If not set, will set to `start_pos`."
50
- ),
51
- gene: str | None = Query(None, description="HGNC gene symbol"),
52
- ref: str | None = Query(None, description=ref_descr),
53
- try_longest_compatible: bool = Query(
54
- True, description=try_longest_compatible_descr
55
- ),
56
- residue_mode: ResidueMode = Query(
57
- ResidueMode.RESIDUE, description="Residue mode for position(s)"
58
- ),
59
- ) -> ManeDataService:
60
- """Return MANE or Longest Compatible Remaining Transcript data on inter-residue
61
- coordinates
62
-
63
- :param str ac: Accession
64
- :param int start_pos: Start position
65
- :param AnnotationLayer start_annotation_layer: Starting annotation layer for query
66
- :param Optional[int] end_pos: End position. If `None` assumes
67
- both `start_pos` and `end_pos` have same values.
68
- :param Optional[str] gene: Gene symbol
69
- :param Optional[str] ref: Reference at position given during input
70
- :param bool try_longest_compatible: `True` if should try longest
71
- compatible remaining if mane transcript was not compatible.
72
- `False` otherwise.
73
- :param ResidueMode residue_mode: Starting residue mode for `start_pos`
74
- and `end_pos`. Will always return coordinates in inter-residue
75
- """
76
- warnings = []
77
- mane_data = None
78
- try:
79
- mane_data = await cool_seq_tool.mane_transcript.get_mane_transcript(
80
- ac=ac,
81
- start_pos=start_pos,
82
- end_pos=end_pos,
83
- start_annotation_layer=start_annotation_layer,
84
- gene=gene,
85
- ref=ref,
86
- try_longest_compatible=try_longest_compatible,
87
- residue_mode=residue_mode,
88
- )
89
-
90
- if not mane_data:
91
- warnings.append("Unable to retrieve MANE data")
92
- except Exception as e:
93
- logger.exception("get_mane_data unhandled exception %s", e)
94
- warnings.append(UNHANDLED_EXCEPTION_MSG)
95
-
96
- return ManeDataService(
97
- mane_data=mane_data, warnings=warnings, service_meta=service_meta()
98
- )
@@ -1,155 +0,0 @@
1
- """Module containing routes related to alignment mapping"""
2
-
3
- import logging
4
-
5
- from fastapi import APIRouter, Query
6
-
7
- from cool_seq_tool.routers import RESP_DESCR, SERVICE_NAME, Tags, cool_seq_tool
8
- from cool_seq_tool.schemas import Assembly, ResidueMode, ToCdnaService, ToGenomicService
9
- from cool_seq_tool.utils import service_meta
10
-
11
- logger = logging.getLogger("cool_seq_tool")
12
-
13
- router = APIRouter(prefix=f"/{SERVICE_NAME}/alignment_mapper")
14
-
15
-
16
- @router.get(
17
- "/p_to_c",
18
- summary="Translate protein representation to cDNA representation",
19
- response_description=RESP_DESCR,
20
- description="Given protein accession and positions, return associated cDNA "
21
- "accession and positions to codon(s)",
22
- response_model=ToCdnaService,
23
- tags=[Tags.ALIGNMENT_MAPPER],
24
- )
25
- async def p_to_c(
26
- p_ac: str = Query(..., description="Protein RefSeq accession"),
27
- p_start_pos: int = Query(..., description="Protein start position"),
28
- p_end_pos: int = Query(..., description="Protein end position"),
29
- residue_mode: ResidueMode = Query(
30
- ResidueMode.RESIDUE,
31
- description="Residue mode for `p_start_pos` and `p_end_pos`",
32
- ),
33
- ) -> ToCdnaService:
34
- """Translate protein representation to cDNA representation
35
-
36
- :param str p_ac: Protein RefSeq accession
37
- :param int p_start_pos: Protein start position
38
- :param int p_end_pos: Protein end position
39
- :param ResidueMode residue_mode: Residue mode for `p_start_pos` and `p_end_pos`.
40
- :return: ToCdnaService containing cDNA representation, warnings, and
41
- service meta
42
- """
43
- try:
44
- c_data, w = await cool_seq_tool.alignment_mapper.p_to_c(
45
- p_ac, p_start_pos, p_end_pos, residue_mode
46
- )
47
- except Exception as e:
48
- logger.error("Unhandled exception: %s", str(e))
49
- w = "Unhandled exception. See logs for more information."
50
- c_data = None
51
- return ToCdnaService(
52
- c_data=c_data, warnings=[w] if w else [], service_meta=service_meta()
53
- )
54
-
55
-
56
- @router.get(
57
- "/c_to_g",
58
- summary="Translate cDNA representation to genomic representation",
59
- response_description=RESP_DESCR,
60
- description="Given cDNA accession and positions for codon(s), return associated genomic"
61
- " accession and positions for a given target genome assembly",
62
- response_model=ToGenomicService,
63
- tags=[Tags.ALIGNMENT_MAPPER],
64
- )
65
- async def c_to_g(
66
- c_ac: str = Query(..., description="cDNA RefSeq accession"),
67
- c_start_pos: int = Query(..., description="cDNA start position for codon"),
68
- c_end_pos: int = Query(..., description="cDNA end position for codon"),
69
- cds_start: int | None = Query(
70
- None, description="CDS start site. If not provided, this will be computed."
71
- ),
72
- residue_mode: ResidueMode = Query(
73
- ResidueMode.RESIDUE,
74
- description="Residue mode for `c_start_pos` and `c_end_pos`",
75
- ),
76
- target_genome_assembly: Assembly = Query(
77
- Assembly.GRCH38, description="Genomic assembly to map to"
78
- ),
79
- ) -> ToGenomicService:
80
- """Translate cDNA representation to genomic representation
81
-
82
- :param str c_ac: cDNA RefSeq accession
83
- :param int c_start_pos: cDNA start position for codon
84
- :param int c_end_pos: cDNA end position for codon
85
- :param Optional[int] cds_start: CDS start site. If not provided, this will be
86
- computed.
87
- :param ResidueMode residue_mode: Residue mode for `c_start_pos` and `c_end_pos`.
88
- :param Assembly target_genome_assembly: Genome assembly to get genomic data for
89
- :return: ToGenomicService containing genomic representation, warnings, and
90
- service meta
91
- """
92
- try:
93
- g_data, w = await cool_seq_tool.alignment_mapper.c_to_g(
94
- c_ac,
95
- c_start_pos,
96
- c_end_pos,
97
- cds_start=cds_start,
98
- residue_mode=residue_mode,
99
- target_genome_assembly=target_genome_assembly,
100
- )
101
- except Exception as e:
102
- logger.error("Unhandled exception: %s", str(e))
103
- w = "Unhandled exception. See logs for more information."
104
- g_data = None
105
- return ToGenomicService(
106
- g_data=g_data, warnings=[w] if w else [], service_meta=service_meta()
107
- )
108
-
109
-
110
- @router.get(
111
- "/p_to_g",
112
- summary="Translate protein representation to genomic representation",
113
- response_description=RESP_DESCR,
114
- description="Given protein accession and positions, return associated genomic "
115
- "accession and positions for a given target genome assembly",
116
- response_model=ToGenomicService,
117
- tags=[Tags.ALIGNMENT_MAPPER],
118
- )
119
- async def p_to_g(
120
- p_ac: str = Query(..., description="Protein RefSeq accession"),
121
- p_start_pos: int = Query(..., description="Protein start position"),
122
- p_end_pos: int = Query(..., description="Protein end position"),
123
- residue_mode: ResidueMode = Query(
124
- ResidueMode.RESIDUE,
125
- description="Residue mode for `p_start_pos` and `p_end_pos`",
126
- ),
127
- target_genome_assembly: Assembly = Query(
128
- Assembly.GRCH38, description="Genomic assembly to map to"
129
- ),
130
- ) -> ToGenomicService:
131
- """Translate protein representation to genomic representation
132
-
133
- :param str p_ac: Protein RefSeq accession
134
- :param int p_start_pos: Protein start position
135
- :param int p_end_pos: Protein end position
136
- :param ResidueMode residue_mode: Residue mode for `p_start_pos` and `p_end_pos`.
137
- :param Assembly target_genome_assembly: Genome assembly to get genomic data for
138
- :return: ToGenomicService containing genomic representation, warnings, and
139
- service meta
140
- """
141
- try:
142
- g_data, w = await cool_seq_tool.alignment_mapper.p_to_g(
143
- p_ac,
144
- p_start_pos,
145
- p_end_pos,
146
- residue_mode=residue_mode,
147
- target_genome_assembly=target_genome_assembly,
148
- )
149
- except Exception as e:
150
- logger.error("Unhandled exception: %s", str(e))
151
- w = "Unhandled exception. See logs for more information."
152
- g_data = None
153
- return ToGenomicService(
154
- g_data=g_data, warnings=[w] if w else [], service_meta=service_meta()
155
- )
cool_seq_tool/version.py DELETED
@@ -1,3 +0,0 @@
1
- """Define package version."""
2
-
3
- __version__ = "0.4.1"
@@ -1,29 +0,0 @@
1
- cool_seq_tool/__init__.py,sha256=BTfkS0bkMtxBL4yGHc4Z7ubmNhdhY2WALfadnk8N1lw,280
2
- cool_seq_tool/api.py,sha256=AbCmdUVH8ltwqH8k7DiVsHpujMzb6c5pyAKY12iIC0U,1210
3
- cool_seq_tool/app.py,sha256=5dBmzTf5SeIF90y_ZyI0K6AMSKgchC33eW_ABN6D8_s,4790
4
- cool_seq_tool/schemas.py,sha256=8xGrP0rAcKLXtZYEe_DJcNp4zapjhN0StRq8uCjoobE,16720
5
- cool_seq_tool/utils.py,sha256=lckkyFKxMAqG79SYO3p28q6BWgEjlQP7CumE2TDP1zc,1601
6
- cool_seq_tool/version.py,sha256=hs3N9Wl67casrrQa2sGIAcpcaUySVk4oLE7JffoQuCI,53
7
- cool_seq_tool/handlers/__init__.py,sha256=KalQ46vX1MO4SJz2SlspKoIRy1n3c3Vp1t4Y2pIfqow,78
8
- cool_seq_tool/handlers/seqrepo_access.py,sha256=JB3cg7YiV2JKa7ImJXz4WtP9XWShk9qYvhCCrZnBQ6M,8983
9
- cool_seq_tool/mappers/__init__.py,sha256=SMSf6sPcu7mdQNuJ4Cj1mbOwFUPuMdFSf0noY4XvTxE,262
10
- cool_seq_tool/mappers/alignment.py,sha256=6Vk4XEar54ivuH8N7oBqa9gUa8E5GjWCI9hC1HCkM18,9552
11
- cool_seq_tool/mappers/exon_genomic_coords.py,sha256=tOmo6kFGcFIRmLBQwSsIZUSiratiyACf946YKV_IU78,38544
12
- cool_seq_tool/mappers/mane_transcript.py,sha256=RrVRUS4IqxxX-HyamNLqpQ_WVWABgiLqwmmIh92uny8,49264
13
- cool_seq_tool/resources/__init__.py,sha256=VwUC8YaucTS6SmRirToulZTF6CuvuLQRSxFfSfAovCc,77
14
- cool_seq_tool/resources/data_files.py,sha256=3lhu28tzlSoTs4vHZNu-hhoAWRrPGuZj_oIjqk2sYQM,3837
15
- cool_seq_tool/resources/status.py,sha256=ENsLiwSxzJOLOsY5IKDM805UWbQAOV3w9s7Rv_FLAUs,5761
16
- cool_seq_tool/resources/transcript_mapping.tsv,sha256=AO3luYQAbFiCoRgiiPXotakb5pAwx1jDCeXpvGdIuac,24138769
17
- cool_seq_tool/routers/__init__.py,sha256=7SqhLv6_mDPpK1Q0L9aykmjhCmsymFqgbSWZH8LuCW0,437
18
- cool_seq_tool/routers/default.py,sha256=zqeQmHmfGUvV32xLbN-fUfYnK_UI1gpqIL8Eu5Y8KzY,3928
19
- cool_seq_tool/routers/mane.py,sha256=boZKP5PH0BAcqEeTBBr9Z3EMY4lhvLLX-pJxUqjBZQ0,3508
20
- cool_seq_tool/routers/mappings.py,sha256=UJaip0QvRfK3Lk3eVuwofUwg2XJqMV5OVY9OLcpnWS4,6061
21
- cool_seq_tool/sources/__init__.py,sha256=51QiymeptF7AeVGgV-tW_9f4pIUr0xtYbyzpvHOCneM,304
22
- cool_seq_tool/sources/mane_transcript_mappings.py,sha256=9Rd_tRCrTk9i9Urp-pMMttq4cCbIJaEJ0n8rM9y9-7I,4077
23
- cool_seq_tool/sources/transcript_mappings.py,sha256=903RKTMBO2rbKh6iTQ1BEWnY4C7saBFMPw2_4ATuudg,10054
24
- cool_seq_tool/sources/uta_database.py,sha256=GJHhYbH130YJo9FIRroR8eavlbaziMwI0JVNP8IPGPM,45636
25
- cool_seq_tool-0.4.1.dist-info/LICENSE,sha256=IpqC9A-tZW7XXXvCS8c4AVINqkmpxiVA-34Qe3CZSjo,1072
26
- cool_seq_tool-0.4.1.dist-info/METADATA,sha256=CnZwl-rVLfY6kcVkQKYsYziT19q48qHRkYFQ96-OCx0,6262
27
- cool_seq_tool-0.4.1.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
28
- cool_seq_tool-0.4.1.dist-info/top_level.txt,sha256=cGuxdN6p3y16jQf6hCwWhE4OptwUeZPm_PNJlPb3b0k,14
29
- cool_seq_tool-0.4.1.dist-info/RECORD,,