예제 #1
0
/* @brief	For bases, differentiate by (base, #occur); For deletions,
 * 			differentiate by (D, #); for insertions, differentiate by
 * 			(I, ins_str)
 *
 * @param	[nuvars]: vars that were not previously called in [gvars]
 */
void pileup (var_t& nuvars, pileup_list_t& nulist, pileup_list_t& rmlist,
		const pileup_list_t& pileuplist, const var_t& gvars,
		const col_t& col, const std::vector<jeb_t>& jeb,
		const GlobalParam& gParam, int iter) {

	//{
	//	std::cout << "pos = " << col.ref_pos << "\n";
 	//}
	int threshold = INT_MAX;

 	// ---------- generate profile and calculate lamda -------------
	pileup_profile_t profile_info;
	strset_t vars;
	if (iter == 0) { // first iteration pop up the pic

		pileup_profiling (profile_info, col, jeb, gParam);

		if (profile_info.lamda_L) {
			threshold = getThreshold (profile_info.lamda_L,
					profile_info.p_L, gParam.bonferroni);
			// ----------------- analyze profile and call vars ------------------
			if (call_pileup_variant (vars, threshold, profile_info.LProfile))	{
				nulist.L.insert(col.ref_pos);
			}
		}

		if (profile_info.lamda_S) {
			threshold = getThreshold (profile_info.lamda_S,
					profile_info.p_S, gParam.bonferroni);
			if (call_pileup_variant (vars, threshold, profile_info.SProfile)) {
				nulist.S.insert(col.ref_pos);
			}
		}

		add_var_entry (nuvars, col.ref_pos, vars);

		{
		//	debug_print_var (nuvars);
		}
	} else { // not the first iteration
		if (pileuplist.L.count(col.ref_pos) || pileuplist.S.count(col.ref_pos)) {

			pileup_profiling (profile_info, col, jeb, gParam);

			if (profile_info.lamda_L && pileuplist.L.count(col.ref_pos)) {
				threshold = getThreshold (profile_info.lamda_L,
						profile_info.p_L, gParam.bonferroni);
				if (! call_pileup_variant (vars, threshold, profile_info.LProfile)){
					rmlist.L.insert(col.ref_pos);
				}
			}

			if (profile_info.lamda_S && pileuplist.S.count(col.ref_pos)) {
				threshold = getThreshold (profile_info.lamda_S,
						profile_info.p_S, gParam.bonferroni);
				if (! call_pileup_variant (vars, threshold, profile_info.SProfile)) {
					rmlist.S.insert(col.ref_pos);
				}
			}

			// identify variants that were not yet in [gvars]
			var_t::const_iterator it_gvar = gvars.find(col.ref_pos);
			if (it_gvar != gvars.end()) {
				strset_t diffs;
				strset_t::const_iterator it_s = vars.begin();
				for (; it_s != vars.end(); ++ it_s){
					if (!it_gvar->second.count(*it_s)) diffs.insert(*it_s);
				}
				if (diffs.size()) add_var_entry(nuvars, col.ref_pos, diffs);
			} else add_var_entry (nuvars, col.ref_pos, vars);

			{
				//debug_print_var (nuvars);
			}

		} // if

	} // else
} // pileup
예제 #2
0
// adds an entry in the variable and handles arrays,
// if spec is a struct specifier definition, 
//   it will only check if struct is declared
// if spec is a struct specifier anonymous definition,
//   anonymous_struct is used.
struct var_entry *
symtab_add_variable(struct tree_node * spec, struct tree_node * vardec) {
	assert(spec -> unit_name == NODE_SPECIFIER);
	assert(vardec -> unit_name == NODE_VARDEC);

	// if variable with same name exists, just return NULL
	
	// getting name requires a deep-in digging.
    struct tree_node * identifier = vardec;
    while (identifier -> flags == FLAG_VARDEC_ARRAY) identifier = identifier -> children[0];
    identifier = identifier -> children[0];
    assert(identifier -> unit_name == TOKEN_IDENTIFIER);
	struct var_entry * e = add_var_entry(identifier -> id_extra -> name);
	if (e == NULL) {
		e = search_var_entry(identifier -> id_extra -> name);
		if (e != NULL) {
			semerrorpos(ERROR_VARIABLE_CONFLICT, vardec -> line);
			printf("variable \'%s\' already declared at line %d\n",
					e -> name, e -> defined_at);
		} else {
			struct struct_entry * se = search_struct_entry(identifier -> id_extra -> name);
			semerrorpos(ERROR_OTHER, vardec -> line);
			printf("variable \'%s\' name conflicts with struct declared at line %d\n",
				se -> name, se -> defined_at);
		}
		return NULL;
	}
	// if spec is basic type, just next
	if (spec -> flags == FLAG_SPECIFIER_BASIC) ;
	// if spec is struct, check if that struct exists
	struct struct_entry * strent = NULL;
	if (spec -> flags == FLAG_SPECIFIER_STRUCT) {
		
		const char *s_name;
		if (spec -> children[0] -> flags == FLAG_STRUCTSPECIFIER_DEC) {
			s_name = spec -> children[0] -> children[1] -> children[0] -> id_extra -> name;
			strent = search_struct_entry(s_name);
			if (strent == NULL) {
				semerrorpos(ERROR_STRUCT_UNDEFINED, vardec -> line);
				printf("struct \'%s\' not declared\n", s_name);
				return NULL;
			} else if (strent -> is_defined == 0) {
				semerrorpos(ERROR_STRUCT_UNDEFINED, vardec -> line);
				printf("struct \'%s\' is not defined\n", s_name);
				return NULL;
			}
		} else if (spec -> children[0] -> flags == FLAG_STRUCTSPECIFIER_DEF) {
		    // a variable declared simultaneously with struct definition
			if (spec -> children[0] -> children[1] -> flags == FLAG_OPTTAG_TAGGED) {
				s_name = spec -> children[0] -> children[1] -> children[0] -> id_extra -> name;
				strent = search_struct_entry(s_name);
				if (strent == NULL) {
					semerrorpos(ERROR_STRUCT_UNDEFINED, vardec -> line);
					printf("struct \'%s\' is not defined\n", s_name);
					return NULL;
				}
			} else if (spec -> children[0]-> children[1] -> flags == FLAG_OPTTAG_EMPTY) {
			    // an anonymous struct
				strent = get_anonymous_struct();
				if (strent == NULL) {
					semerrorpos(ERROR_OTHER, vardec -> line);
					printf("anonymous struct not set\n");
					return NULL;
				}
			} else assert(0);
		} else assert(0);
	} // end if (spec -> flags == FLAG_SPECIFIER_STRUCT)
	// now e points to a var_entry, filled with name
	// spec points to a valid spec
	e -> defined_at = identifier -> line;
	if (vardec -> flags == FLAG_VARDEC_ARRAY) {
		e -> type_flag = TYPE_ARRAY;
		if (spec -> flags == FLAG_SPECIFIER_BASIC)
			e -> t.array_type = construct_basic_array_type(spec, vardec);
		else if (spec -> flags == FLAG_SPECIFIER_STRUCT)
			e -> t.array_type = construct_struct_array_type(strent, vardec);
	} else if (spec -> flags == FLAG_SPECIFIER_BASIC) {
		e -> type_flag = TYPE_BASIC;
		e -> t.basic_type = spec -> children[0] -> type_name;
	} else {
		assert(spec -> flags == FLAG_SPECIFIER_STRUCT);
		e -> type_flag = TYPE_STRUCT;
		e -> t.struct_type = strent;
	}
	return e;
} // end of function symtab_add_variable