示例#1
0
def test_add_impact_severity(variant):
    plugin = VcfPlugin()

    variant.most_severe_consequence = 'stop_gained'
    plugin._add_impact_severity(variant)

    assert variant.impact_severity == 'HIGH'
示例#2
0
def test_add_impact_severity(variant):
    plugin = VcfPlugin()
    
    variant.most_severe_consequence = 'stop_gained'
    plugin._add_impact_severity(variant)
    
    assert variant.impact_severity == 'HIGH'
示例#3
0
def test_add_most_severe(variant):
    plugin = VcfPlugin()
    
    variant.consequences = ['downstream_gene_variant', 'stop_gained']
    plugin._add_most_severe_consequence(variant)
    
    assert variant.most_severe_consequence == 'stop_gained'
示例#4
0
def test_add_most_severe(variant):
    plugin = VcfPlugin()

    variant.consequences = ['downstream_gene_variant', 'stop_gained']
    plugin._add_most_severe_consequence(variant)

    assert variant.most_severe_consequence == 'stop_gained'
示例#5
0
def test_individual(case_obj):
    adapter=VcfPlugin()
    adapter.add_case(case_obj)
    
    ind_id = "ADM1059A1"
    ind_obj = adapter.individual(ind_id)
    assert ind_obj.ind_id == ind_id
