|
1 | | -from collections import Counter |
2 | 1 | import csv |
3 | 2 | import io |
4 | 3 | import logging |
5 | | -from operator import attrgetter |
6 | 4 | import re |
7 | | -from typing import Any, BinaryIO, Iterable, List, Optional, TYPE_CHECKING, Sequence, Literal |
| 5 | +from collections import Counter |
| 6 | +from operator import attrgetter |
| 7 | +from typing import TYPE_CHECKING, Any, BinaryIO, Iterable, List, Literal, Optional, Sequence |
8 | 8 |
|
9 | | -from mavedb.models.mapped_variant import MappedVariant |
10 | 9 | import numpy as np |
11 | 10 | import pandas as pd |
12 | 11 | from pandas.testing import assert_index_equal |
13 | 12 | from sqlalchemy import Integer, and_, cast, func, or_, select |
14 | | -from sqlalchemy.orm import Session, aliased, contains_eager, joinedload, Query, selectinload |
| 13 | +from sqlalchemy.orm import Query, Session, aliased, contains_eager, joinedload, selectinload |
15 | 14 |
|
16 | 15 | from mavedb.lib.exceptions import ValidationError |
17 | 16 | from mavedb.lib.logging.context import logging_context, save_to_logging_context |
|
26 | 25 | from mavedb.lib.mave.utils import is_csv_null |
27 | 26 | from mavedb.lib.validation.constants.general import null_values_list |
28 | 27 | from mavedb.lib.validation.utilities import is_null as validate_is_null |
29 | | -from mavedb.lib.variants import get_hgvs_from_post_mapped, is_hgvs_g, is_hgvs_p |
| 28 | +from mavedb.lib.variants import get_digest_from_post_mapped, get_hgvs_from_post_mapped, is_hgvs_g, is_hgvs_p |
30 | 29 | from mavedb.models.contributor import Contributor |
31 | 30 | from mavedb.models.controlled_keyword import ControlledKeyword |
32 | 31 | from mavedb.models.doi_identifier import DoiIdentifier |
|
36 | 35 | from mavedb.models.experiment_controlled_keyword import ExperimentControlledKeywordAssociation |
37 | 36 | from mavedb.models.experiment_publication_identifier import ExperimentPublicationIdentifierAssociation |
38 | 37 | from mavedb.models.experiment_set import ExperimentSet |
| 38 | +from mavedb.models.mapped_variant import MappedVariant |
39 | 39 | from mavedb.models.publication_identifier import PublicationIdentifier |
40 | 40 | from mavedb.models.refseq_identifier import RefseqIdentifier |
41 | 41 | from mavedb.models.refseq_offset import RefseqOffset |
@@ -547,6 +547,7 @@ def get_score_set_variants_as_csv( |
547 | 547 | if include_post_mapped_hgvs: |
548 | 548 | namespaced_score_set_columns["mavedb"].append("post_mapped_hgvs_g") |
549 | 549 | namespaced_score_set_columns["mavedb"].append("post_mapped_hgvs_p") |
| 550 | + namespaced_score_set_columns["mavedb"].append("post_mapped_vrs_digest") |
550 | 551 | for namespace in namespaces: |
551 | 552 | namespaced_score_set_columns[namespace] = [] |
552 | 553 | if include_custom_columns: |
@@ -596,7 +597,9 @@ def get_score_set_variants_as_csv( |
596 | 597 | if limit: |
597 | 598 | variants_query = variants_query.limit(limit) |
598 | 599 | variants = db.scalars(variants_query).all() |
599 | | - rows_data = variants_to_csv_rows(variants, columns=namespaced_score_set_columns, namespaced=namespaced, mappings=mappings) # type: ignore |
| 600 | + rows_data = variants_to_csv_rows( |
| 601 | + variants, columns=namespaced_score_set_columns, namespaced=namespaced, mappings=mappings |
| 602 | + ) # type: ignore |
600 | 603 | rows_columns = [ |
601 | 604 | ( |
602 | 605 | f"{namespace}.{col}" |
@@ -701,6 +704,9 @@ def variant_to_csv_row( |
701 | 704 | value = hgvs_str |
702 | 705 | else: |
703 | 706 | value = "" |
| 707 | + elif column_key == "post_mapped_vrs_digest": |
| 708 | + digest = get_digest_from_post_mapped(mapping.post_mapped) if mapping and mapping.post_mapped else None |
| 709 | + value = digest if digest is not None else "" |
704 | 710 | if is_null(value): |
705 | 711 | value = na_rep |
706 | 712 | key = f"mavedb.{column_key}" if namespaced else column_key |
|
0 commit comments