Example #1
0
void TKeyboard::Start(String banner, uint8_t set= KBMAJ)
{
  dbgprintln("TKeyboard Start");
  state = false;
  Caption = "";
  Banner = banner;
  switch(set){
    case KBMAJ: Set1();break;
    case KBNUM: Set2();break;
    case KBMIN: Set3();break;
    case KBPHONE: Set4();break;
    default:break;
  }
}
Example #2
0
void TKeyboard::SetMn()
{
  if (Key[0][0]->Caption == "Q") 
    Set3();
    else Set1();
}
static constexpr uint64_t Set1(const uint32_t aBits) {
    return aBits == 0 ? 0 : 1 | (Set1(aBits - 1) << 1);
}
Example #4
0
//------------------------------------------------------------
//Function merges two data sets fast. Storages it in "const char *set_mereged". This function is performed form R code.
void fast_merge_C_(char *set1, int *num_ids1_, int *num_snps1_,
			 					   char *set2, int *num_ids2_, int *num_snps2_,
									 unsigned *num_ids_intersected, unsigned *num_snps_intersected, unsigned *snp_intersected, unsigned *ids_intersected,
									 bool *replace_na_,
									 char *strand_set1, char *strand_set2,
									 char *coding_set1, char *coding_set2,
									 char *alleleID, char **alleleID_names, unsigned *alleleID_amount,
									 char *alleleID_reverse_array,
									 unsigned *error_amount_,
									 unsigned *found_error_amount_snp,
									 unsigned *found_error_amount_id,
									 unsigned *id_position_error, unsigned *id_snpposition_error, char *val_set1_error, char *val_set2_error,
									 unsigned *snp_position_error, char* snp_set1_codding_error, char* snp_set2_codding_error,
									 bool *user_want_to_look_at_strand_,
									 char *set_mereged)
{

		
bool user_want_to_look_at_strand = *user_want_to_look_at_strand_;
bool replace_na = *replace_na_;





std::map<std::string, std::string> complemetntary;
complemetntary["AT"];
complemetntary["at"];
complemetntary["TA"];
complemetntary["ta"];
complemetntary["CG"];
complemetntary["cg"];
complemetntary["GC"];
complemetntary["gc"];









//---------------------------------
std::map<char, char*> coding_polymorphism_map;

unsigned alleleID_amount_ = *alleleID_amount;
unsigned error_amount = *error_amount_;
int error_amount_tmp = *error_amount_; 
unsigned snp_error_counter=0; //this is counter for function recoding_snp_data_under_coding_and_strand 


for(unsigned i=0 ; i<alleleID_amount_ ; i++)
	{
	coding_polymorphism_map[alleleID[i]] = alleleID_names[i];
	}
//---------------------------------




//---------------------------------
std::map<char, char> alleleID_reverse;
for(unsigned i=0 ; i<*alleleID_amount ; i++)
	{
	alleleID_reverse[alleleID[i]] = alleleID_reverse_array[i];
	}
//---------------------------------




Search search(snp_intersected, ids_intersected, *num_snps_intersected, *num_ids_intersected);


unsigned shift_i=0;

unsigned num_ids1  = *num_ids1_,
	  		 num_snps1 = *num_snps1_,
				 num_ids2  = *num_ids2_,
	 			 num_snps2 = *num_snps2_;

const unsigned snps_sum = num_snps1 + num_snps2;
unsigned num_ids_total_in_new_set  = num_ids1 + num_ids2 - *num_ids_intersected;  // total amount of IDs
unsigned num_snps_total_in_new_set = snps_sum - *num_snps_intersected; // total amount of SNPs





gtps_container Set1(set1, strand_set1, coding_set1, num_ids1, num_snps1);	//creat object to facilitate working with set1
gtps_container Set2(set2, strand_set2, coding_set2, num_ids2, num_snps2);	//creat object to facilitate working with set2

gtps_container Set_merged(set_mereged, num_ids_total_in_new_set, num_snps_total_in_new_set); //Here we will storage our merged set

	

char set1_val, set2_val;
unsigned errors_counter_id=0;


//Start to merge. The mearged set will in the end 
for(unsigned i=1 ; i<=snps_sum ; i++)
	{
	if(i <= num_snps1)
		{

			for(unsigned k=1 ; k<=num_ids1 ; k++)
				{
				Set_merged.set(k, i, Set1.get(k, i));
				}//all data from current snp of set1 is copied to new set. Congratulations!!!

			
			if(unsigned snp_in_set2=search.what_snp_is_in_set2(i)) //snp_in_set2 is number of snp in set2 which is intersected with snp with number i 
				{
				//Variable snp_in_set2 storages snp number which corresponds with snp in set1. In other words snp with number snp_in_set2 in snp2 and current snp in set1 is similar. Not clear?
				//Now we need to copy data from set2. Without intersectioning IDs!
				unsigned int shift_k=0;
				for(unsigned k=1 ; k<=num_ids2 ; k++)
					{
					set2_val = Set2.get(k, snp_in_set2);
					
					
					set2_val = recoding_snp_data_under_coding_and_strand(set2_val, &Set2, &Set1, snp_in_set2, i, &coding_polymorphism_map, &alleleID_reverse , snp_position_error, snp_set1_codding_error, snp_set2_codding_error, &error_amount_tmp, found_error_amount_snp, &snp_error_counter, user_want_to_look_at_strand, &complemetntary);	
					
					if(unsigned id_num_in_set1 = search.what_id_is_in_set1(k)) //This means that current id and current snp belong for both set
				 		{
						set1_val = Set1.get(id_num_in_set1, i);
//						set2_val = Set2.get(k, snp_in_set2);
						
//							set2_val = recoding_snp_data_under_coding_and_strand(set2_val, &Set2, &Set1, snp_in_set2, i, &coding_polymorphism_map, &alleleID_reverse , snp_position_error, snp_set1_codding_error, snp_set2_codding_error, &error_amount_tmp, found_error_amount_snp, &snp_error_counter, user_want_to_look_at_strand, &complemetntary);	
							if(error_amount_tmp == -1)
								{
								//Function "recoding_snp_data_under_coding_and_strand" changed it to -1 because amount of errors a lot and we have to finish merging.
								return;
								}


					
						if(set1_val != set2_val)
							{

							// condition added by Yurii: avoid too many errors when
							// merging sets with largely different # of genotyped SNPs
							if (!(replace_na && (set1_val==0 || set2_val==0))) {
									id_position_error[errors_counter_id]=id_num_in_set1;
									id_snpposition_error[errors_counter_id]=i;
									val_set1_error[errors_counter_id]=set1_val;
									val_set2_error[errors_counter_id]=set2_val;
									errors_counter_id++;
							}


							if(errors_counter_id >= error_amount) 
								{
								*found_error_amount_id = errors_counter_id;
								Rprintf("ID:Error: Too many errors while merging sets (see error table). Change error_amount value to increase error-table size.\n");
								return;
								}

								
								//Replace NA if it is not forbiden by user
								if(replace_na)
									{	
									if( int(set1_val) == 0 && int(set2_val) != 0 )
										{
										//Set_merged.set(id_num_in_set1, i, Set2.get(k,snp_in_set2));
										Set_merged.set(id_num_in_set1, i, set2_val);
										}
									}
							}

						shift_k++;
					 	continue;
						}

					//Set_merged.set(k - shift_k + num_ids1, i, Set2.get(k,snp_in_set2));
					Set_merged.set(k - shift_k + num_ids1, i, set2_val);
					}
				}


		}
	else
		{
		unsigned shift_k=0;
		
		
		if(search.is_it_snp_in_set1(i-num_snps1))
	 		{
			shift_i++; 
			continue;
			} // This snp has storaged already for both sets.
		
		for(unsigned k=1 ; k<=num_ids2 ; k++)
			{
			if(unsigned num_id_in_set1 = search.what_id_is_in_set1(k))
					{
					Set_merged.set(num_id_in_set1, i-shift_i, Set2.get(k, i-num_snps1));
					shift_k++;
					}
			else	
				{
				Set_merged.set(k-shift_k+num_ids1, i-shift_i, Set2.get(k, i-num_snps1));
				}
		
			}
			
		}


	
	}//end of for cycle




*found_error_amount_id = errors_counter_id;
}