• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cnr-ibba / SMARTER-database / 9409416133

07 Jun 2024 12:01AM UTC coverage: 94.434%. Remained the same
9409416133

Pull #132

github

web-flow
Merge 85d054b54 into 61b51548b
Pull Request #132: ⬆️ Bump tornado from 6.4 to 6.4.1

3071 of 3252 relevant lines covered (94.43%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.49
/src/data/import_manifest.py
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
"""
1✔
4
Created on Tue Mar  2 10:38:05 2021
5

6
@author: Paolo Cozzi <paolo.cozzi@ibba.cnr.it>
7
"""
8

9
import click
1✔
10
import logging
1✔
11

12
from src.features.illumina import read_Manifest
1✔
13
from src.features.smarterdb import (
1✔
14
    Location, global_connection, SupportedChip)
15
from src.data.common import get_variant_species, update_variant, new_variant
1✔
16

17
logger = logging.getLogger(__name__)
1✔
18

19

20
@click.command()
1✔
21
@click.option('--species_class', type=str, required=True)
1✔
22
@click.option('--manifest', type=str, required=True)
1✔
23
@click.option('--chip_name', type=str, required=True)
1✔
24
@click.option('--version', type=str, required=True)
1✔
25
@click.option('--sender', type=str, required=True)
1✔
26
def main(species_class, manifest, chip_name, version, sender):
1✔
27
    """Load SNP data from Illumina manifest file into SMARTER-database"""
28

29
    # determining the proper VariantSpecies class
30
    VariantSpecie = get_variant_species(species_class)
1✔
31

32
    # check chip_name
33
    illumina_chip = SupportedChip.objects(name=chip_name).get()
1✔
34

35
    # reset chip data (if any)
36
    illumina_chip.n_of_snps = 0
1✔
37

38
    logger.info(f"Reading from {manifest}")
1✔
39

40
    # grep a sample SNP
41
    for i, record in enumerate(read_Manifest(manifest, delimiter=",")):
1✔
42
        # update chip data indipendentely if it is an update or not
43
        illumina_chip.n_of_snps += 1
1✔
44

45
        # create a location object
46
        location = Location(
1✔
47
            version=version,
48
            chrom=record.chr,
49
            position=record.mapinfo,
50
            illumina=record.snp,
51
            illumina_strand=record.ilmnstrand,
52
            strand=record.sourcestrand,
53
            imported_from="manifest",
54
            date=record.date,
55
        )
56

57
        variant = VariantSpecie(
1✔
58
            chip_name=[chip_name],
59
            name=record.name,
60
            sequence={chip_name: record.sourceseq},
61
            sender=sender
62
        )
63

64
        # search for a snp in database (relying on name)
65
        qs = VariantSpecie.objects.filter(name=record.name)
1✔
66

67
        if qs.count() == 1:
1✔
68
            update_variant(qs, variant, location)
1✔
69

70
        elif qs.count() == 0:
1✔
71
            new_variant(variant, location)
1✔
72

73
        if (i+1) % 5000 == 0:
1✔
74
            logger.info(f"{i+1} variants processed")
×
75

76
    # update chip info
77
    illumina_chip.save()
1✔
78

79
    logger.info(f"{i+1} variants processed")
1✔
80

81
    logger.info("Completed")
1✔
82

83

84
if __name__ == '__main__':
1✔
85
    log_fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
×
86
    logging.basicConfig(level=logging.INFO, format=log_fmt)
×
87

88
    # connect to database
89
    global_connection()
×
90

91
    main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc