Exemple #1
0
class TestUcscSnpDao(unittest.TestCase):
    #---------------------------------------------
    # Constants
    #---------------------------------------------
    
    #---------------------------------------------
    # Setup Methods
    #---------------------------------------------
    def setUp(self):
        '''Use a localhost UCSC copy.'''
        url = 'mysql://*****:*****@localhost/ucsc'
        self.engine = create_engine(url)
        self.dao = SnpDao(url)
        # Base.metadata.create_all(self.engine) 
        
    def tearDown(self):
        '''Drop the database.'''
        pass
    
    #---------------------------------------------
    # Test Methods
    #---------------------------------------------
    def test_num_records(self):
        '''Test getting the total # of SNP records.'''
        assert_equal(self.dao.num_records(), 54212080, 'Wrong row count from SNP table')

    # Slow test; can take ~20 seconds
    @nottest
    def inactive_test_snps_on_chromosome(self):
        '''Test retrieving SNPs by chromosome.'''
        chrom = 22
        assert_equal(len(list(self.dao.chrom_snps(chrom))), 730365, 'Wrong number of SNPs on chromosome %d' % (chrom,))

    def test_get_snps(self):
        '''Test retrieving SNPs by chromosome.'''
        snps = self.dao.get_snps(['rs144773400', 'rs143255646', 'rs145599635'])
        assert_equal(len(snps), 3, 'Wrong number returned SNPs entries')
        assert_equal([snp.bp for snp in snps], [10229, 10145, 10234], 'Wrong SNP base-pair positions')
Exemple #2
0
####################################################################################
if __name__ == '__main__':
    '''
    --------------------------------------------------
    Main program
    --------------------------------------------------
    '''
    options, args = __parse_command_line_args(sys.argv)
    var_file_prefix, input_file, output_file = args
    genotype_filter = __GENOTYPE_FILTER[options.genotype_filter]
    genotype_cleaner = __GENOTYPE_CLEANER[options.genotype_filter]
    allele_start_index = 1 if options.type == 'imputed' else 0
    try:
        # Read location list
        snp_dao = SnpDao(options.db_url)
        input_file = sys.stdin if args[1] == '-' else open(input_file, 'rb')

        # Sample IDs are read from the pedigree, and must match the genotype files' ordering
        pedigree = io_pedigree.read(options.pedigree_file,
                                    options.genotype_id_file)
        node_of = pedigree.node_of
        sample_id = np.loadtxt(
            options.id_file, dtype=np.int,
            ndmin=1) if options.id_file else pedigree._sample_id
        N = pedigree.num_genotyped
        sample_index = np.array(
            filter(lambda x: x is not None and x < N,
                   map(node_of.get, sample_id))
        )  # Filter FINDIVs that are not in the imputed FINDIV set
Exemple #3
0
 def setUp(self):
     '''Use a localhost UCSC copy.'''
     url = 'mysql://*****:*****@localhost/ucsc'
     self.engine = create_engine(url)
     self.dao = SnpDao(url)