Ejemplo n.º 1
0
    def test_gene_experiment_datum_unicode(self):
        '''This tests the unicode representation of a :class:`~data.models.GeneExperimentData`.'''

        test_datum = GeneExperimentData(experiment=mRNASeqExperiment.objects.get(pk=1),
        	gene=Gene.objects.get(pk='Pikfyve'),
        	fold_change = 0.419048218,
        	p_value = 0.110512214,
        	q_value = 0.995959851) 
        self.assertEqual(test_datum.__unicode__(), "Pikfyve")
Ejemplo n.º 2
0
    def test_create_new_gene_experiment_datum_minimum(self):
        '''This test creates a :class:`~data.models.GeneExperimentData` with the required information only.'''

        test_datum = GeneExperimentData(experiment=mRNASeqExperiment.objects.get(pk=1),
        	gene=Gene.objects.get(pk='Pikfyve'),
        	fold_change = 0.419048218,
        	p_value = 0.110512214,
        	q_value = 0.995959851) 
        test_datum.save()
        self.assertEqual(test_datum.pk, 1) #presumes no objects loaded in fixture data
Ejemplo n.º 3
0
    def test_gene_experiment_datum_unicode(self):
        '''This tests the unicode representation of a :class:`~data.models.GeneExperimentData`.'''

        test_datum = GeneExperimentData(
            experiment=mRNASeqExperiment.objects.get(pk=1),
            gene=Gene.objects.get(pk='Pikfyve'),
            fold_change=0.419048218,
            p_value=0.110512214,
            q_value=0.995959851)
        self.assertEqual(test_datum.__unicode__(), "Pikfyve")
Ejemplo n.º 4
0
    def test_create_new_gene_experiment_datum_minimum(self):
        '''This test creates a :class:`~data.models.GeneExperimentData` with the required information only.'''

        test_datum = GeneExperimentData(
            experiment=mRNASeqExperiment.objects.get(pk=1),
            gene=Gene.objects.get(pk='Pikfyve'),
            fold_change=0.419048218,
            p_value=0.110512214,
            q_value=0.995959851)
        test_datum.save()
        self.assertEqual(test_datum.pk,
                         1)  #presumes no objects loaded in fixture data
def cufflinks_gene_diff_import(experiment_id, filename):
    '''This function imports the data from a gene_exp.diff into :class:`~data.models.GeneExperimentData` objects.
    
    This function requires a valid experiment_id and a file.
    '''

    import decimal

    experiment = mRNASeqExperiment.objects.get(pk=experiment_id)
    new_genes = 0
    updated_genes = 0
    with open(filename, 'r') as inputfile:
        for row in csv.DictReader(inputfile, delimiter='\t'):
            try:
                datum = GeneExperimentData(
                    experiment=experiment,
                    gene=Gene.objects.get(pk=row['gene']),
                    fold_change=row['log2(fold_change)'],
                    p_value=row['p_value'],
                    q_value=row['q_value'],
                    locus=row['locus'],
                    internal_id=row['test_id'],
                    sample_1=row['sample_1'],
                    sample_2=row['sample_2'],
                    amount_1=row['value_1'],
                    amount_2=row['value_2'],
                    status=row['status'],
                    test_statistic=row['test_stat'],
                    significant=row['significant'])
                datum.save()
                updated_genes += 1
            except Gene.DoesNotExist:
                #create a new gene with that name
                new_gene = Gene(name=row['gene'])
                new_gene.save()
                datum = GeneExperimentData(
                    experiment=experiment,
                    gene=new_gene,
                    fold_change=row['log2(fold_change)'],
                    p_value=row['p_value'],
                    q_value=row['q_value'],
                    locus=row['locus'],
                    internal_id=row['test_id'],
                    sample_1=row['sample_1'],
                    sample_2=row['sample_2'],
                    amount_1=row['value_1'],
                    amount_2=row['value_2'],
                    status=row['status'],
                    test_statistic=row['test_stat'],
                    significant=row['significant'])
                datum.save()
                new_genes += 1
    return "Added %i measurements and created %i new genes." % (
        updated_genes + new_genes, new_genes)
