int mpeg4_p2_video_packetizer_c::process(packet_cptr packet) { extract_size(packet->data->get_buffer(), packet->data->get_size()); extract_aspect_ratio(packet->data->get_buffer(), packet->data->get_size()); int result = m_input_is_native == m_output_is_native ? video_packetizer_c::process(packet) : m_input_is_native ? process_native(packet) : process_non_native(packet); ++m_frames_output; return result; }
//processes input file containing structures of interest, in triplet form //similar code to make_cluster: converts triplet to profile, void process_input(FILE *fp) { HASHTBL *halfbrac; FILE *file; char temp[100],tmp[ARRAYSIZE],*profile,*fullprofile,*diff; int i,j,k,*id,last=0,lastprob; int numhelix = 0,fullnum = 0,size = INIT_SIZE,size2 = INIT_SIZE,size3 = INIT_SIZE; if (!(halfbrac = hashtbl_create(HASHSIZE,NULL))) { fprintf(stderr, "ERROR: hashtbl_create() for halfbrac failed"); exit(EXIT_FAILURE); } if (!(input = hashtbl_create(HASHSIZE,NULL))) { fprintf(stderr, "ERROR: hashtbl_create() for input failed"); exit(EXIT_FAILURE); } //longest = hashtbl_get(max,"longest"); profile = malloc(sizeof(char)*ARRAYSIZE*size); fullprofile = malloc(sizeof(char)*ARRAYSIZE*size2); diff = malloc(sizeof(char)*ARRAYSIZE*size3); profile[0] = '\0'; fullprofile[0] = '\0'; diff[0] = '\0'; if (!(file = fopen(INPUT,"r"))) fprintf(stderr,"Cannot open %s\n",INPUT); while (fgets(temp,100,file)) { if (sscanf(temp,"%d %d %d",&i,&j,&k) == 3) { sprintf(tmp,"%d %d",i,j); id = hashtbl_get(bp,tmp); //printf("id is %d for %d %d %d\n",id,i,j,k); if (!id) id = process_native(i,j,k); if (*id != last) { sprintf(tmp,"%d",*id); if (hashtbl_get(freq,tmp)) { //is a freq helix, save to profile numhelix++; if (strlen(profile)+strlen(tmp) > (ARRAYSIZE*size-2)) profile = resize(&size,strlen(profile)+strlen(tmp)+1,profile); //printf("adding %d to profile\n",*id); sprintf(profile,"%s%s ",profile,tmp); } else { if (strlen(diff)+strlen(tmp)+2 > ARRAYSIZE*size3) diff = resize(&size3,strlen(diff)+strlen(tmp)+2,diff); sprintf(diff,"%s%s ",diff,tmp); //printf("printing diff %s\n",diff); } fullnum++; if (strlen(fullprofile)+strlen(tmp) > (ARRAYSIZE*size-2)) fullprofile = resize(&size2,strlen(fullprofile)+strlen(tmp)+2,fullprofile); sprintf(fullprofile,"%s%s ",fullprofile,tmp); //printf("helix %d added is %s\n",fullnum,tmp); last = *id; make_brackets(halfbrac,i,j,*id); } else //if id == last printf("helix %d %d %d is duplicate with id %d: process_input()\n",i,j,k,*id); } else if (sscanf(temp,"Structure %d (%d)",&i,&j) == 2) { if (strlen(fullprofile) == 0) { lastprob = j; continue; } //printf("profile is %s, fullprofile %s with diff %s\n\n",profile,fullprofile,diff); halfbrac = process_input_profile(fp,halfbrac,fullprofile,fullnum,profile,numhelix,diff,lastprob); numhelix = 0; fullnum = 0; profile[0] = '\0'; fullprofile[0] = '\0'; diff[0] = '\0'; lastprob = j; } } //printf("input profile is %s with fullprofile %s and diff %s\n",profile,fullprofile,diff); halfbrac = process_input_profile(fp,halfbrac,fullprofile,fullnum,profile,numhelix,diff,lastprob); free(profile); hashtbl_destroy(halfbrac); //finds edges between centroids find_centroid_edges(fp); }
//process input into three profiles Hs,Hu,Hn //s = selected profiles, u = unselected in sample,n=in native only //connects them, puts Hs in cluster with freq = 0 if not already there int process_one_input(FILE *fp) { HASHTBL *halfbrac; FILE *file; char temp[100],tmp[ARRAYSIZE],*profile,*fullprofile,*diff,*native,*diffn,*dup; int i,j,k,*id,last=0,insample; int numhelix = 0,fullnum = 0,natnum = 0; int size = INIT_SIZE,size2 = INIT_SIZE,size3 = INIT_SIZE,size4 = INIT_SIZE,size5 = INIT_SIZE; if (!(halfbrac = hashtbl_create(HASHSIZE,NULL))) { fprintf(stderr, "ERROR: hashtbl_create() for halfbrac failed"); exit(EXIT_FAILURE); } if (!(input = hashtbl_create(HASHSIZE,NULL))) { fprintf(stderr, "ERROR: hashtbl_create() for input failed"); exit(EXIT_FAILURE); } //longest = hashtbl_get(max,"longest"); profile = malloc(sizeof(char)*ARRAYSIZE*size); fullprofile = malloc(sizeof(char)*ARRAYSIZE*size2); diff = malloc(sizeof(char)*ARRAYSIZE*size3); native = malloc(sizeof(char)*ARRAYSIZE*size4); diffn = malloc(sizeof(char)*ARRAYSIZE*size5); profile[0] = '\0'; fullprofile[0] = '\0'; diff[0] = '\0'; native[0] = '\0'; diffn[0] = '\0'; if (!(file = fopen(INPUT,"r"))) fprintf(stderr,"Cannot open %s\n",INPUT); while (fgets(temp,100,file)) { // if (sscanf(temp,"Structure %d (%d)",&i,&prob) == 2) if (sscanf(temp,"%d %d %d",&i,&j,&k) == 3) { insample = 1; sprintf(tmp,"%d %d",i,j); id = hashtbl_get(bp,tmp); if (!id) { id = process_native(i,j,k); //printf("number in marginals %d\n",hashtbl_numkeys(marginals)); if (*id > hashtbl_numkeys(marginals)) insample = 0; } if (*id != last) { sprintf(tmp,"%d",*id); if (strlen(native)+strlen(tmp) > (ARRAYSIZE*size4-2)) native = realloc(native,ARRAYSIZE*(++size4)); sprintf(native,"%s%s ",native,tmp); natnum++; if (insample) { fullnum++; if (strlen(fullprofile)+strlen(tmp) > (ARRAYSIZE*size2-2)) fullprofile = realloc(fullprofile,ARRAYSIZE*(++size2)); sprintf(fullprofile,"%s%s ",fullprofile,tmp); if (hashtbl_get(freq,tmp)) { //is a freq helix, save to profile numhelix++; if (strlen(profile)+strlen(tmp) > (ARRAYSIZE*size-2)) profile = realloc(profile,ARRAYSIZE*(++size)); //printf("adding %d to profile\n",*id); sprintf(profile,"%s%s ",profile,tmp); } else { //if not freq record diff if (strlen(diff)+strlen(tmp)+2 > ARRAYSIZE*size3) diff = realloc(diff,ARRAYSIZE*(++size3)); sprintf(diff,"%s%s ",diff,tmp); //printf("printing diff %s\n",diff); } } else { if (strlen(diffn)+strlen(tmp)+2 > ARRAYSIZE*size5) diffn = realloc(diffn,ARRAYSIZE*(++size5)); sprintf(diffn,"%s%s ",diffn,tmp); } last = *id; make_brackets(halfbrac,i,j,*id); } else if (VERBOSE) printf("helix %d %d %d is duplicate with id %d: process_input()\n",i,j,k,*id); } } native = sort_input(native,natnum); //printf("native is now %s\n",native); make_bracket_rep(halfbrac,native); hashtbl_destroy(halfbrac); fullprofile = sort_input(fullprofile,fullnum); profile = sort_input(profile,numhelix); //printf("native %s, fullprofile %s, profile %s, diff %s, diffn %s\n",native,fullprofile,profile,diff,diffn); if (fullnum != natnum) make_edge_and_node(fp,fullprofile,native,diffn,natnum); if (numhelix != fullnum) make_edge_and_node(fp,profile,fullprofile,diff,fullnum); fprintf(fp,"\"%s\" [style = filled, fillcolor = gray60];\n",profile); sprintf(tmp,"%d ",numhelix); if (strlen(tmp)+strlen(profile) > ARRAYSIZE*size+1) profile = realloc(profile,ARRAYSIZE*(++size)); dup = mystrdup(profile); sprintf(profile,"%s%s",tmp,dup); id = hashtbl_get(cluster,profile); free(dup); if (!id) { id = malloc(sizeof(int)); *id = 0; hashtbl_insert(cluster,profile,id); //printf("inserting input %s into cluster\n",profile); } free(profile); return numhelix; }