예제 #1
0
def test_gwas_unpickle():
    g1 = [
        Gwas("1", 101, "A", "T", 1, 0, 5e-8, 1000, 0.4, "rs1234", None, None,
             None),
        Gwas("1", 105, "A", "T", 1, 0, 5e-8, 1000, 0.4, "rs1234", None, None,
             None),
        Gwas("1", 102, "A", "T", 1, 0, 5e-8, 1000, 0.4, "rs1234", None, None,
             None)
    ]
    g2 = []
    idx = []
    results = tempfile.TemporaryFile()
    for result in g1:
        heappush(idx, (result.pos, results.tell()))
        pickle.dump(result, results)

    while idx:
        pos = heappop(idx)
        results.seek(pos[1])
        result = pickle.load(results)
        g2.append(result)

    assert g2[0].pos == 101
    assert g2[1].pos == 102
    assert g2[2].pos == 105

    results.close()
예제 #2
0
def test_are_alleles_iupac():
    g = Gwas('test', 1, 'A', 'T', None, None, None, None, None, None, None,
             None, None)
    g.check_alleles_are_vaild()

    with pytest.raises(AssertionError):
        g = Gwas('test', 1, 'A', 'wdeT', None, None, None, None, None, None,
                 None, None, None)
        g.check_alleles_are_vaild()
예제 #3
0
def test_check_reference_allele():
    with pysam.FastaFile(os.path.join(os.path.dirname(__file__),
                                      "test.fasta")) as fasta:
        g = Gwas('test', 1, 'A', 'T', 1, None, None, None, None, None, None,
                 None, None)
        g.check_reference_allele(fasta)

        with pytest.raises(AssertionError):
            g = Gwas('test', 1, 'T', 'A', 1, None, None, None, None, None,
                     None, None, None)
            g.check_reference_allele(fasta)
예제 #4
0
def test_normalise():
    with pysam.FastaFile(os.path.join(os.path.dirname(__file__),
                                      "test.fasta")) as fasta:
        # SNV
        g = Gwas('test', 1, 'A', 'T', None, None, None, None, None, None, None,
                 None, None)
        g.check_reference_allele(fasta)
        g.normalise(fasta, padding=5)
        assert g.chrom == "test"
        assert g.pos == 1
        assert g.ref == "A"
        assert g.alt == "T"

        # left pad SNV
        g = Gwas('test', 10, 'ACACA', 'ACACT', None, None, None, None, None,
                 None, None, None, None)
        g.check_reference_allele(fasta)
        g.normalise(fasta, padding=5)
        assert g.chrom == "test"
        assert g.pos == 14
        assert g.ref == "A"
        assert g.alt == "T"

        # right pad SNV
        g = Gwas('test', 10, 'ACACA', 'TCACA', None, None, None, None, None,
                 None, None, None, None)
        g.check_reference_allele(fasta)
        g.normalise(fasta, padding=5)
        assert g.chrom == "test"
        assert g.pos == 10
        assert g.ref == "A"
        assert g.alt == "T"

        # left pad ins
        g = Gwas('test', 10, 'ACA', 'ACAGT', None, None, None, None, None,
                 None, None, None, None)
        g.check_reference_allele(fasta)
        g.normalise(fasta, padding=5)
        assert g.chrom == "test"
        assert g.pos == 12
        assert g.ref == "A"
        assert g.alt == "AGT"

        # left-align pad del
        g = Gwas('test', 10, 'ACACA', 'ACA', None, None, None, None, None,
                 None, None, None, None)
        g.check_reference_allele(fasta)
        g.normalise(fasta, padding=5)
        assert g.chrom == "test"
        assert g.pos == 9
        assert g.ref == "TAC"
        assert g.alt == "T"
예제 #5
0
def test_update_dbsnp():
    with pysam.VariantFile(
            os.path.join(os.path.dirname(__file__), "dbsnp.vcf.gz")) as dbsnp:
        g = Gwas('test', 1, 'A', 'T', 1, None, None, None, None, None, None,
                 None, None)
        assert g.dbsnpid is None
        g.update_dbsnp(dbsnp)
        assert g.dbsnpid == "rs1234"
        g = Gwas('test', 2, 'A', 'T', 1, None, None, None, None, None, None,
                 None, None)
        assert g.dbsnpid is None
        g.update_dbsnp(dbsnp)
        assert g.dbsnpid is None
예제 #6
0
def test_reverse_sign():
    g = Gwas('test', 1, 'A', 'T', 1, None, None, None, None, None, None, None,
             None)
    g.reverse_sign()
    assert g.chrom == "test"
    assert g.pos == 1
    assert g.ref == "T"
    assert g.alt == "A"
    assert g.b == -1