1919)
2020from mavedb .models .experiment_controlled_keyword import ExperimentControlledKeywordAssociation
2121from mavedb .models .experiment_publication_identifier import ExperimentPublicationIdentifierAssociation
22- from mavedb .models .mapped_variant import MappedVariant
2322from mavedb .models .publication_identifier import PublicationIdentifier
23+ from mavedb .models .published_variant import PublishedVariantsMV
2424from mavedb .models .raw_read_identifier import RawReadIdentifier
2525from mavedb .models .refseq_identifier import RefseqIdentifier
2626from mavedb .models .refseq_offset import RefseqOffset
3737from mavedb .models .uniprot_identifier import UniprotIdentifier
3838from mavedb .models .uniprot_offset import UniprotOffset
3939from mavedb .models .user import User
40- from mavedb .models .variant import Variant
4140
4241router = APIRouter (
4342 prefix = "/api/v1/statistics" ,
@@ -484,9 +483,12 @@ def variant_counts(group: Optional[GroupBy] = None, db: Session = Depends(get_db
484483 Returns a dictionary of counts for the number of published and distinct variants in the database.
485484 Optionally, group the counts by the day on which the score set (and by extension, the variant) was published.
486485 """
487- query = _join_model_and_filter_unpublished (select (ScoreSet .published_date , func .count (Variant .id )), ScoreSet )
486+ variants = db .execute (
487+ select (PublishedVariantsMV .published_date , func .count (PublishedVariantsMV .variant_id ))
488+ .group_by (PublishedVariantsMV .published_date )
489+ .order_by (PublishedVariantsMV .published_date )
490+ ).all ()
488491
489- variants = db .execute (query .group_by (ScoreSet .published_date ).order_by (ScoreSet .published_date )).all ()
490492 if group == GroupBy .month :
491493 grouped = {k : sum (c for _ , c in g ) for k , g in itertools .groupby (variants , lambda t : t [0 ].strftime ("%Y-%m" ))}
492494 elif group == GroupBy .year :
@@ -506,17 +508,15 @@ def mapped_variant_counts(
506508 Optionally, group the counts by the day on which the score set (and by extension, the variant) was published.
507509 Optionally, return the count of all mapped variants, not just the current/most up to date ones.
508510 """
509- query = _join_model_and_filter_unpublished (
510- select (ScoreSet .published_date , func .count (MappedVariant .id )).join (
511- Variant , Variant .id == MappedVariant .variant_id
512- ),
513- ScoreSet ,
514- )
511+ query = select (PublishedVariantsMV .published_date , func .count (PublishedVariantsMV .mapped_variant_id ))
515512
516513 if onlyCurrent :
517- query = query .where (MappedVariant .current .is_ (True ))
514+ query = query .where (PublishedVariantsMV .current_mapped_variant .is_ (True ))
515+
516+ variants = db .execute (
517+ query .group_by (PublishedVariantsMV .published_date ).order_by (PublishedVariantsMV .published_date )
518+ ).all ()
518519
519- variants = db .execute (query .group_by (ScoreSet .published_date ).order_by (ScoreSet .published_date )).all ()
520520 if group == GroupBy .month :
521521 grouped = {k : sum (c for _ , c in g ) for k , g in itertools .groupby (variants , lambda t : t [0 ].strftime ("%Y-%m" ))}
522522 elif group == GroupBy .year :
0 commit comments