~ubuntu-branches/ubuntu/utopic/r-cran-genabel/utopic

« back to all changes in this revision

Viewing changes to src/interactions_rare_recesive_alleles.cpp

  • Committer: Package Import Robot
  • Author(s): Andreas Tille, Charles Plessy, Andreas Tille
  • Date: 2014-08-07 17:30:04 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140807173004-24c20tmrw61yl5dz
Tags: 1.8-0-1
[ Charles Plessy ]
* debian/control: removed myself from Uploaders.

[ Andreas Tille ]
* New upstream version
* Moved debian/upstream to debian/upstream/metadata
* cme fix dpkg-control
* More detailed copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
//__________________________________________________________________________________________
103
103
int snp_snp_interaction_results::push_chi2(float chi2, unsigned central_snp_position, unsigned window_snp_position)
104
104
{
105
 
static int window_current;
 
105
static unsigned int window_current;
106
106
window_current = snp_number - central_snp_position;
107
107
if(window_current > window) window_current=window;
108
108
 
109
 
if(central_snp_position >= snp_number || central_snp_position <0) {Rprintf("snp_snp_interaction_results::push_chi2: error: central_snp_position is out of bound"); return -1;}
110
 
if(window_snp_position > window_current || window_snp_position<0) {Rprintf("snp_snp_interaction_results::push_chi2: error: window is out of bound"); return -1;}        
 
109
if(central_snp_position >= snp_number) {Rprintf("snp_snp_interaction_results::push_chi2: error: central_snp_position is out of bound"); return -1;}
 
110
if(window_snp_position > window_current) {Rprintf("snp_snp_interaction_results::push_chi2: error: window is out of bound"); return -1;} 
111
111
chi2_results[central_snp_position][window_snp_position] = chi2;
112
112
//std::cout<<"snp_snp_interaction_results::push_chi2 end\n";
113
113
return 0;
141
141
//__________________________________________________________________________________________
142
142
unsigned snp_snp_interaction_results::get_current_window(unsigned central_snp_position)
143
143
{
144
 
static int window_current;
 
144
static unsigned int window_current;
145
145
window_current = snp_number - central_snp_position - 1;
146
146
if(window_current > window) window_current=window;
147
147
 
161
161
 
162
162
//find first ellement which is not NA. If there is only NAs then return NA
163
163
//_____________________________________________
164
 
for(int i = 0 ; i<number; i++)
 
164
for(unsigned i = 0 ; i<number; i++)
165
165
        {
166
166
        if(ISNAN(array[i])) 
167
167
                {
178
178
//_____________________________________________
179
179
 
180
180
 
181
 
for(int i = 1; i<number; i++)
 
181
for(unsigned i = 1; i<number; i++)
182
182
        {
183
183
        if(ISNAN(array[i])) continue;
184
184
        if(array[i] > max)
255
255
        return chi2_test_yates(m);
256
256
        }
257
257
 
 
258
 
 
259
return -1;
258
260
}       
259
261
 
260
262
 
309
311
        }
310
312
}
311
313
 
312
 
double independence_test_2x2(int *x1, int *x2, int* y, int N, unsigned snp1_position, unsigned snp2_position, INDEPENDENCE_TEST_NAME_ENUM test_name, int min_expected_cut_off) 
 
314
double independence_test_2x2(int *x1, int *x2, int* y, unsigned int N, unsigned snp1_position, unsigned snp2_position, INDEPENDENCE_TEST_NAME_ENUM test_name, int min_expected_cut_off) 
313
315
        {
314
316
        static double matrix[2][2];
315
317
 
417
419
 
418
420
 
419
421
 
420
 
int num_ids                                                             = INTEGER_VALUE(num_ids_);
421
 
int num_snps                                                              = INTEGER_VALUE(num_snps_);
 
422
unsigned num_ids                                        = unsigned(INTEGER_VALUE(num_ids_));
 
423
unsigned num_snps                                       = unsigned(INTEGER_VALUE(num_snps_));
422
424
int *trait_binary                                                               = INTEGER(trait_binary_);
423
 
int window                                                              = INTEGER_VALUE(window_);
 
425
unsigned window                                         = unsigned(INTEGER_VALUE(window_));
424
426
int min_expected_cut_off        = INTEGER_VALUE(min_expected_cut_off_); // if observed value less then min_expected_cut_off then perform fisfer or yates
425
427
bool return_all_result                                  = LOGICAL_VALUE(return_all_result_); //if true then returns vector with maximum chisq and for each snp and matrix with chi2s where each row corresponds to a snp and a column corresponds to a snp with which interaction is tested with
426
428
 
515
517
unsigned step=10000;
516
518
 
517
519
float chi2;
518
 
int window_current=window;
 
520
unsigned window_current=window;
519
521
 
520
522
//in this loop the tests between two snps within a window is done. In each iteration tests between a "central" snp and snp around (withn a window) are done.
521
523
for(unsigned snp_counter=0 ; snp_counter<num_snps-1 ; snp_counter++) //enumerate eache snp in genome
616
618
 
617
619
UNPROTECT(1);
618
620
 
619
 
delete snp1, snp2;
 
621
delete [] snp1;
 
622
delete [] snp2;
620
623
 
621
624
return(results_R);
622
625
} //end of interaction_rare_recesive_allele_C_