示例#6
0
    def test_filters_no_filter(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {}
        result = plugin.variants(case_id, filters=filters, count=1000)
        
        assert result.nr_of_variants == 108
示例#7
0
    def test_filters_no_filter(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {}
        result = plugin.variants(case_id, filters=filters, count=1000)
        
        assert result.nr_of_variants == 108
示例#8
0
def test_variant():
    vcf_plugin = VcfPlugin(root_path=vcf)
    variant = vcf_plugin.variant('hapmap.vcf', 'X_155239821_G_A')
    assert variant['CHROM'] == 'X'
    assert variant['POS'] == '155239821'

    # get 10th variant
    variant = vcf_plugin.variant('hapmap.vcf', '3_124998098_C_A')
    assert variant['index'] == 10
def test_add_compounds(variant):
    plugin = VcfPlugin()
    info_dict = {
        'Compounds': "643594:11_120999413_G_A>24|11_120988038_T_G>23|11_120991571_G_A>10|11_121028581_C_G>36"
    }
    plugin._add_compounds(variant, info_dict)
    compounds = variant.compounds
    highest_scored_compound = compounds[0]
    assert int(highest_scored_compound.combined_score) == 36
示例#10
0
def test_format_variants(cyvcf_variant, case_obj, header):
    vcf_plugin = VcfPlugin()
    vcf_plugin.head = header
    vcf_plugin.vep_header = header.vep_columns
    vcf_plugin.snpeff_header = header.snpeff_columns

    variant_obj = vcf_plugin._format_variants(cyvcf_variant, index=1,
                             case_obj=case_obj, add_all_info=False)

    assert variant_obj.CHROM == cyvcf_variant.CHROM
    assert variant_obj.start == cyvcf_variant.start
示例#11
0
def test_variant(case_obj):
    vcf_plugin = VcfPlugin()
    vcf_plugin.add_case(case_obj)

    variant = vcf_plugin.variant(case_obj.case_id, 'X_155239821_G_A')
    assert variant['CHROM'] == 'X'
    assert int(variant['POS']) == 155239821

    # get 10th variant
    variant = vcf_plugin.variant(case_obj.case_id, '3_124998098_C_A')
    assert variant['index'] == 10
示例#12
0
文件: cli.py 项目: brainstorm/puzzle
def load(ctx, variant_source, family_file, family_type):
    """
    Load a case into the database.

    This can be done with a config file or from command line.
    If no database was found run puzzle init first.
    """
    db_path = ctx.obj['db_path']
    if not os.path.exists(db_path):
        logger.warn("database not initialized, run 'puzzle init'")
        ctx.abort()

    logger.debug('Set puzzle backend to {0}'.format(ctx.obj['mode']))
    mode = ctx.obj['mode']
    logger.debug('Set puzzle mode to {0}'.format(ctx.obj['variant_type']))
    variant_type = ctx.obj['variant_type']

    if mode == 'vcf':
        logger.info("Initialzing VCF plugin")
        if not family_file:
            logger.error("Please provide a ped like file")
            ctx.abort()
        try:
            plugin = VcfPlugin(
                root_path=variant_source,
                case_lines=family_file,
                case_type=family_type,
                vtype=variant_type
            )
        except SyntaxError as e:
            logger.error(e.message)
            ctx.abort()

    elif mode == 'gemini':
        logger.debug("Initialzing GEMINI plugin")
        try:
            plugin = GeminiPlugin(db=variant_source, vtype=variant_type)
        except NameError:
            logger.error("Need to have gemini installed to use gemini plugin")
            ctx.abort()
        except DatabaseError as e:
            logger.error("{0} is not a valid gemini db".format(variant_source))
            logger.info("variant-source has to point to a gemini database")
            ctx.abort()

    logger.debug("Plugin setup was succesfull")
    # from gemini can create multiple cases
    store = SqlStore(db_path)

    for case_obj in plugin.cases():
        # extract case information
        logger.debug("adding case: {}".format(case_obj['case_id']))
        store.add_case(case_obj, vtype=variant_type, mode=mode)
示例#13
0
def test_variants_case_no_ped():
    vcf_plugin = VcfPlugin(root_path=vcf)
    variants = vcf_plugin.variants(case_id='hapmap.vcf')
    variant = next(variants)
    assert variant['CHROM'] == 'X'
    assert int(variant['POS']) == 84563218
    assert variant['index'] == 1

    variant = next(variants)
    assert variant['CHROM'] == '2'
    assert int(variant['POS']) == 233349186
    assert variant['index'] == 2
示例#14
0
def test_variants_case_with_ped():
    vcf_plugin = VcfPlugin(root_path=vcf, case_lines=individuals, case_type='ped')
    variants = vcf_plugin.variants(case_id='636808')
    variant = next(variants)
    assert variant['CHROM'] == 'X'
    assert int(variant['POS']) == 84563218
    assert variant['index'] == 1

    variant = next(variants)
    assert variant['CHROM'] == '2'
    assert int(variant['POS']) == 233349186
    assert variant['index'] == 2
示例#15
0
    def test_filters_frequency(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {'frequency':'0.001'}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        for variant_obj in variants:
            assert variant_obj.max_freq <= 0.001
        
        assert nr_of_variants == 73
示例#16
0
    def test_filters_frequency(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {'frequency':'0.001'}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        for variant_obj in variants:
            assert variant_obj.max_freq <= 0.001
        
        assert nr_of_variants == 88
示例#17
0
    def test_filters_impact_severities_high(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {'impact_severities':['HIGH']}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        
        for variant_obj in variants:
            assert variant_obj.impact_severity == 'HIGH'
        
        assert nr_of_variants == 7
示例#18
0
def select_plugin(case_obj):
    """Select and initialize the correct plugin for the case."""
    if case_obj.variant_mode == 'vcf':
        logger.debug("Using vcf plugin")
        plugin = VcfPlugin(root_path=case_obj.variant_source,
                           vtype=case_obj.variant_type)
        plugin.case_objs = [case_obj]
    elif case_obj.variant_mode == 'gemini':
        logger.debug("Using gemini plugin")
        plugin = GeminiPlugin(db=case_obj.variant_source,
                              vtype=case_obj.variant_type)

    case_id = case_obj.case_id
    return plugin, case_id
示例#19
0
    def test_filters_gene_ids(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {'gene_ids':['POF1B']}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        
        for variant_obj in variants:
            assert 'POF1B' in variant_obj.gene_symbols
        
        assert nr_of_variants == 1
示例#20
0
    def test_filters_cadd(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {'cadd':'20'}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        
        for variant_obj in variants:
            variant_obj.cadd_score >= 20
        
        assert nr_of_variants == 50
示例#21
0
    def test_filters_consequence(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {'consequence':['frameshift_variant']}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        
        for variant_obj in variants:
            assert 'frameshift_variant' in variant_obj.consequences
        
        assert nr_of_variants == 4
示例#22
0
    def test_filters_impact_severities_high(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {'impact_severities':['HIGH']}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        
        for variant_obj in variants:
            assert variant_obj.impact_severity == 'HIGH'
        
        assert nr_of_variants == 7
示例#23
0
    def test_filters_cadd(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {'cadd':'20'}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        
        for variant_obj in variants:
            variant_obj.cadd_score >= 20
        
        assert nr_of_variants == 50
示例#24
0
    def test_filters_consequence(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {'consequence':['frameshift_variant']}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        
        for variant_obj in variants:
            assert 'frameshift_variant' in variant_obj.consequences
        
        assert nr_of_variants == 4
示例#25
0
    def test_filters_gene_ids(self, case_obj):
        plugin = VcfPlugin()
        plugin.add_case(case_obj)
        case_id = case_obj.case_id

        filters = {'gene_ids':['POF1B']}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        
        for variant_obj in variants:
            assert 'POF1B' in variant_obj.gene_symbols
        
        assert nr_of_variants == 1
示例#26
0
def test_variants_case(case_obj):
    vcf_plugin = VcfPlugin()
    vcf_plugin.add_case(case_obj)
    #case_id is 'hapmap.vcf' since no ped file is given
    result = vcf_plugin.variants(case_id=case_obj.case_id)
    variants = result.variants
    variant = variants[0]
    assert variant['CHROM'] == 'X'
    assert int(variant['POS']) == 84563218
    assert variant['index'] == 1

    variant = variants[1]
    assert variant['CHROM'] == '2'
    assert int(variant['POS']) == 233349186
    assert variant['index'] == 2
示例#27
0
def test_variants_case(case_obj):
    vcf_plugin = VcfPlugin()
    vcf_plugin.add_case(case_obj)
    #case_id is 'hapmap.vcf' since no ped file is given
    result = vcf_plugin.variants(case_id=case_obj.case_id)
    variants = result.variants
    variant = variants[0]
    assert variant['CHROM'] == 'X'
    assert int(variant['POS']) == 84563218
    assert variant['index'] == 1

    variant = variants[1]
    assert variant['CHROM'] == '2'
    assert int(variant['POS']) == 233349186
    assert variant['index'] == 2
示例#28
0
def test_add_consequences(variant):
    plugin = VcfPlugin()
    # The raw variant line is treated like a string so it does not matter
    # if it is malformed
    raw_variant_line = "7\t98994144\t.\tA\tC\t51.68\tPASS\tAC=1;AF=0.167;AN=6"\
    ";BaseQRankSum=-1.965;CADD=13.51;CSQ=C|downstream_gene_variant|MODIFIER|"\
    "ARPC1B|ENSG00000130429|Transcript|ENST00000491294|retained_intron|||||||"\
    "||||1724|1|HGNC|704||||||||||||||,C|downstream_gene_variant|MODIFIER|"\
    "ARPC1B|ENSG00000130429|Transcript|ENST00000451682|protein_coding||||||||"\
    "|||1745|1|HGNC|704||CCDS5661.1|ENSP00000389631|ARC1B_HUMAN|F8VXW2_HUMAN"\
    "&C9K057_HUMAN&C9JTT6_HUMAN&C9JQM8_HUMAN&C9JM51_HUMAN&C9JFG9_HUMAN&C9JEY1"\
    "_HUMAN&C9JBJ7_HUMAN&C9J6C8_HUMAN&C9J4Z7_HUMAN&A4D275_HUMAN|UPI0000125D33|"

    plugin._add_consequences(variant, raw_variant_line)

    assert variant.consequences == ["downstream_gene_variant"]
示例#29
0
    def select_plugin(self, case_obj):
        """Select and initialize the correct plugin for the case."""
        if case_obj.variant_mode == 'vcf':
            logger.debug("Using vcf plugin")
            plugin = VcfPlugin(case_obj.variant_type)
        elif case_obj.variant_mode == 'gemini':
            logger.debug("Using gemini plugin")
            plugin = GeminiPlugin(case_obj.variant_type)

        #Add case to plugin
        plugin.add_case(case_obj)

        self.variant_type = case_obj.variant_type

        case_id = case_obj.case_id
        return plugin, case_id
示例#30
0
    def select_plugin(self, case_obj):
        """Select and initialize the correct plugin for the case."""
        if case_obj.variant_mode == "vcf":
            logger.debug("Using vcf plugin")
            plugin = VcfPlugin(case_obj.variant_type)
        elif case_obj.variant_mode == "gemini":
            logger.debug("Using gemini plugin")
            plugin = GeminiPlugin(case_obj.variant_type)

        # Add case to plugin
        plugin.add_case(case_obj)

        self.variant_type = case_obj.variant_type

        case_id = case_obj.case_id
        return plugin, case_id
示例#31
0
def test_add_consequences(variant):
    plugin = VcfPlugin()
    # The raw variant line is treated like a string so it does not matter
    # if it is malformed
    raw_variant_line = "7\t98994144\t.\tA\tC\t51.68\tPASS\tAC=1;AF=0.167;AN=6"\
    ";BaseQRankSum=-1.965;CADD=13.51;CSQ=C|downstream_gene_variant|MODIFIER|"\
    "ARPC1B|ENSG00000130429|Transcript|ENST00000491294|retained_intron|||||||"\
    "||||1724|1|HGNC|704||||||||||||||,C|downstream_gene_variant|MODIFIER|"\
    "ARPC1B|ENSG00000130429|Transcript|ENST00000451682|protein_coding||||||||"\
    "|||1745|1|HGNC|704||CCDS5661.1|ENSP00000389631|ARC1B_HUMAN|F8VXW2_HUMAN"\
    "&C9K057_HUMAN&C9JTT6_HUMAN&C9JQM8_HUMAN&C9JM51_HUMAN&C9JFG9_HUMAN&C9JEY1"\
    "_HUMAN&C9JBJ7_HUMAN&C9J6C8_HUMAN&C9J4Z7_HUMAN&A4D275_HUMAN|UPI0000125D33|"
    
    plugin._add_consequences(variant, raw_variant_line)
    
    assert variant.consequences == ["downstream_gene_variant"]
示例#32
0
def test_setup_no_file():
    """Test to initialize a gemini database without any file"""

    adapter = VcfPlugin()

    assert adapter.variant_type == 'snv'

    assert adapter.filters.can_filter_gene == True
    assert adapter.filters.can_filter_inheritance == True
示例#33
0
    def test_filters_range(self, case_obj, indexed_vcf_file):
        plugin = VcfPlugin()
        case_obj.variant_source = indexed_vcf_file
        case_obj.compressed = True
        case_obj.tabix_index = True
        
        plugin.add_case(case_obj)
        case_id = case_obj.case_id
        start = 1771120
        end = 1771130

        filters = {'range':{'chromosome':'1', 'start':start, 'end':end}}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        
        for variant_obj in variants:
            assert variant_obj.start >= start
            assert variant_obj.stop <= end
        
        assert nr_of_variants == 1
示例#34
0
    def test_filters_range(self, case_obj, indexed_vcf_file):
        plugin = VcfPlugin()
        case_obj.variant_source = indexed_vcf_file
        case_obj.compressed = True
        case_obj.tabix_index = True
        
        plugin.add_case(case_obj)
        case_id = case_obj.case_id
        start = 1771120
        end = 1771130

        filters = {'range':{'chromosome':'1', 'start':start, 'end':end}}
        result = plugin.variants(case_id, filters=filters, count=1000)
        variants = result.variants
        nr_of_variants = result.nr_of_variants
        
        for variant_obj in variants:
            assert variant_obj.start >= start
            assert variant_obj.stop <= end
        
        assert nr_of_variants == 1
示例#35
0
class BaseConfig:
    PROJECT = PROJECT_NAME
    DEBUG = False
    TESTING = False

    # http://flask.pocoo.org/docs/quickstart/#sessions
    SECRET_KEY = 'secret key'
    PUZZLE_BACKEND = VcfPlugin()
    STORE_ENABLED = False

    # default blueprints
    BLUEPRINTS = [public_bp, variants_bp]

    #Phemonizer credentials
    PHENOMIZER_AUTH = False
示例#36
0
def test_variant(case_obj):
    vcf_plugin = VcfPlugin()
    vcf_plugin.add_case(case_obj)

    variant = vcf_plugin.variant(case_obj.case_id, 'X_155239821_G_A')
    assert variant['CHROM'] == 'X'
    assert int(variant['POS']) == 155239821

    # get 10th variant
    variant = vcf_plugin.variant(case_obj.case_id, '3_124998098_C_A')
    assert variant['index'] == 10
示例#37
0
def test_format_variants(cyvcf_variant, case_obj, header):
    vcf_plugin = VcfPlugin()
    vcf_plugin.head = header
    vcf_plugin.vep_header = header.vep_columns
    vcf_plugin.snpeff_header = header.snpeff_columns

    variant_obj = vcf_plugin._format_variants(cyvcf_variant, index=1,
                             case_obj=case_obj, add_all_info=False)

    assert variant_obj.CHROM == cyvcf_variant.CHROM
    assert variant_obj.start == cyvcf_variant.start
示例#38
0
def test_add_genetic_models_no_models(variant):
    plugin = VcfPlugin()
    info_dict = {}
    plugin._add_genetic_models(variant, info_dict)
    
    assert variant.genetic_models == []
示例#39
0
def test_individuals(case_obj):
    adapter=VcfPlugin()
    adapter.add_case(case_obj)
    
    individuals = [ind for ind in adapter.individuals()]
    assert len(individuals) == 3
示例#40
0
def test_add_most_severe_no_info(variant):
    plugin = VcfPlugin()
    plugin._add_most_severe_consequence(variant)

    assert variant.most_severe_consequence == None
示例#41
0
def vcf():
    db = VcfPlugin()
    return db
示例#42
0
def test_add_genetic_models(variant):
    plugin = VcfPlugin()
    info_dict = {'GeneticModels': '643594:AD_dn|AR_comp_dn'}
    plugin._add_genetic_models(variant, info_dict)
    
    assert set(variant.genetic_models) == set(['AD_dn', 'AR_comp_dn'])
示例#43
0
def test_setup_variant_type():
    """docstring for test_setup_variant_type"""
    adapter = VcfPlugin('sv')

    assert adapter.variant_type == 'sv'
示例#44
0
def test__add_individual(individual):
    adapter=VcfPlugin()
    adapter._add_individual(individual)
    assert len(adapter.individual_objs) == 1
示例#45
0
def test_add_rank_score_no_score(variant):
    plugin = VcfPlugin()
    info_dict = {}
    plugin._add_rank_score(variant, info_dict)
    
    assert variant.rank_score == None
示例#46
0
def test_add_most_severe_no_info(variant):
    plugin = VcfPlugin()
    plugin._add_most_severe_consequence(variant)
    
    assert variant.most_severe_consequence == None
示例#47
0
def vcf():
    db = VcfPlugin(TestConfig.PUZZLE_VCF_FILE)
    return db
示例#48
0
def test_add_compounds_no_compounds(variant):
    plugin = VcfPlugin()
    info_dict = {}
    plugin._add_compounds(variant, info_dict)
    assert variant.compounds == []
示例#49
0
def test_add_cadd_score(variant):
    plugin = VcfPlugin()
    info_dict = {'CADD': '24'}
    plugin._add_cadd_score(variant, info_dict)
    
    assert float(variant.cadd_score) == 24.0
示例#50
0
文件: load.py 项目: J35P312/PuzzleWin
def load(ctx, variant_source, family_file, family_type, root, mode,
        variant_type):
    """
    Load a variant source into the database.

    If no database was found run puzzle init first.
    
    1. VCF: If a vcf file is used it can be loaded with a ped file
    2. GEMINI: Ped information will be retreived from the gemini db
    """
    if root is None:
        #This is the default puzzle folder
        root = os.path.expanduser("~/.puzzle")

    if os.path.isfile(root):
        logger.error("'root' can't be a file")
        ctx.abort()

    logger.info("Root directory is: {}".format(root))

    db_path = os.path.join(root, 'puzzle_db.sqlite3')
    logger.info("db path is: {}".format(db_path))

    if not os.path.exists(db_path):
        logger.warn("database not initialized, run 'puzzle init'")
        ctx.abort()

    logger.debug('Set puzzle backend to {0}'.format(mode))

    logger.debug('Set variant type to {0}'.format(variant_type))

    if mode == 'vcf':
        logger.info("Initialzing VCF plugin")

        try:
            plugin = VcfPlugin(
                root_path=variant_source,
                case_lines=family_file,
                case_type=family_type,
                vtype=variant_type
            )
        except SyntaxError as e:
            logger.error(e.message)
            ctx.abort()

    elif mode == 'gemini':
        logger.debug("Initialzing GEMINI plugin")
        try:
            plugin = GeminiPlugin(db=variant_source, vtype=variant_type)
        except NameError:
            logger.error("Need to have gemini installed to use gemini plugin")
            ctx.abort()
        except DatabaseError as e:
            logger.error("{} is not a valid gemini db".format(variant_source))
            logger.info("variant-source has to point to a gemini database")
            ctx.abort()

    logger.debug("Plugin setup was succesfull")
    # from gemini can create multiple cases
    store = SqlStore(db_path)

    for case_obj in plugin.cases():
        if store.case(case_id=case_obj.case_id).case_id == case_obj.case_id:
            logger.warn("{} already exists in the database"
                        .format(case_obj.case_id))
            continue

        # extract case information
        logger.debug("adding case: {}".format(case_obj.case_id))
        store.add_case(case_obj, vtype=variant_type, mode=mode)
示例#51
0
def test_add_rank_score(variant):
    plugin = VcfPlugin()
    info_dict = {'RankScore': '643594:24'}
    plugin._add_rank_score(variant, info_dict)
    
    assert int(variant.rank_score) == 24