Skip to content

Commit

Permalink
fix: use correct logging setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Jul 2, 2024
1 parent ec6cced commit f0d4448
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 80 deletions.
11 changes: 0 additions & 11 deletions src/cool_seq_tool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
"""The cool_seq_tool package"""

import logging

logging.basicConfig(
filename="cool_seq_tool.log",
format="[%(asctime)s] - %(name)s - %(levelname)s : %(message)s",
)
logger = logging.getLogger("cool_seq_tool")
logger.setLevel(logging.DEBUG)

LOG_FN = "cool_seq_tool.log"
2 changes: 1 addition & 1 deletion src/cool_seq_tool/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from cool_seq_tool.sources.transcript_mappings import TranscriptMappings
from cool_seq_tool.sources.uta_database import UTA_DB_URL, UtaDatabase

logger = logging.getLogger(__name__)
_logger = logging.getLogger(__name__)


class CoolSeqTool:
Expand Down
10 changes: 5 additions & 5 deletions src/cool_seq_tool/handlers/seqrepo_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from cool_seq_tool.schemas import ResidueMode
from cool_seq_tool.utils import get_inter_residue_pos

logger = logging.getLogger(__name__)
_logger = logging.getLogger(__name__)


SEQREPO_ROOT_DIR = environ.get("SEQREPO_ROOT_DIR", "/usr/local/share/seqrepo/latest")
Expand Down Expand Up @@ -66,7 +66,7 @@ def get_reference_sequence(
sequence = self.sr.fetch(ac, start=start, end=end)
except KeyError:
msg = f"Accession, {ac}, not found in SeqRepo"
logger.warning(msg)
_logger.warning(msg)
return "", msg
except ValueError as e:
error = str(e)
Expand All @@ -80,7 +80,7 @@ def get_reference_sequence(
)
else:
msg = f"{e}"
logger.warning(msg)
_logger.warning(msg)
return "", msg
else:
# If start is valid, but end is invalid, SeqRepo still returns
Expand Down Expand Up @@ -118,7 +118,7 @@ def translate_identifier(
)
except KeyError:
msg = f"SeqRepo unable to get translated identifiers for {ac}"
logger.warning(msg)
_logger.warning(msg)
return [], msg
else:
return ga4gh_identifiers, None
Expand All @@ -133,7 +133,7 @@ def translate_alias(self, input_str: str) -> tuple[list[str | None], str | None]
return self.sr.translate_alias(input_str), None
except KeyError:
msg = f"SeqRepo could not translate alias {input_str}"
logger.warning(msg)
_logger.warning(msg)
return [], msg

def chromosome_to_acs(self, chromosome: str) -> tuple[list[str] | None, str | None]:
Expand Down
12 changes: 6 additions & 6 deletions src/cool_seq_tool/mappers/exon_genomic_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"CoordinatesResponseType", GenomicDataResponse, TranscriptExonDataResponse
)

logger = logging.getLogger(__name__)
_logger = logging.getLogger(__name__)


class ExonGenomicCoordsMapper:
Expand Down Expand Up @@ -80,7 +80,7 @@ def _return_warnings(
``genomic_data`` field is ``None``
:return: Response object with warning message
"""
logger.warning(warning_msg)
_logger.warning(warning_msg)
resp.warnings.append(warning_msg)
return resp

Expand Down Expand Up @@ -436,7 +436,7 @@ async def _get_alt_ac_start_and_end(
"""
if tx_exon_start is None and tx_exon_end is None:
msg = "Must provide either `tx_exon_start` or `tx_exon_end` or both"
logger.warning(msg)
_logger.warning(msg)
return None, msg

alt_ac_data = {"start": None, "end": None}
Expand All @@ -462,7 +462,7 @@ async def _get_alt_ac_start_and_end(
error = "Genomic accession does not match"
else:
error = "Strand does not match"
logger.warning(
_logger.warning(
"%s: %s != %s",
error,
alt_ac_data["start"][i],
Expand Down Expand Up @@ -726,7 +726,7 @@ async def _set_mane_genomic_data(
msg = f"Unable to find mane data for {alt_ac} with position {pos}"
if gene:
msg += f" on gene {gene}"
logger.warning(msg)
_logger.warning(msg)
return msg

params["gene"] = mane_data.gene
Expand All @@ -750,7 +750,7 @@ async def _set_mane_genomic_data(
f"{params['transcript']} with position {tx_pos} "
f"does not exist on exons: {tx_exons}"
)
logger.warning(msg)
_logger.warning(msg)
return msg

strand_to_use = strand if strand is not None else mane_data.strand
Expand Down
46 changes: 23 additions & 23 deletions src/cool_seq_tool/mappers/mane_transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)
from cool_seq_tool.utils import get_inter_residue_pos

logger = logging.getLogger(__name__)
_logger = logging.getLogger(__name__)


class EndAnnotationLayer(str, Enum):
Expand Down Expand Up @@ -168,10 +168,10 @@ async def _p_to_c(
elif ac.startswith("ENSP"):
ac = self.transcript_mappings.ensp_to_enst[ac]
else:
logger.warning("Unable to find accession: %s", ac)
_logger.warning("Unable to find accession: %s", ac)
return None
except KeyError:
logger.warning("%s not found in transcript_mappings", ac)
_logger.warning("%s not found in transcript_mappings", ac)
return None

pos = self._p_to_c_pos(start_pos, end_pos)
Expand All @@ -196,7 +196,7 @@ async def _c_to_g(self, ac: str, pos: tuple[int, int]) -> dict | None:
0
]
):
logger.warning("Ensembl transcript not found: %s", ac)
_logger.warning("Ensembl transcript not found: %s", ac)
return None

temp_ac = ac.split(".")[0]
Expand All @@ -206,7 +206,7 @@ async def _c_to_g(self, ac: str, pos: tuple[int, int]) -> dict | None:
# c. coordinate does not contain cds start, so we need to add it
cds_start_end = await self.uta_db.get_cds_start_end(temp_ac)
if not cds_start_end:
logger.warning("Accession %s not found in UTA", temp_ac)
_logger.warning("Accession %s not found in UTA", temp_ac)
return None
coding_start_site = cds_start_end[0]
pos = pos[0] + coding_start_site, pos[1] + coding_start_site
Expand Down Expand Up @@ -237,7 +237,7 @@ async def _get_and_validate_genomic_tx_data(
tx_ac, pos, annotation_layer, alt_ac=alt_ac
)
if not genomic_tx_data:
logger.warning(
_logger.warning(
"Unable to find genomic_tx_data for %s at position %s on annotation layer %s",
alt_ac,
pos,
Expand All @@ -255,7 +255,7 @@ async def _get_and_validate_genomic_tx_data(

# Validation check: Exon structure
if og_alt_exon_id != liftover_alt_exon_id:
logger.warning(
_logger.warning(
"Original alt_exon_id %s does not match liftover alt_exon_id %s",
og_alt_exon_id,
liftover_alt_exon_id,
Expand Down Expand Up @@ -293,7 +293,7 @@ def _get_c_data(
gt_cds_end = c_pos_change[1] > cds_end and c_pos_change[1] > cds_end

if lt_cds_start or gt_cds_end:
logger.info(
_logger.info(
"%s with position %s is not within CDS start/end",
refseq_c_ac,
c_pos_change,
Expand Down Expand Up @@ -381,7 +381,7 @@ async def _g_to_c(
)

if not result:
logger.warning(
_logger.warning(
"Unable to find transcript, %s, position change", refseq_c_ac
)
return None
Expand Down Expand Up @@ -438,7 +438,7 @@ def _validate_reading_frames(
new_rf = self._get_reading_frame(transcript_data.pos[pos_index])

if og_rf != new_rf:
logger.warning(
_logger.warning(
"%s original reading frame (%s) does not match new %s, %s reading frame (%s)",
ac,
og_rf,
Expand All @@ -449,7 +449,7 @@ def _validate_reading_frames(
return False
else:
if pos_index == 0:
logger.warning("%s must having start position", ac)
_logger.warning("%s must having start position", ac)
return False
return True

Expand Down Expand Up @@ -503,18 +503,18 @@ def _validate_references(
residue_mode=residue_mode,
)
if not mane_ref:
logger.info("Unable to validate reference for MANE Transcript")
_logger.info("Unable to validate reference for MANE Transcript")

if expected_ref != mane_ref:
logger.info(
_logger.info(
"Expected ref, %s, but got %s on MANE accession, %s",
expected_ref,
mane_ref,
mane_transcript.refseq,
)

if expected_ref != ref:
logger.warning(
_logger.warning(
"Expected ref, %s, but got %s on accession, %s", expected_ref, ref, ac
)
return False
Expand Down Expand Up @@ -692,7 +692,7 @@ def _get_protein_rep(
)

if df.is_empty():
logger.warning("Unable to get transcripts from gene %s", gene)
_logger.warning("Unable to get transcripts from gene %s", gene)
return lcr_result

prioritized_tx_acs = self._get_prioritized_transcripts_from_gene(df)
Expand Down Expand Up @@ -814,7 +814,7 @@ def _get_protein_rep(
pos = lcr_result.pos

if not self._validate_index(ac, pos, coding_start_site):
logger.warning(
_logger.warning(
"%s are not valid positions on %s with coding start site %s",
pos,
ac,
Expand All @@ -841,7 +841,7 @@ def _get_protein_rep(
pos = lcr_result_dict[k]["pos"]
if not self._validate_index(ac, pos, cds):
valid = False
logger.warning(
_logger.warning(
"%s are not valid positions on %s with coding start site %s",
pos,
ac,
Expand Down Expand Up @@ -999,7 +999,7 @@ async def get_mane_transcript(
return await self.g_to_mane_c(
ac, start_pos, end_pos, gene=gene, residue_mode=residue_mode
)
logger.warning("Annotation layer not supported: %s", start_annotation_layer)
_logger.warning("Annotation layer not supported: %s", start_annotation_layer)
return None

async def g_to_grch38(self, ac: str, start_pos: int, end_pos: int) -> dict | None:
Expand All @@ -1025,7 +1025,7 @@ async def g_to_grch38(self, ac: str, start_pos: int, end_pos: int) -> dict | Non

# Coordinate liftover
if assembly < "GRCh37":
logger.warning("Liftover only supported for GRCh37")
_logger.warning("Liftover only supported for GRCh37")
return None

liftover_start_i = self.uta_db.get_liftover(
Expand Down Expand Up @@ -1130,7 +1130,7 @@ async def g_to_mane_c(
)

if not await self.uta_db.validate_genomic_ac(ac):
logger.warning("Genomic accession does not exist: %s", ac)
_logger.warning("Genomic accession does not exist: %s", ac)
return None

mane_data = self.mane_transcript_mappings.get_gene_mane_data(gene)
Expand All @@ -1156,7 +1156,7 @@ async def g_to_mane_c(
)
if not mane_tx_genomic_data:
continue
logger.info("Not using most recent assembly")
_logger.info("Not using most recent assembly")

coding_start_site = mane_tx_genomic_data["coding_start_site"]
coding_end_site = mane_tx_genomic_data["coding_end_site"]
Expand All @@ -1167,7 +1167,7 @@ async def g_to_mane_c(
if not self._validate_index(
mane_c_ac, mane_c_pos_change, coding_start_site
):
logger.warning(
_logger.warning(
"%s are not valid positions on %s with coding start site %s",
mane_c_pos_change,
mane_c_ac,
Expand Down Expand Up @@ -1257,7 +1257,7 @@ async def grch38_to_mane_c_p(
if not self._validate_index(
mane_c_ac, mane_c_pos_change, coding_start_site
):
logger.warning(
_logger.warning(
"%s are not valid positions on %s with coding start site %s",
mane_c_pos_change,
mane_c_ac,
Expand Down
8 changes: 5 additions & 3 deletions src/cool_seq_tool/routers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
from cool_seq_tool.utils import service_meta

logger = logging.getLogger("cool_seq_tool")
_logger = logging.getLogger(__name__)

router = APIRouter(prefix=f"/{SERVICE_NAME}")

Expand Down Expand Up @@ -54,7 +54,9 @@ async def genomic_to_transcript_exon_coordinates(
**request_body
)
except Exception as e:
logger.error("genomic_to_transcript_exon_coordinates unhandled exception %s", e)
_logger.error(
"genomic_to_transcript_exon_coordinates unhandled exception %s", e
)
response.warnings.append(UNHANDLED_EXCEPTION_MSG)

return response
Expand Down Expand Up @@ -89,7 +91,7 @@ async def transcript_to_genomic_coordinates(
)
)
except Exception as e:
logger.error("transcript_to_genomic_coordinates unhandled exception %s", e)
_logger.error("transcript_to_genomic_coordinates unhandled exception %s", e)
response.warnings.append(UNHANDLED_EXCEPTION_MSG)

return response
Expand Down
4 changes: 2 additions & 2 deletions src/cool_seq_tool/routers/mane.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from cool_seq_tool.schemas import AnnotationLayer, ManeDataService, ResidueMode
from cool_seq_tool.utils import service_meta

logger = logging.getLogger("cool_seq_tool")
_logger = logging.getLogger(__name__)

router = APIRouter(prefix=f"/{SERVICE_NAME}/mane")

Expand Down Expand Up @@ -90,7 +90,7 @@ async def get_mane_data(
if not mane_data:
warnings.append("Unable to retrieve MANE data")
except Exception as e:
logger.exception("get_mane_data unhandled exception %s", e)
_logger.exception("get_mane_data unhandled exception %s", e)
warnings.append(UNHANDLED_EXCEPTION_MSG)

return ManeDataService(
Expand Down
Loading

0 comments on commit f0d4448

Please sign in to comment.