Ejemplo n.º 6
0
    def test_create_new_gene_experiment_datum_all(self):
        '''This test creates a :class:`~data.models.GeneExperimentData` with all information entered.'''

        test_datum = GeneExperimentData(experiment=mRNASeqExperiment.objects.get(pk=1),
        	gene=Gene.objects.get(pk='Pikfyve'),
        	fold_change = 0.419048218,
        	p_value = 0.110512214,
        	q_value = 0.995959851,
        	locus = '1:3054232-3054733',
        	internal_id = 'XLOC_000001',
        	sample_1 = 'Control',
        	sample_2 = 'Treated',
        	amount_1 = 0.0778978,
        	amount_2 = 0.0881688,
        	status = 'OK',
        	test_statistic = -0.0754818,
        	significant = 'no') 
        test_datum.save()
        self.assertEqual(test_datum.pk, 1) #presumes one model loaded in fixture data       
Ejemplo n.º 7
0
    def test_create_new_gene_experiment_datum_all(self):
        '''This test creates a :class:`~data.models.GeneExperimentData` with all information entered.'''

        test_datum = GeneExperimentData(
            experiment=mRNASeqExperiment.objects.get(pk=1),
            gene=Gene.objects.get(pk='Pikfyve'),
            fold_change=0.419048218,
            p_value=0.110512214,
            q_value=0.995959851,
            locus='1:3054232-3054733',
            internal_id='XLOC_000001',
            sample_1='Control',
            sample_2='Treated',
            amount_1=0.0778978,
            amount_2=0.0881688,
            status='OK',
            test_statistic=-0.0754818,
            significant='no')
        test_datum.save()
        self.assertEqual(test_datum.pk,
                         1)  #presumes one model loaded in fixture data
def cufflinks_gene_diff_import(experiment_id, filename):
    '''This function imports the data from a gene_exp.diff into :class:`~data.models.GeneExperimentData` objects.
    
    This function requires a valid experiment_id and a file.
    '''
    
    import decimal
    
    experiment = mRNASeqExperiment.objects.get(pk=experiment_id)
    new_genes = 0
    updated_genes =0
    with open(filename, 'r') as inputfile:
        for row in csv.DictReader(inputfile, delimiter='\t'):
            try: 
                datum = GeneExperimentData(
                     experiment=experiment,
        			 gene=Gene.objects.get(pk=row['gene']),
        			 fold_change = row['log2(fold_change)'],
        			 p_value = row['p_value'],
        			 q_value = row['q_value'],
        			 locus = row['locus'],
        			 internal_id = row['test_id'],
        			 sample_1 = row['sample_1'],
        			 sample_2 = row['sample_2'],
        			 amount_1 = row['value_1'],
        			 amount_2 = row['value_2'],
        			 status = row['status'],
        			 test_statistic = row['test_stat'],
        			 significant = row['significant'])
                datum.save()
                updated_genes += 1
            except Gene.DoesNotExist:
                #create a new gene with that name
                new_gene = Gene(name=row['gene'])
                new_gene.save()
                datum = GeneExperimentData(
                     experiment=experiment,
        			 gene=new_gene,
        			 fold_change = row['log2(fold_change)'],
        			 p_value = row['p_value'],
        			 q_value = row['q_value'],
        			 locus = row['locus'],
        			 internal_id = row['test_id'],
        			 sample_1 = row['sample_1'],
        			 sample_2 = row['sample_2'],
        			 amount_1 = row['value_1'],
        			 amount_2 = row['value_2'],
        			 status = row['status'],
        			 test_statistic = row['test_stat'],
        			 significant = row['significant'])
                datum.save()
                new_genes +=1
    return "Added %i measurements and created %i new genes." %(updated_genes+new_genes, new_genes)