int32 abAbacus::addContig() { if (tigStore) uma = tigStore->loadMultiAlign(iid, type == AS_UNITIG); if (uma == NULL) fprintf(stderr,"Lookup failure in CNS: MultiAlign for unitig %d could not be found.\n",iid); assert(uma != NULL); // Contigs used to be added gapped, unitigs as ungapped. // This caused no end of trouble in MergeMultiAligns and // ReplaceEndUnitigInContig. ResetVA_char(ungappedSequence); ResetVA_char(ungappedQuality); GetMultiAlignUngappedConsensus(uma, ungappedSequence, ungappedQuality); sequence = Getchar(ungappedSequence,0); quality = Getchar(ungappedQuality,0); fragment.length = GetMultiAlignUngappedLength(uma); fragment.utype = (type == AS_UNITIG) ? utype : AS_OTHER_UNITIG; fragment.n_components = GetNumIntMultiPoss(uma->f_list) + GetNumIntUnitigPoss(uma->u_list); fragment.components = SetUngappedFragmentPositions(type, fragment.n_components, uma); //fprintf(stderr, "AppendFragToLocalStore()-- TIG %d len=%d\n", iid, fragment.length); }
unsigned char Get_character() { unsigned char ret; Printf("Enter a character: "); ret = Getchar(); ret = Getchar(); return ret; }
static void getword(int first, int (*tst)(int)) { int i=0, c; yytext[i++]= (char) first; while (tst(c = Getchar())) { yytext[i++] = (char) c; if (c == '\\') { c = Getchar(); yytext[i++] = (char) c; /* no tst */ } } yytext[i] = '\0'; Ungetch(c); }
static int getinline(void) { int c; if (ReDiRect) { c = *ReDiRect++; if (c == '\0') { ReDiRect = (char *) 0; c = *Inliner[Inlining]++; } } else { c = *Inliner[Inlining]++; } if (c == '\0') { lineno = Inline_stub[Inlining]->cln; Fname = Inline_stub[Inlining]->cfn; Inlining--; #if 0 if (verbose&32) printf("spin: %s:%d, done inlining %s\n", Fname, lineno, Inline_stub[Inlining+1]->nm->name); #endif return Getchar(); } return c; }
int ncss_Getchar(void) { int c; static int blankline = 1; if ((c = Getchar()) != EOF) { if (blankline) { if (!ISSPACE(c)) { blankline = 0; } } else { if (c == '\n') { c = T_NCNULINE; blankline = 1; } } } else { blankline = 1; } if (c == T_NCNULINE) ncss_Line++; return c; }
static void ncss(FILE *in, int *linesp, int *nclinesp) { int c; int lines = 0; int nclines = 0; int boline = 1; while ((c = Getchar()) != EOF) { if (c == '\n') { lines++; boline = 1; } else if (boline && !ISSPACE(c)) { boline = 0; nclines++; } } *linesp = lines; *nclinesp = nclines; }
bool buildUTGMessage(int32 ID, SnapUnitigMesg *utg) { MultiAlignT *ma = ScaffoldGraph->tigStore->loadMultiAlign(ID, TRUE); if (ma == NULL) return(false); utg->eaccession = AS_UID_fromInteger(getUID(uidServer)); utg->iaccession = ID; utg->coverage_stat = ScaffoldGraph->tigStore->getUnitigCoverageStat(ID); utg->microhet_prob = ScaffoldGraph->tigStore->getUnitigMicroHetProb(ID); utg->status = ScaffoldGraph->tigStore->getUnitigStatus(ID); utg->status = (utg->status == AS_UNASSIGNED ? AS_UNIQUE : utg->status); utg->length = GetMultiAlignLength(ma); utg->consensus = Getchar(ma->consensus, 0); utg->quality = Getchar(ma->quality, 0); utg->forced = 0; utg->num_frags = GetNumIntMultiPoss(ma->f_list); utg->num_vars = 0; utg->f_list = (SnapMultiPos*)safe_malloc(utg->num_frags * sizeof(SnapMultiPos)); utg->v_list = NULL; if (utg->consensus == NULL) fprintf(stderr, "buildUTGMessage()-- unitig %d missing consensus sequence\n", utg->iaccession); assert(utg->consensus != NULL); if (utg->length != strlen(utg->consensus)) fprintf(stderr, "buildUTGMessage()-- unitig %d length %d != consensus string length "F_SIZE_T"\n", utg->iaccession, utg->length, strlen(utg->consensus)); assert(utg->length == strlen(utg->consensus)); for (int32 i=0; i<utg->num_frags; i++) { IntMultiPos *imp = GetIntMultiPos(ma->f_list, i); utg->f_list[i].type = imp->type; utg->f_list[i].eident = FRGmap.lookup(imp->ident); utg->f_list[i].position = imp->position; utg->f_list[i].delta_length = imp->delta_length; utg->f_list[i].delta = imp->delta; } return(true); }
static int follow(int tok, int ifyes, int ifno) { int c; if ((c = Getchar()) == tok) { return ifyes; } Ungetch(c); return ifno; }
char GetName() { char c = Look; if (!isalpha(Look)) { sprintf(tmp, "Name"); Expected(tmp); } Getchar(); return toupper(c); }
void Match(char x) { if (Look == x) { Getchar(); } else { sprintf(tmp, "'%c'", x); Expected(tmp); } }
static int pre_proc(void) { char b[512]; int c, i = 0; b[i++] = '#'; while ((c = Getchar()) != '\n' && c != EOF) { b[i++] = (char) c; } b[i] = '\0'; yylval = nn(ZN, 0, ZN, ZN); yylval->sym = lookup(b); return PREPROC; }
static void decomment_file(char *fname, FILE *f) { int c; extern int Cppflag; Input = f; Cppflag = 1; while ((c = Getchar()) != EOF) { putc(c, stdout); } }
static void do_directive(int first) { int c = first; /* handles lines starting with pound */ getword(c, isalpha_); if (strcmp(yytext, "#ident") == 0) goto done; if ((c = Getchar()) != ' ') fatal("malformed preprocessor directive - # .", 0); if (!isdigit_(c = Getchar())) fatal("malformed preprocessor directive - # .lineno", 0); getword(c, isdigit_); lineno = atoi(yytext); /* pickup the line number */ if ((c = Getchar()) == '\n') return; /* no filename */ if (c != ' ') fatal("malformed preprocessor directive - .fname", 0); if ((c = Getchar()) != '\"') { printf("got %c, expected \" -- lineno %d\n", c, lineno); fatal("malformed preprocessor directive - .fname (%s)", yytext); } getword(Getchar(), notquote); /* was getword(c, notquote); */ if (Getchar() != '\"') fatal("malformed preprocessor directive - fname.", 0); /* strcat(yytext, "\""); */ Fname = lookup(yytext); done: while (Getchar() != '\n') ; }
void precondition(char *q) { int c, nest = 1; for (;;) { c = Getchar(); *q++ = c; switch (c) { case '\n': lineno++; break; case '[': nest++; break; case ']': if (--nest <= 0) { *--q = '\0'; return; } break; } } fatal("cannot happen", (char *) 0); /* unreachable */ }
void moveloop() { #if defined(MICRO) || defined(WIN32) char ch; int abort_lev; #endif int moveamt = 0, wtcap = 0, change = 0; boolean didmove = FALSE, monscanmove = FALSE; flags.moonphase = phase_of_the_moon(); if(flags.moonphase == FULL_MOON) { You("are lucky! Full moon tonight."); change_luck(1); } else if(flags.moonphase == NEW_MOON) { pline("Be careful! New moon tonight."); } flags.friday13 = friday_13th(); if (flags.friday13) { pline("Watch out! Bad things can happen on Friday the 13th."); change_luck(-1); } initrack(); /* Note: these initializers don't do anything except guarantee that we're linked properly. */ decl_init(); monst_init(); monstr_init(); /* monster strengths */ objects_init(); commands_init(); (void) encumber_msg(); /* in case they auto-picked up something */ u.uz0.dlevel = u.uz.dlevel; youmonst.movement = NORMAL_SPEED; /* give the hero some movement points */ for(;;) { get_nh_event(); #ifdef POSITIONBAR do_positionbar(); #endif didmove = flags.move; if(didmove) { /* actual time passed */ youmonst.movement -= NORMAL_SPEED; do { /* hero can't move this turn loop */ wtcap = encumber_msg(); flags.mon_moving = TRUE; do { monscanmove = movemon(); if (youmonst.movement >= NORMAL_SPEED) { curmonst = &youmonst; break; /* it's now your turn */ } } while (monscanmove); flags.mon_moving = FALSE; if (!monscanmove && youmonst.movement < NORMAL_SPEED) { /* both you and the monsters are out of steam this round */ /* set up for a new turn */ struct monst *mtmp; mcalcdistress(); /* adjust monsters' trap, blind, etc */ /* reallocate movement rations to monsters */ for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) mtmp->movement += mcalcmove(mtmp); if(!rn2(u.uevent.udemigod ? 25 : (depth(&u.uz) > depth(&stronghold_level)) ? 50 : 70)) (void) makemon((struct permonst *)0, 0, 0, NO_MM_FLAGS); /* calculate how much time passed. */ #ifdef STEED if (u.usteed && u.umoved) { /* your speed doesn't augment steed's speed */ moveamt = mcalcmove(u.usteed); } else #endif { moveamt = youmonst.data->mmove; if (Very_fast) { /* speed boots or potion */ /* average movement is 1.67 times normal */ moveamt += NORMAL_SPEED / 2; if (rn2(3) == 0) moveamt += NORMAL_SPEED / 2; } else if (Fast) { /* average movement is 1.33 times normal */ if (rn2(3) != 0) moveamt += NORMAL_SPEED / 2; } } switch (wtcap) { case UNENCUMBERED: break; case SLT_ENCUMBER: moveamt -= (moveamt / 4); break; case MOD_ENCUMBER: moveamt -= (moveamt / 2); break; case HVY_ENCUMBER: moveamt -= ((moveamt * 3) / 4); break; case EXT_ENCUMBER: moveamt -= ((moveamt * 7) / 8); break; default: break; } youmonst.movement += moveamt; if (youmonst.movement < 0) youmonst.movement = 0; settrack(); monstermoves++; moves++; /********************************/ /* once-per-turn things go here */ /********************************/ if (flags.bypasses) clear_bypasses(); if(Glib) glibr(); nh_timeout(); run_regions(); if (u.ublesscnt) u.ublesscnt--; if(flags.time && !flags.run) flags.botl = 1; /* One possible result of prayer is healing. Whether or * not you get healed depends on your current hit points. * If you are allowed to regenerate during the prayer, the * end-of-prayer calculation messes up on this. * Another possible result is rehumanization, which requires * that encumbrance and movement rate be recalculated. */ if (u.uinvulnerable) { /* for the moment at least, you're in tiptop shape */ wtcap = UNENCUMBERED; } else if (Upolyd && youmonst.data->mlet == S_EEL && !is_pool(u.ux,u.uy) && !Is_waterlevel(&u.uz) && !(u.uswallow && u.ustuck->data == &mons[PM_WATER_ELEMENTAL])) { if (u.mh > 1) { u.mh--; flags.botl = 1; } else if (u.mh < 1) killer_format = KILLED_BY_AN, rehumanize("inability to breathe air"); } else if (Upolyd && u.mh < u.mhmax) { if (u.mh < 1) rehumanize(0); else if (Regeneration || (wtcap < MOD_ENCUMBER && !(moves%20))) { flags.botl = 1; u.mh++; } } else if (u.uhp < u.uhpmax && (wtcap < MOD_ENCUMBER || !u.umoved || Regeneration)) { if (u.ulevel > 9 && !(moves % 3)) { int heal, Con = (int) ACURR(A_CON); if (Con <= 12) { heal = 1; } else { heal = rnd(Con); if (heal > u.ulevel-9) heal = u.ulevel-9; } flags.botl = 1; u.uhp += heal; if(u.uhp > u.uhpmax) u.uhp = u.uhpmax; } else if (Regeneration || (u.ulevel <= 9 && !(moves % ((MAXULEV+12) / (u.ulevel+2) + 1)))) { flags.botl = 1; u.uhp++; } } /* moving around while encumbered is hard work */ if (wtcap > MOD_ENCUMBER && u.umoved) { if(!(wtcap < EXT_ENCUMBER ? moves%30 : moves%10)) { if (Upolyd && u.mh > 1) { u.mh--; } else if (!Upolyd && u.uhp > 1) { u.uhp--; } else { You("pass out from exertion!"); exercise(A_CON, FALSE); fall_asleep(-10, FALSE); } } } if ((u.uen < u.uenmax) && ((wtcap < MOD_ENCUMBER && (!(moves%((MAXULEV + 8 - u.ulevel) * (Role_if(PM_WIZARD) ? 3 : 4) / 6)))) || Energy_regeneration)) { u.uen += rn1((int)(ACURR(A_WIS) + ACURR(A_INT)) / 15 + 1,1); if (u.uen > u.uenmax) u.uen = u.uenmax; flags.botl = 1; } if(!u.uinvulnerable) { if(Teleportation && !rn2(85)) { xchar old_ux = u.ux, old_uy = u.uy; tele(); if (u.ux != old_ux || u.uy != old_uy) { if (!next_to_u()) { check_leash(old_ux, old_uy); } #ifdef REDO /* clear doagain keystrokes */ pushch(0); savech(0); #endif } } /* delayed change may not be valid anymore */ if ((change == 1 && !Polymorph) || (change == 2 && u.ulycn == NON_PM)) change = 0; if(Polymorph && !rn2(100)) change = 1; else if (u.ulycn >= LOW_PM && !Upolyd && !rn2(80 - (20 * night()))) change = 2; if (change && !Unchanging) { if (multi >= 0) { if (occupation) stop_occupation(); else nomul(0); if (change == 1) polyself(FALSE); else you_were(); change = 0; } } if(u.utrap && u.utraptype == TT_LAVA) { if(!is_lava(u.ux,u.uy)) u.utrap = 0; else if (!u.uinvulnerable) { u.utrap -= 1<<8; if(u.utrap < 1<<8) { killer_format = KILLED_BY; killer = "molten lava"; You("sink below the surface and die."); done(DISSOLVED); } else if(didmove && !u.umoved) { Norep("You sink deeper into the lava."); u.utrap += rnd(4); } } } } if(Searching && multi >= 0) (void) dosearch0(1); dosounds(); /* hack - make sure damage from storms is not blamed on the player */ flags.mon_moving = TRUE; do_storms(); flags.mon_moving = FALSE; gethungry(); age_spells(); exerchk(); invault(); if (u.uhave.amulet) amulet(); if (!rn2(40+(int)(ACURR(A_DEX)*3))) u_wipe_engr(rnd(3)); if (u.uevent.udemigod && !u.uinvulnerable) { if (u.udg_cnt) u.udg_cnt--; if (!u.udg_cnt) { intervene(); u.udg_cnt = rn1(200, 50); } } restore_attrib(); /* underwater and waterlevel vision are done here */ if (Is_waterlevel(&u.uz)) movebubbles(); else if (Underwater) under_water(0); /* vision while buried done here */ else if (u.uburied) under_ground(0); /* when immobile, count is in turns */ if(multi < 0) { if (++multi == 0) { /* finished yet? */ unmul((char *)0); /* if unmul caused a level change, take it now */ if (u.utotype) deferred_goto(); } } } } while (youmonst.movement<NORMAL_SPEED); /* hero can't move loop */ /******************************************/ /* once-per-hero-took-time things go here */ /******************************************/ curmonst = &youmonst; } /* actual time passed */ /****************************************/ /* once-per-player-input things go here */ /****************************************/ find_ac(); if(!flags.mv || Blind) { /* redo monsters if hallu or wearing a helm of telepathy */ if (HHallucination && !Halluc_resistance) { /* update screen randomly */ /* see_monsters(); see_objects(); see_traps(); if (u.uswallow) swallowed(0); */ if (u.uswallow) { swallowed(1); } else if (Underwater && !Is_waterlevel(&u.uz)) { under_water(1); } else if (u.uburied) { under_ground(1); } else { register int x, y; register struct rm *lev; vision_recalc(2); /*clear_nhwindow(WIN_MAP);*/ clear_glyph_buffer(); for (x = 1; x < COLNO; x++) { lev = &levl[x][0]; for (y = 0; y < ROWNO; y++, lev++) if (lev->glyph != cmap_to_glyph(S_stone)) show_glyph(x,y,lev->glyph); } vision_recalc(0); see_monsters(); } } else if (Unblind_telepat) { see_monsters(); } else if (Warning || Warn_of_mon) see_monsters(); if (vision_full_recalc) vision_recalc(0); /* vision! */ } #ifdef REALTIME_ON_BOTL if(iflags.showrealtime) { /* Update the bottom line if the number of minutes has * changed */ if(get_realtime() / 60 != realtime_data.last_displayed_time / 60) flags.botl = 1; } #endif if(flags.botl || flags.botlx) bot(); flags.move = 1; if(multi >= 0 && occupation) { #if defined(MICRO) || defined(WIN32) abort_lev = 0; if (kbhit()) { if ((ch = Getchar()) == ABORT) abort_lev++; # ifdef REDO else pushch(ch); # endif /* REDO */ } if (!abort_lev && (*occupation)() == 0) #else if ((*occupation)() == 0) #endif occupation = 0; if( #if defined(MICRO) || defined(WIN32) abort_lev || #endif monster_nearby()) { stop_occupation(); reset_eat(); } #if defined(MICRO) || defined(WIN32) if (!(++occtime % 7)) display_nhwindow(WIN_MAP, FALSE); #endif continue; } if ((u.uhave.amulet || Clairvoyant) && !In_endgame(&u.uz) && !BClairvoyant && !(moves % 15) && !rn2(2)) do_vicinity_map(); #ifdef WIZARD if (iflags.sanity_check) sanity_check(); #endif #ifdef CLIPPING /* just before rhack */ cliparound(u.ux, u.uy); #endif u.umoved = FALSE; if (multi > 0) { lookaround(); if (!multi) { /* lookaround may clear multi */ flags.move = 0; if (flags.time) flags.botl = 1; continue; } if (flags.mv) { if(multi < COLNO && !--multi) flags.travel = iflags.travel1 = flags.mv = flags.run = 0; domove(); } else { --multi; rhack(save_cm); } } else if (multi == 0) { #ifdef MAIL ckmailstatus(); #endif rhack((char *)0); } if (u.utotype) /* change dungeon level */ deferred_goto(); /* after rhack() */ /* !flags.move here: multiple movement command stopped */ else if (flags.time && (!flags.move || !flags.mv)) flags.botl = 1; if (vision_full_recalc) vision_recalc(0); /* vision! */ /* when running in non-tport mode, this gets done through domove() */ if ((!flags.run || iflags.runmode == RUN_TPORT) && (multi && (!flags.travel ? !(multi % 7) : !(moves % 7L)))) { if (flags.time && flags.run) flags.botl = 1; display_nhwindow(WIN_MAP, FALSE); } } }
static int abAbacus::SetUngappedFragmentPositions(FragType type,int32 n_frags, MultiAlignT *uma) { int32 num_frags = GetNumIntMultiPoss(uma->f_list); int32 num_unitigs = GetNumIntUnitigPoss(uma->u_list); HashTable_AS *unitigFrags = CreateScalarHashTable_AS(); int32 num_columns = GetMultiAlignLength(uma); int32 ungapped_pos = 0; int32 *gapped_positions = new int32 [num_columns + 1]; char *consensus = Getchar(uma->consensus,0); for (int32 i=0; i<num_columns+1; i++) { gapped_positions[i] = ungapped_pos; if (consensus[i] != '-') ungapped_pos++; } // Remember the first fragment we add. int32 first_frag = GetNumCNS_AlignedContigElements(fragment_positions); for (int32 ifrag=0; ifrag<num_frags; ifrag++) { CNS_AlignedContigElement epos; IntMultiPos *frag = GetIntMultiPos(uma->f_list, ifrag); if (ExistsInHashTable_AS(unitigFrags, frag->ident, 0)) { fprintf(stderr,"SetUngappedFragmentPositions()-- ident %d already in hashtable\n", frag->ident); assert(0); } if (HASH_SUCCESS != InsertInHashTable_AS(unitigFrags, frag->ident, 0, 1, 0)) { fprintf(stderr,"SetUngappedFragmentPositions()-- Failure to insert ident %d in hashtable\n", frag->ident); assert(0); } assert(frag->position.bgn >= 0); assert(frag->position.bgn < num_columns + 1); assert(frag->position.end >= 0); assert(frag->position.end < num_columns + 1); epos.frg_or_utg = CNS_ELEMENT_IS_FRAGMENT; epos.idx.fragment.frgIdent = frag->ident; epos.idx.fragment.frgType = frag->type; epos.idx.fragment.frgContained = frag->contained; epos.idx.fragment.frgInUnitig = (type == AS_CONTIG) ? -1 : uma->maID; epos.position.bgn = gapped_positions[frag->position.bgn]; epos.position.end = gapped_positions[frag->position.end]; //fprintf(stderr, "SetUngappedFragmentPositions()-- FRG id=%d type=%c pos=%d,%d (orig pos=%d,%d)\n", // frag->ident, frag->type, epos.position.bgn, epos.position.end, frag->position.bgn, frag->position.end); // Adjust the ungapped position if we fall within a gap // if (epos.position.bgn == epos.position.end) { fprintf(stderr,"SetUngappedFragmentPositions()-- Encountered bgn==end=="F_S32" in ungapped coords within SetUngappedFragmentPositions for "F_CID "(gapped coords "F_S32","F_S32")\n", epos.position.bgn,frag->ident,frag->position.bgn,frag->position.end); assert(frag->position.bgn != frag->position.end); if (frag->position.bgn < frag->position.end) { if (epos.position.bgn > 0) epos.position.bgn--; else epos.position.end++; } else { if (epos.position.end > 0) epos.position.end--; else epos.position.bgn++; } fprintf(stderr,"SetUngappedFragmentPositions()-- Reset to "F_S32","F_S32"\n", epos.position.bgn, epos.position.end); } AppendVA_CNS_AlignedContigElement(fragment_positions, &epos); } for (int32 ifrag=0; ifrag < num_unitigs; ifrag++){ CNS_AlignedContigElement epos; IntUnitigPos *unitig = GetIntUnitigPos(uma->u_list, ifrag); epos.frg_or_utg = CNS_ELEMENT_IS_UNITIG; epos.idx.unitig.utgIdent = unitig->ident; epos.idx.unitig.utgType = unitig->type; epos.position.bgn = gapped_positions[unitig->position.bgn]; epos.position.end = gapped_positions[unitig->position.end]; //fprintf(stderr, "SetUngappedFragmentPositions()-- UTG id=%d type=%c pos=%d,%d (orig pos=%d,%d)\n", // unitig->ident, unitig->type, epos.position.bgn, epos.position.end, unitig->position.bgn, unitig->position.end); AppendVA_CNS_AlignedContigElement(fragment_positions,&epos); } // This is used only by ReplaceEndUnitigInContig(). Mark fragments in the "anchoring" contig // that belong to this unitig. // if (type != AS_CONTIG) { Fragment *anchor = GetFragment(fragmentStore,0); if ((anchor != NULL) && (anchor->type == AS_CONTIG)) { CNS_AlignedContigElement *af = GetCNS_AlignedContigElement(fragment_positions, anchor->components); for (int32 ifrag=0; ifrag < anchor->n_components; ifrag++, af++) { if ((af->frg_or_utg == CNS_ELEMENT_IS_FRAGMENT) && (ExistsInHashTable_AS(unitigFrags, af->idx.fragment.frgIdent, 0))) af->idx.fragment.frgInUnitig = uma->maID; } } } DeleteHashTable_AS(unitigFrags); delete [] gapped_positions; return first_frag; }
void Init() { Getchar(); }
int32 main(int32 argc, char **argv) { int32 arg = 1; int32 err = 0; int32 hlp = 0; char * gkpStoreName = NULL; int32 gkpStorePart = 0; char * msgFile = NULL; char * outputFileName= NULL; char * seqAn = NULL; char * wrkDir = NULL; char * seqStoreName = NULL; int32 seqStoreVer = 0; int32 seqStorePart = 0; argc = AS_configure(argc, argv); while (arg < argc) { if (strcmp(argv[arg], "-c") == 0) { msgFile = argv[++arg]; } else if (strcmp(argv[arg], "-G") == 0) { gkpStoreName = argv[++arg]; } else if (strcmp(argv[arg], "-S") == 0) { gkpStorePart = atoi(argv[++arg]); } else if (strcmp(argv[arg], "-o") == 0) { outputFileName = argv[++arg]; } else if (strcmp(argv[arg], "-s") == 0) { seqAn = argv[++arg]; } else if (strcmp(argv[arg], "-w") == 0) { wrkDir = argv[++arg]; } else if (strcmp(argv[arg], "-u") == 0) { seqStoreName = argv[++arg]; } else if (strcmp(argv[arg], "-V") == 0) { seqStoreVer = atoi(argv[++arg]); } else if (strcmp(argv[arg], "-p") == 0) { seqStorePart = atoi(argv[++arg]); } else { err++; } arg++; } if ((err) || (gkpStoreName == NULL) || (msgFile == NULL) || (outputFileName == NULL) || seqAn == NULL) { fprintf(stderr, "USAGE: SeqAn_CNS -G <gkpStore> -c <input.cgb> -o <output.cgi> -s <seqan_executable> [-u seqstore, required for contig consensus] [-w working directory]\n"); exit(1); } gkStore *gkpStore = new gkStore(gkpStoreName, FALSE, FALSE); gkpStore->gkStore_loadPartition(gkpStorePart); gkFragment fr; GenericMesg *pmesg; tSequenceDB *sequenceDB = NULL; FILE *infp = fopen(msgFile,"r"); FILE *tempReads; FILE *outfp = fopen(outputFileName, "w"); char fileName[AS_SEQAN_MAX_BUFFER_LENGTH]; char *prefix = outputFileName; getFileName(prefix, wrkDir, AS_SEQAN_INPUT_NAME, fileName); int32 i = 0; while ((EOF != ReadProtoMesg_AS(infp, &pmesg))) { int32 freeMem = 0; if (pmesg->t == MESG_IUM) { IntUnitigMesg *ium_mesg = (IntUnitigMesg *)pmesg->m; if (strlen(ium_mesg->consensus) == 0) { tempReads = fopen(fileName,"w"); for (i =0; i < ium_mesg->num_frags; i++) { // get the fragment sequence gkpStore->gkStore_getFragment(ium_mesg->f_list[i].ident, &fr, GKFRAGMENT_QLT); uint32 clrBeg = fr.gkFragment_getClearRegionBegin(); uint32 clrEnd = fr.gkFragment_getClearRegionEnd (); char *seqStart = fr.gkFragment_getSequence(); char *seq = seqStart+clrBeg; seq[clrEnd] = 0; AS_UTL_writeFastA(tempReads, seq, clrEnd-clrBeg, ">"F_IID","F_IID"\n", ium_mesg->f_list[i].position.bgn, ium_mesg->f_list[i].position.end); } fclose(tempReads); updateRecord(ium_mesg, fileName, seqAn, prefix, wrkDir); freeMem = 1; } WriteProtoMesg_AS(outfp, pmesg); if (freeMem) { safe_free(ium_mesg->consensus); safe_free(ium_mesg->quality); } } else if (pmesg->t == MESG_ICM) { IntConConMesg *icm_mesg = (IntConConMesg *)pmesg->m; if (seqStoreName == NULL) { fprintf(stderr, "USAGE: The -u option is required for contig consensus\n"); exit(1); } if (sequenceDB == NULL) { sequenceDB = openSequenceDB(seqStoreName, FALSE, seqStoreVer); openSequenceDBPartition(sequenceDB, seqStorePart); } if (strlen(icm_mesg->consensus) == 0) { tempReads = fopen(fileName,"w"); for (i =0; i < icm_mesg->num_pieces; i++) { // get the fragment sequence gkpStore->gkStore_getFragment(icm_mesg->pieces[i].ident, &fr, GKFRAGMENT_QLT); uint32 clrBeg = fr.gkFragment_getClearRegionBegin(); uint32 clrEnd = fr.gkFragment_getClearRegionEnd (); char *seqStart = fr.gkFragment_getSequence(); char *seq = seqStart+clrBeg; seq[clrEnd] = 0; AS_UTL_writeFastA(tempReads, seq, clrEnd-clrBeg, ">"F_IID","F_IID"\n", icm_mesg->pieces[i].position.bgn, icm_mesg->pieces[i].position.end); } // now handle the unitig messages for (i =0; i < icm_mesg->num_unitigs; i++) { VA_TYPE(char) *ungappedSequence = CreateVA_char(0); VA_TYPE(char) *ungappedQuality = CreateVA_char(0); MultiAlignT *uma = loadMultiAlignTFromSequenceDB(sequenceDB, icm_mesg->unitigs[i].ident, 1); assert(uma != NULL); GetMultiAlignUngappedConsensus(uma, ungappedSequence, ungappedQuality); char * seq = Getchar(ungappedSequence,0); AS_UTL_writeFastA(tempReads, seq, strlen(seq), ">"F_IID","F_IID"\n", icm_mesg->unitigs[i].position.bgn, icm_mesg->unitigs[i].position.end); } fclose(tempReads); updateICMRecord(icm_mesg, fileName, seqAn, prefix, wrkDir); freeMem = 1; } WriteProtoMesg_AS(outfp, pmesg); if (freeMem) { safe_free(icm_mesg->consensus); safe_free(icm_mesg->quality); } } } fclose(infp); fclose(outfp); return 0; }
void writeCCO(FILE *asmFile, bool doWrite) { SnapConConMesg cco; GenericMesg pmesg = { &cco, MESG_CCO }; GraphNodeIterator contigs; ContigT *contig; fprintf(stderr, "writeCCO()--\n"); InitGraphNodeIterator(&contigs, ScaffoldGraph->ContigGraph, GRAPH_NODE_DEFAULT); while ((contig = NextGraphNodeIterator(&contigs)) != NULL) { assert(contig->id >= 0); assert(contig->id < GetNumGraphNodes(ScaffoldGraph->ContigGraph)); if (contig->flags.bits.isChaff) continue; NodeCGW_T *unitig = GetGraphNode(ScaffoldGraph->CIGraph, contig->info.Contig.AEndCI); if ((ScaffoldGraph->tigStore->getNumUnitigs(contig->id, FALSE) == 1) && (contig->scaffoldID == NULLINDEX) && (unitig->info.CI.numInstances > 0)) // Contig is a surrogate instance continue; MultiAlignT *ma = ScaffoldGraph->tigStore->loadMultiAlign(contig->id, FALSE); cco.eaccession = AS_UID_fromInteger(getUID(uidServer)); cco.iaccession = contig->id; cco.placed = ScaffoldGraph->tigStore->getContigStatus(contig->id); cco.length = GetMultiAlignLength(ma); cco.consensus = Getchar(ma->consensus, 0); cco.quality = Getchar(ma->quality, 0); cco.forced = 0; cco.num_pieces = GetNumIntMultiPoss(ma->f_list); cco.num_unitigs = GetNumIntMultiPoss(ma->u_list); cco.num_vars = GetNumIntMultiPoss(ma->v_list); cco.pieces = NULL; cco.unitigs = NULL; cco.vars = NULL; if (cco.consensus == NULL) fprintf(stderr, "buildCCOMessage()-- contig %d missing consensus sequence\n", cco.iaccession); assert(cco.consensus != NULL); if (cco.length != strlen(cco.consensus)) fprintf(stderr, "buildCCOMessage()-- contig %d length %d != consensus string length "F_SIZE_T"\n", cco.iaccession, cco.length, strlen(cco.consensus)); assert(cco.length == strlen(cco.consensus)); if (cco.num_pieces > 0) { cco.pieces = (SnapMultiPos *)safe_malloc(cco.num_pieces * sizeof(SnapMultiPos)); for(int32 i=0; i<cco.num_pieces; i++) { IntMultiPos *imp = GetIntMultiPos(ma->f_list, i); cco.pieces[i].type = imp->type; cco.pieces[i].eident = FRGmap.lookup(imp->ident); cco.pieces[i].delta_length = imp->delta_length; cco.pieces[i].position = imp->position; cco.pieces[i].delta = imp->delta; } } if (cco.num_unitigs > 0) { cco.unitigs = (UnitigPos *)safe_malloc(cco.num_unitigs * sizeof(UnitigPos)); for(int32 i=0; i<cco.num_unitigs; i++) { IntUnitigPos *imp = GetIntUnitigPos(ma->u_list, i); cco.unitigs[i].type = imp->type; cco.unitigs[i].eident = UTGmap.lookup(imp->ident); cco.unitigs[i].position = imp->position; cco.unitigs[i].delta = imp->delta; cco.unitigs[i].delta_length = imp->delta_length; } } if (cco.num_vars > 0) { cco.vars = (IntMultiVar *)safe_malloc(cco.num_vars * sizeof(IntMultiVar)); for(int32 i=0; i<cco.num_vars; i++) { IntMultiVar *imv = GetIntMultiVar(ma->v_list, i); cco.vars[i].var_id = imv->var_id; cco.vars[i].phased_id = imv->phased_id; cco.vars[i].position = imv->position; cco.vars[i].num_reads = imv->num_reads; cco.vars[i].num_alleles = imv->num_alleles; cco.vars[i].num_alleles_confirmed = imv->num_alleles_confirmed; cco.vars[i].min_anchor_size = imv->min_anchor_size; cco.vars[i].var_length = imv->var_length; cco.vars[i].alleles = imv->alleles; cco.vars[i].var_seq_memory = imv->var_seq_memory; cco.vars[i].read_id_memory = imv->read_id_memory; cco.vars[i].enc_num_reads = NULL; cco.vars[i].enc_weights = NULL; cco.vars[i].enc_var_seq = NULL; cco.vars[i].enc_read_ids = NULL; } } if (doWrite) WriteProtoMesg_AS(asmFile, &pmesg); safe_free(cco.pieces); safe_free(cco.unitigs); safe_free(cco.vars); CCOmap.add(cco.iaccession, cco.eaccession); } }
void dumpContigInfo(ChunkInstanceT *contig) { int contigOrientation; MultiAlignT *ma; char *seq1; int len1; VA_TYPE(char) *consensus = CreateVA_char(2048); VA_TYPE(char) *quality = CreateVA_char(2048); fprintf( stderr, "*********************** contig analysis **************************\n"); fprintf( stderr, "analyzing contig: %d\n", contig->id); if (contig->offsetAEnd.mean < contig->offsetBEnd.mean) contigOrientation = 0; else contigOrientation = 1; fprintf(stderr, "contig orientation: %d\t length: %d contig offsetAEnd: %d\t offsetBEnd: %d\n", contigOrientation, (int)contig->bpLength.mean, (int)contig->offsetAEnd.mean, (int)contig->offsetBEnd.mean); ma = ScaffoldGraph->tigStore->loadMultiAlign(contig->id, ScaffoldGraph->ContigGraph->type == CI_GRAPH); // Get the consensus sequences for the contig from the Store GetConsensus(ScaffoldGraph->ContigGraph, contig->id, consensus, quality); seq1 = Getchar(consensus, 0); len1 = strlen(seq1); if (contigOrientation == 1) reverseComplementSequence(seq1, len1); if (len1 < 5000) { fprintf( stderr, ">contig%d consensus seq (flipped to reflect scaff orientation)\n", contig->id); fprintf( stderr, "%s\n", seq1); } else { char tmpchar = seq1[2500]; seq1[2500] = '\0'; fprintf( stderr, ">contig%d left end\n", contig->id); fprintf( stderr, "%s\n", seq1); seq1[2500] = tmpchar; fprintf( stderr, ">contig%d right end\n", contig->id); fprintf( stderr, "%s\n", seq1 + len1 - 2501); } #if 1 int numUnitigs = GetNumIntUnitigPoss(ma->u_list); fprintf( stderr, "number unitigs: %d\n", numUnitigs); int i; for (i = 0; i < numUnitigs; i++) { IntUnitigPos *upos = GetIntUnitigPos( ma->u_list, i); ChunkInstanceT *unitig = GetGraphNode( ScaffoldGraph->CIGraph, upos->ident); MultiAlignT *uma = ScaffoldGraph->tigStore->loadMultiAlign(unitig->id, ScaffoldGraph->CIGraph->type == CI_GRAPH); IntMultiPos *ump; int icntfrag; fprintf( stderr, " unitig: %d\t num frags: %ld surrogate: %d\n", unitig->id, GetNumIntMultiPoss(uma->f_list), (unitig->flags.bits.isStoneSurrogate || unitig->flags.bits.isWalkSurrogate)); if (unitig->flags.bits.isStoneSurrogate || unitig->flags.bits.isWalkSurrogate) { fprintf (stderr, " surrogate unitig offsetAEnd: %f, offsetBEnd: %f\n", unitig->offsetAEnd.mean, unitig->offsetBEnd.mean); unitig = GetGraphNode( ScaffoldGraph->CIGraph, unitig->info.CI.baseID); fprintf ( stderr, " using original unitig: %d\n", unitig->id); uma = ScaffoldGraph->tigStore->loadMultiAlign(unitig->id, ScaffoldGraph->CIGraph->type == CI_GRAPH); } // now print out info on the frags in the unitig for (icntfrag = 0; icntfrag < GetNumIntMultiPoss(uma->f_list); icntfrag++) { IntMultiPos *imp = GetIntMultiPos(uma->f_list, icntfrag); CIFragT *frag = GetCIFragT(ScaffoldGraph->CIFrags, imp->ident); fprintf(stderr, " frag: %6d\t contig pos (5p, 3p): %6d, %6d\n", imp->ident, (int) frag->contigOffset5p.mean, (int) frag->contigOffset3p.mean); } } #endif #if 1 CIEdgeT * e; GraphEdgeIterator edges(ScaffoldGraph->ContigGraph, contig->id, ALL_END, ALL_EDGES); // FALSE == ITERATOR_VERBOSE while((e = edges.nextRaw()) != NULL) PrintGraphEdge( stderr, ScaffoldGraph->ContigGraph, "Analyzing edge", e, 0); #endif DeleteVA_char(consensus); DeleteVA_char(quality); }
int lex(void) { int c; again: c = Getchar(); yytext[0] = (char) c; yytext[1] = '\0'; switch (c) { case EOF: return c; case '\n': /* newline */ lineno++; /* make most semi-colons optional */ if (implied_semis && context && in_seq && par_cnt == 0 && follows_token(last_token)) { if (0) { printf("insert ; line %d, last_token %d in_seq %d\n", lineno-1, last_token, in_seq); } ValToken(1, SEMI); } /* else fall thru */ case '\r': /* carriage return */ goto again; case ' ': case '\t': case '\f': /* white space */ goto again; case '#': /* preprocessor directive */ if (in_comment) goto again; if (pp_mode) { last_token = PREPROC; return pre_proc(); } do_directive(c); goto again; case '\"': getword(c, notquote); if (Getchar() != '\"') fatal("string not terminated", yytext); strcat(yytext, "\""); SymToken(lookup(yytext), STRING) case '$': getword('\"', notdollar); if (Getchar() != '$') fatal("ltl definition not terminated", yytext); strcat(yytext, "\""); SymToken(lookup(yytext), STRING) case '\'': /* new 3.0.9 */ c = Getchar(); if (c == '\\') { c = Getchar(); if (c == 'n') c = '\n'; else if (c == 'r') c = '\r'; else if (c == 't') c = '\t'; else if (c == 'f') c = '\f'; } if (Getchar() != '\'' && !in_comment) fatal("character quote missing: %s", yytext); ValToken(c, CONST) default: break; } if (isdigit_(c)) { long int nr; getword(c, isdigit_); errno = 0; nr = strtol(yytext, NULL, 10); if (errno != 0) { fprintf(stderr, "spin: value out of range: '%s' read as '%d'\n", yytext, (int) nr); } ValToken((int)nr, CONST) } if (isalpha_(c) || c == '_') { getword(c, isalnum_); if (!in_comment) { c = check_name(yytext); if (c) { last_token = c; return c; } /* else fall through */ } goto again; } if (ltl_mode) { switch (c) { case '-': c = follow('>', IMPLIES, '-'); break; case '[': c = follow(']', ALWAYS, '['); break; case '<': c = follow('>', EVENTUALLY, '<'); if (c == '<') { c = Getchar(); if (c == '-') { c = follow('>', EQUIV, '-'); if (c == '-') { Ungetch(c); c = '<'; } } else { Ungetch(c); c = '<'; } } default: break; } } switch (c) { case '/': c = follow('*', 0, '/'); if (!c) { in_comment = 1; goto again; } break; case '*': c = follow('/', 0, '*'); if (!c) { in_comment = 0; goto again; } break; case ':': c = follow(':', SEP, ':'); break; case '-': c = follow('>', ARROW, follow('-', DECR, '-')); break; case '+': c = follow('+', INCR, '+'); break; case '<': c = follow('<', LSHIFT, follow('=', LE, LT)); break; case '>': c = follow('>', RSHIFT, follow('=', GE, GT)); break; case '=': c = follow('=', EQ, ASGN); break; case '!': c = follow('=', NE, follow('!', O_SND, SND)); break; case '?': c = follow('?', R_RCV, RCV); break; case '&': c = follow('&', AND, '&'); break; case '|': c = follow('|', OR, '|'); break; case ';': c = SEMI; break; case '.': c = follow('.', DOTDOT, '.'); break; case '{': scope_seq[scope_level++]++; set_cur_scope(); break; case '}': scope_level--; set_cur_scope(); break; default : break; } ValToken(0, c) }
void moveloop() { #ifdef MICRO char ch; int abort_lev; #endif int moverate = 0; boolean didmove = 0; /* Note: these initializers don't do anything except guarantee that we're linked properly. */ decl_init(); monst_init(); monstr_init(); /* monster strengths */ objects_init(); (void) encumber_msg(); /* in case they auto-picked up something */ for(;;) { #ifdef CLIPPING cliparound(u.ux, u.uy); #endif #if defined(MAC_MPW32) && !defined(MODEL_FAR) UnloadAllSegments(); /* Marks non-resident segments as purgeable */ #endif get_nh_event(); didmove = flags.move; if(flags.move) { /* actual time passed */ #ifdef POLYSELF int oldmtimedone; #endif int wtcap; if (u.utotype) deferred_goto(); wtcap = encumber_msg(); #ifdef POLYSELF oldmtimedone = u.mtimedone; #endif #ifdef SOUNDS dosounds(); #endif if(moverate <= 0) { /* calculate how much time passed. */ int moveamt = 0; if(Fast & ~INTRINSIC) moveamt = 6; else if(Fast) moveamt = 8; else moveamt = 12; switch(wtcap) { case UNENCUMBERED: break; case SLT_ENCUMBER: moveamt = (moveamt * 4) / 3; break; case MOD_ENCUMBER: moveamt *= 2; break; case HVY_ENCUMBER: moveamt *= 4; break; default: moveamt *= 12; break; } moverate += moveamt; settrack(); } if(moverate > 0) { movemon(); /* a monster may have levteleported player -dlc */ if (u.utotype) deferred_goto(); if(!rn2(u.uevent.udemigod ? 25 : (depth(&u.uz) > depth(&stronghold_level)) ? 50 : 70)) (void) makemon((struct permonst *)0, 0, 0); ++monstermoves; remove_cadavers(&fobj); remove_cadavers(&invent); moverate -= 12; } if(Glib) glibr(); nh_timeout(); ++moves; if (u.ublesscnt) u.ublesscnt--; if(flags.time) flags.botl = 1; /* One possible result of prayer is healing. Whether or * not you get healed depends on your current hit points. * If you are allowed to regenerate during the prayer, the * end-of-prayer calculation messes up on this. */ if (u.uinvulnerable) ; else #ifdef POLYSELF if (u.mtimedone && u.mh < u.mhmax) { if (u.mh < 1) { rehumanize(); moverate = 0; } else if (Regeneration || (wtcap < MOD_ENCUMBER && !(moves%20))) { flags.botl = 1; u.mh++; } } else #endif if(u.uhp < u.uhpmax) { if(u.ulevel > 9) { int heal; if(HRegeneration || (!(moves%3) && (wtcap < MOD_ENCUMBER || !flags.mv))) { flags.botl = 1; if (ACURR(A_CON) <= 12) heal = 1; else heal = rnd((int) ACURR(A_CON)-12); if (heal > u.ulevel-9) heal = u.ulevel-9; u.uhp += heal; if(u.uhp > u.uhpmax) u.uhp = u.uhpmax; } } else if(HRegeneration || ((wtcap < MOD_ENCUMBER || !flags.mv) && (!(moves%((MAXULEV+12)/(u.ulevel+2)+1))))) { flags.botl = 1; u.uhp++; } } if (wtcap > MOD_ENCUMBER && flags.mv) { if(!(wtcap < EXT_ENCUMBER ? moves%30 : moves%10)) { if(u.uhp > 1) { u.uhp--; } else { pline("You pass out from exertion!"); exercise(A_CON, FALSE); nomul(-10); u.usleep = 1; } } } if ((u.uen < u.uenmax) && ((wtcap < MOD_ENCUMBER && (!(moves%((MAXULEV + 1 - u.ulevel) * (pl_character[0] == 'W' ? 3 : 4) / 2)))) || Energy_regeneration)) { u.uen += rn1((int)(ACURR(A_WIS) + ACURR(A_INT)) / 10 + 1,1); if (u.uen > u.uenmax) u.uen = u.uenmax; flags.botl = 1; } if(!u.uinvulnerable) { if(Teleportation && !rn2(85)) { #ifdef REDO /* clear doagain keystrokes */ pushch(0); savech(0); #endif tele(); } #ifdef POLYSELF if(Polymorph && !rn2(100)) { if (multi >= 0) { if (occupation) stop_occupation(); else nomul(0); } polyself(); moverate = 0; } else if (u.ulycn >= 0 && !rn2(80 - (20 * night()))) { if (multi >= 0) { if (occupation) stop_occupation(); else nomul(0); } you_were(); moverate = 0; } #endif } if(Searching && multi >= 0) (void) dosearch0(1); do_storms(); hatch_eggs(); burn_lamps(); gethungry(); exerchk(); invault(); amulet(); if (!rn2(40+(int)(ACURR(A_DEX)*3))) u_wipe_engr(rnd(3)); if (u.uevent.udemigod && !u.uinvulnerable) { if (u.udg_cnt) u.udg_cnt--; if (!u.udg_cnt) { intervene(); u.udg_cnt = rn1(200, 50); } } restore_attrib(); /* underwater and waterlevel vision are done here */ if (Is_waterlevel(&u.uz)) movebubbles(); else if (Underwater) under_water(0); #ifdef POLYSELF if ((oldmtimedone && !u.mtimedone) || (!oldmtimedone && u.mtimedone)) moverate = 0; #endif } if(multi < 0) { if(!++multi){ pline("%s",nomovemsg ? nomovemsg : (const char *)"You can move again."); nomovemsg = 0; u.usleep = 0; if(afternmv) (*afternmv)(); afternmv = 0; } } find_ac(); if(!flags.mv || Blind) { /* redo monsters if hallu or wearing a helm of telepathy */ if (Hallucination || (HTelepat & (WORN_HELMET|WORN_AMUL|W_ART))) see_monsters(); /* redo objects if hallucinating */ if (Hallucination) see_objects(); /* update swallowed display */ if (Hallucination && u.uswallow) swallowed(0); if (vision_full_recalc) vision_recalc(0); /* vision! */ } if(flags.botl || flags.botlx) bot(); flags.move = 1; if(multi >= 0 && occupation) { #ifdef MICRO abort_lev = 0; if (kbhit()) { if ((ch = Getchar()) == ABORT) abort_lev++; # ifdef REDO else pushch(ch); # endif /* REDO */ } if (!abort_lev && (*occupation)() == 0) #else if ((*occupation)() == 0) #endif occupation = 0; if( #ifdef MICRO abort_lev || #endif monster_nearby()) { stop_occupation(); reset_eat(); } #ifdef MICRO if (!(++occtime % 7)) display_nhwindow(WIN_MAP, FALSE); #endif continue; } if((u.uhave.amulet || Clairvoyant) && !In_endgame(&u.uz) && !(moves%15) && !rn2(2)) do_vicinity_map(); if(u.utrap && u.utraptype == TT_LAVA) { if(!is_lava(u.ux,u.uy)) u.utrap = 0; else { u.utrap -= 1<<8; if(u.utrap < 1<<8) { killer_format = KILLED_BY; killer = "molten lava"; You("sink below the surface and suffocate."); done(DROWNING); /*whatever*/ } else if(didmove && !u.umoved) { Norep("You sink deeper into the lava."); u.utrap += rnd(4); } } } u.umoved = FALSE; if(!didmove || moverate <= 0) { if(multi > 0) { lookaround(); if(!multi) { /* lookaround may clear multi */ flags.move = 0; continue; } if(flags.mv) { if(multi < COLNO && !--multi) flags.mv = flags.run = 0; domove(); } else { --multi; rhack(save_cm); } } else if(multi == 0) { #ifdef MAIL ckmailstatus(); #endif rhack(NULL); } } if (vision_full_recalc) vision_recalc(0); /* vision! */ if(multi && multi%7 == 0) display_nhwindow(WIN_MAP, FALSE); } }
void PrintMultiAlignT(FILE *out, MultiAlignT *ma, gkStore *frag_store, int32 show_qv, int32 dots, uint32 clrrng_flag) { int32 depth; int32 i; int32 window; char **multia=NULL; int32 **idarray; int32 **oriarray; char *consensus = Getchar(ma->consensus,0); char *quality = Getchar(ma->quality,0); gkFragment rsp; dots = 0; if ((consensus == NULL) || (consensus[0] == 0)) { fprintf(out, "No MultiAlignment to print for tig %d -- no consensus sequence present.\n", ma->maID); return; } int32 length = strlen(consensus); IMP2Array(GetIntMultiPos(ma->f_list,0), GetNumIntMultiPoss(ma->f_list), GetNumchars(ma->consensus), frag_store, &depth, &multia, &idarray, &oriarray, clrrng_flag); fprintf(out,"<<< begin Contig %d >>>",ma->maID);; char gruler[MULTIALIGN_PRINT_WIDTH + 200]; char uruler[MULTIALIGN_PRINT_WIDTH + 200]; int32 ungapped = 1; int32 tick = 1; for (window=0;window<length;) { int32 row_id = 0; int32 orient = 0; int32 rowlen = (window + MULTIALIGN_PRINT_WIDTH < length) ? MULTIALIGN_PRINT_WIDTH : length - window; fprintf(out, "\n"); fprintf(out, "\n"); fprintf(out, "<<< Contig %d, gapped length: %d >>>\n",ma->maID, length); { memset(gruler, 0, MULTIALIGN_PRINT_WIDTH + 200); memset(uruler, 0, MULTIALIGN_PRINT_WIDTH + 200); for (int32 rowind=0; rowind<rowlen; rowind++) { if (((window + 1 + rowind) % 25) == 0) sprintf(gruler + rowind, "| GAP=%d", window + 1 + rowind); if ((ungapped % 25) == 0) sprintf(uruler + rowind, "| UNG=%d", ungapped); if (consensus[window + rowind] != '-') ungapped++; } for (int32 i=0; i<MULTIALIGN_PRINT_WIDTH; i++) { if (gruler[i] == 0) gruler[i] = ' '; if (uruler[i] == 0) uruler[i] = ' '; } for (int32 i=MULTIALIGN_PRINT_WIDTH-1; (i >= 0) && (gruler[i] == ' '); i--) gruler[i] = 0; for (int32 i=MULTIALIGN_PRINT_WIDTH-1; (i >= 0) && (uruler[i] == ' '); i--) uruler[i] = 0; fprintf(out, "%s\n", gruler); fprintf(out, "%s\n", uruler); } { char save = consensus[window + rowlen]; consensus[window+rowlen] = 0; fprintf(out,"%s cns (uid,iid) type\n", consensus+window); consensus[window+rowlen] = save; } { char save = quality[window + rowlen]; quality[window+rowlen] = 0; fprintf(out,"%s qlt\n", quality+window); quality[window+rowlen] = save; } for (i=0;i<depth;i++) { assert(multia[2*i] != NULL); // Change matching bases to '.' or lowercase. // Count the number of non-blank letters. int32 nonBlank = 0; for (int32 j=0; j<MULTIALIGN_PRINT_WIDTH; j++) { if (window + j > length) break; if (multia[2*i][window+j] == consensus[window+j]) { if (dots) { multia[2*i] [window+j] = '.'; multia[2*i+1][window+j] = ' '; } else { multia[2*i][window+j] = tolower(multia[2*i][window+j]); } } if (multia[2*i][window+j] != ' ') nonBlank++; if (idarray[i][window + j] > 0) { row_id = idarray[i][window + j]; orient = oriarray[i][window + j]; } } if (nonBlank == 0) continue; // Figure out the ID and orientation for this block frag_store->gkStore_getFragment(row_id, &rsp, GKFRAGMENT_INF); { char save = multia[2*i][window + MULTIALIGN_PRINT_WIDTH]; multia[2*i][window + MULTIALIGN_PRINT_WIDTH] = 0; fprintf(out, "%s %c (%s,%d)\n", multia[2*i]+window, (orient>0)?'>':'<', AS_UID_toString(rsp.gkFragment_getReadUID()), row_id); multia[2*i][window + MULTIALIGN_PRINT_WIDTH] = save; } if (show_qv) { char save = multia[2*i+1][window + MULTIALIGN_PRINT_WIDTH]; multia[2*i+1][window + MULTIALIGN_PRINT_WIDTH] = 0; fprintf(out, "%s\n", multia[2*i+1]+window); multia[2*i+1][window + MULTIALIGN_PRINT_WIDTH] = save; } } window += MULTIALIGN_PRINT_WIDTH; } fprintf(out,"\n<<< end Contig %d >>>\n", ma->maID); for (i=0;i<2*depth;i++) safe_free(multia[i]); safe_free(multia); for (i=0;i<depth;i++) { safe_free(idarray[i]); safe_free(oriarray[i]); } safe_free(idarray); safe_free(oriarray); }
Symbol * prep_inline(Symbol *s, Lextok *nms) { int c, nest = 1, dln, firstchar, cnr; char *p; Lextok *t; static char Buf1[SOMETHINGBIG], Buf2[RATHERSMALL]; static int c_code = 1; for (t = nms; t; t = t->rgt) if (t->lft) { if (t->lft->ntyp != NAME) fatal("bad param to inline %s", s?s->name:"--"); t->lft->sym->hidden |= 32; } if (!s) /* C_Code fragment */ { s = (Symbol *) emalloc(sizeof(Symbol)); s->name = (char *) emalloc(strlen("c_code")+26); sprintf(s->name, "c_code%d", c_code++); s->context = context; s->type = CODE_FRAG; } else s->type = PREDEF; p = &Buf1[0]; Buf2[0] = '\0'; for (;;) { c = Getchar(); switch (c) { case '[': if (s->type != CODE_FRAG) goto bad; precondition(&Buf2[0]); /* e.g., c_code [p] { r = p-r; } */ continue; case '{': break; case '\n': lineno++; /* fall through */ case ' ': case '\t': case '\f': case '\r': continue; default : printf("spin: saw char '%c'\n", c); bad: fatal("bad inline: %s", s->name); } break; } dln = lineno; if (s->type == CODE_FRAG) { if (verbose&32) sprintf(Buf1, "\t/* line %d %s */\n\t\t", lineno, Fname->name); else strcpy(Buf1, ""); } else sprintf(Buf1, "\n#line %d \"%s\"\n{", lineno, Fname->name); p += strlen(Buf1); firstchar = 1; cnr = 1; /* not zero */ more: c = Getchar(); *p++ = (char) c; if (p - Buf1 >= SOMETHINGBIG) fatal("inline text too long", 0); switch (c) { case '\n': lineno++; cnr = 0; #if 0 if (nest <= 0) { *--p = '\0'; } #endif break; case '{': cnr++; nest++; break; case '}': cnr++; if (--nest <= 0) { *p = '\0'; if (s->type == CODE_FRAG) *--p = '\0'; /* remove trailing '}' */ def_inline(s, dln, &Buf1[0], &Buf2[0], nms); if (firstchar) printf("%3d: %s, warning: empty inline definition (%s)\n", dln, Fname->name, s->name); return s; /* normal return */ } break; case '#': if (cnr == 0) { p--; do_directive(c); /* reads to newline */ } else { firstchar = 0; cnr++; } break; case '\t': case ' ': case '\f': cnr++; break; default: firstchar = 0; cnr++; break; } goto more; }
void moveloop() { #if defined(MICRO) || defined(WIN32) char ch; int abort_lev; #endif int moveamt = 0, wtcap = 0, change = 0; boolean didmove = FALSE, monscanmove = FALSE; flags.moonphase = phase_of_the_moon(); if(flags.moonphase == FULL_MOON) { You("are lucky! Full moon tonight."); change_luck(1); } else if(flags.moonphase == NEW_MOON) { pline("Be careful! New moon tonight."); } flags.friday13 = friday_13th(); if (flags.friday13) { pline("Watch out! Bad things can happen on Friday the 13th."); change_luck(-1); } /* KMH -- February 2 */ flags.groundhogday = groundhog_day(); if (flags.groundhogday) pline("Happy Groundhog Day!"); initrack(); /* Note: these initializers don't do anything except guarantee that we're linked properly. */ decl_init(); monst_init(); monstr_init(); /* monster strengths */ objects_init(); #ifdef WIZARD if (wizard) add_debug_extended_commands(); #endif (void) encumber_msg(); /* in case they auto-picked up something */ if (defer_see_monsters) { defer_see_monsters = FALSE; see_monsters(); } u.uz0.dlevel = u.uz.dlevel; youmonst.movement = NORMAL_SPEED; /* give the hero some movement points */ for(;;) { get_nh_event(); #ifdef POSITIONBAR do_positionbar(); #endif didmove = flags.move; if(didmove) { /* actual time passed */ youmonst.movement -= NORMAL_SPEED; do { /* hero can't move this turn loop */ wtcap = encumber_msg(); flags.mon_moving = TRUE; do { monscanmove = movemon(); if (youmonst.movement > NORMAL_SPEED) break; /* it's now your turn */ } while (monscanmove); flags.mon_moving = FALSE; if (!monscanmove && youmonst.movement < NORMAL_SPEED) { /* both you and the monsters are out of steam this round */ /* set up for a new turn */ struct monst *mtmp; mcalcdistress(); /* adjust monsters' trap, blind, etc */ /* reallocate movement rations to monsters */ for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) mtmp->movement += mcalcmove(mtmp); if(!rn2(u.uevent.udemigod ? 25 : (depth(&u.uz) > depth(&stronghold_level)) ? 50 : 70)) (void) makemon((struct permonst *)0, 0, 0, NO_MM_FLAGS); /* calculate how much time passed. */ #ifdef STEED if (u.usteed && u.umoved) { /* your speed doesn't augment steed's speed */ moveamt = mcalcmove(u.usteed); } else #endif { moveamt = youmonst.data->mmove; if (Very_fast) { /* speed boots or potion */ /* average movement is 1.67 times normal */ moveamt += NORMAL_SPEED / 2; if (rn2(3) == 0) moveamt += NORMAL_SPEED / 2; } else if (Fast) { /* average movement is 1.33 times normal */ if (rn2(3) != 0) moveamt += NORMAL_SPEED / 2; } if (tech_inuse(T_BLINK)) { /* TECH: Blinking! */ /* Case Average Variance * ------------------------- * Normal 12 0 * Fast 16 12 * V fast 20 12 * Blinking 24 12 * F & B 28 18 * V F & B 30 18 */ moveamt += NORMAL_SPEED * 2 / 3; if (rn2(3) == 0) moveamt += NORMAL_SPEED / 2; } } switch (wtcap) { case UNENCUMBERED: break; case SLT_ENCUMBER: moveamt -= (moveamt / 4); break; case MOD_ENCUMBER: moveamt -= (moveamt / 2); break; case HVY_ENCUMBER: moveamt -= ((moveamt * 3) / 4); break; case EXT_ENCUMBER: moveamt -= ((moveamt * 7) / 8); break; default: break; } youmonst.movement += moveamt; if (youmonst.movement < 0) youmonst.movement = 0; settrack(); monstermoves++; moves++; /********************************/ /* once-per-turn things go here */ /********************************/ if (flags.bypasses) clear_bypasses(); if(Glib) glibr(); nh_timeout(); run_regions(); #ifdef DUNGEON_GROWTH dgn_growths(TRUE, TRUE); #endif if (u.ublesscnt) u.ublesscnt--; if(flags.time && !flags.run) flags.botl = 1; /* One possible result of prayer is healing. Whether or * not you get healed depends on your current hit points. * If you are allowed to regenerate during the prayer, the * end-of-prayer calculation messes up on this. * Another possible result is rehumanization, which requires * that encumbrance and movement rate be recalculated. */ if (u.uinvulnerable) { /* for the moment at least, you're in tiptop shape */ wtcap = UNENCUMBERED; } else if (Upolyd && youmonst.data->mlet == S_EEL && !is_pool(u.ux,u.uy) && !Is_waterlevel(&u.uz)) { if (u.mh > 1) { u.mh--; flags.botl = 1; } else if (u.mh < 1) rehumanize(); } else if (Upolyd && u.mh < u.mhmax) { if (u.mh < 1) rehumanize(); else if (Regeneration || (wtcap < MOD_ENCUMBER && !(moves%20))) { flags.botl = 1; u.mh++; } } else if (u.uhp < u.uhpmax && (wtcap < MOD_ENCUMBER || !u.umoved || Regeneration)) { /* * KMH, balance patch -- New regeneration code * Healthstones have been added, which alter your effective * experience level and constitution (-2 cursed, +1 uncursed, * +2 blessed) for the basis of regeneration calculations. */ int efflev = u.ulevel + u.uhealbonus; int effcon = ACURR(A_CON) + u.uhealbonus; int heal = 1; if (efflev > 9 && !(moves % 3)) { if (effcon <= 12) { heal = 1; } else { heal = rnd(effcon); if (heal > efflev-9) heal = efflev-9; } flags.botl = 1; u.uhp += heal; if(u.uhp > u.uhpmax) u.uhp = u.uhpmax; } else if (Regeneration || (efflev <= 9 && !(moves % ((MAXULEV+12) / (u.ulevel+2) + 1)))) { flags.botl = 1; u.uhp++; } } if (!u.uinvulnerable && u.uen > 0 && u.uhp < u.uhpmax && tech_inuse(T_CHI_HEALING)) { u.uen--; u.uhp++; flags.botl = 1; } /* moving around while encumbered is hard work */ if (wtcap > MOD_ENCUMBER && u.umoved) { if(!(wtcap < EXT_ENCUMBER ? moves%30 : moves%10)) { if (Upolyd && u.mh > 1) { u.mh--; } else if (!Upolyd && u.uhp > 1) { u.uhp--; } else { You("pass out from exertion!"); exercise(A_CON, FALSE); fall_asleep(-10, FALSE); } } } /* KMH -- OK to regenerate if you don't move */ if ((u.uen < u.uenmax) && (Energy_regeneration || ((wtcap < MOD_ENCUMBER || !flags.mv) && (!(moves%((MAXULEV + 15 - u.ulevel) * (Role_if(PM_WIZARD) ? 3 : 4) / 6)))))) { u.uen += rn1((int)(ACURR(A_WIS) + ACURR(A_INT)) / 15 + 1,1); #ifdef WIZ_PATCH_DEBUG pline("mana was = %d now = %d",temp,u.uen); #endif if (u.uen > u.uenmax) u.uen = u.uenmax; flags.botl = 1; } if(!u.uinvulnerable) { if(Teleportation && !rn2(85)) { xchar old_ux = u.ux, old_uy = u.uy; tele(); if (u.ux != old_ux || u.uy != old_uy) { if (!next_to_u()) { check_leash(&youmonst, old_ux, old_uy, TRUE); } #ifdef REDO /* clear doagain keystrokes */ pushch(0); savech(0); #endif } } long ch = (80 - (40 * night())) / 2 * (Race_if(PM_HUMAN_WEREWOLF) ? u.ulevel * u.ulevel : 2); ch = (ch > LARGEST_INT) ? LARGEST_INT : ch; /* delayed change may not be valid anymore */ if ((change == 1 && !Polymorph) || (change == 2 && u.ulycn == NON_PM)) change = 0; if(Polymorph && !rn2(100)) change = 1; else if (u.ulycn >= LOW_PM && !Upolyd && !rn2((int)ch)) change = 2; if (change && !Unchanging) { if (multi >= 0) { if (occupation) stop_occupation(); else nomul(0); if (change == 1) polyself(FALSE); else you_were(); change = 0; } } } /* !u.uinvulnerable */ if(Searching && multi >= 0) (void) dosearch0(1); dosounds(); do_storms(); gethungry(); age_spells(); exerchk(); invault(); if (u.uhave.amulet) amulet(); if (!rn2(40+(int)(ACURR(A_DEX)*3))) u_wipe_engr(rnd(3)); if (u.uevent.udemigod && !u.uinvulnerable) { if (u.udg_cnt) u.udg_cnt--; if (!u.udg_cnt) { intervene(); u.udg_cnt = rn1(200, 50); } } restore_attrib(); /* underwater and waterlevel vision are done here */ if (Is_waterlevel(&u.uz)) movebubbles(); else if (Underwater) under_water(0); /* vision while buried done here */ else if (u.uburied) under_ground(0); /* when immobile, count is in turns */ if(multi < 0) { if (++multi == 0) { /* finished yet? */ unmul((char *)0); /* if unmul caused a level change, take it now */ if (u.utotype) deferred_goto(); } } } } while (youmonst.movement<NORMAL_SPEED); /* hero can't move loop */ /******************************************/ /* once-per-hero-took-time things go here */ /******************************************/ } /* actual time passed */ /****************************************/ /* once-per-player-input things go here */ /****************************************/ find_ac(); if(!flags.mv || Blind) { /* redo monsters if hallu or wearing a helm of telepathy */ if (Hallucination) { /* update screen randomly */ see_monsters(); see_objects(); see_traps(); if (u.uswallow) swallowed(0); } else if (Unblind_telepat) { see_monsters(); } else if (Warning || Warn_of_mon) see_monsters(); if (vision_full_recalc) vision_recalc(0); /* vision! */ } if(flags.botl || flags.botlx) bot(); flags.move = 1; if(multi >= 0 && occupation) { #if defined(MICRO) || defined(WIN32) abort_lev = 0; if (kbhit()) { if ((ch = Getchar()) == ABORT) abort_lev++; # ifdef REDO else pushch(ch); # endif /* REDO */ } if (!abort_lev && (*occupation)() == 0) #else if ((*occupation)() == 0) #endif occupation = 0; if( #if defined(MICRO) || defined(WIN32) abort_lev || #endif monster_nearby()) { stop_occupation(); reset_eat(); } #if defined(MICRO) || defined(WIN32) if (!(++occtime % 7)) display_nhwindow(WIN_MAP, FALSE); #endif continue; } if ((u.uhave.amulet || Clairvoyant) && !In_endgame(&u.uz) && !BClairvoyant && !(moves % 15) && !rn2(2)) do_vicinity_map(); if(u.utrap && u.utraptype == TT_LAVA) { if(!is_lava(u.ux,u.uy)) u.utrap = 0; else if (!u.uinvulnerable) { u.utrap -= 1<<8; if(u.utrap < 1<<8) { killer_format = KILLED_BY; killer = "molten lava"; You("sink below the surface and die."); done(DISSOLVED); } else if(didmove && !u.umoved) { Norep("You sink deeper into the lava."); u.utrap += rnd(4); } } } #ifdef WIZARD if (iflags.sanity_check) sanity_check(); #endif #ifdef CLIPPING /* just before rhack */ cliparound(u.ux, u.uy); #endif u.umoved = FALSE; if (multi > 0) { lookaround(); if (!multi) { /* lookaround may clear multi */ flags.move = 0; if (flags.time) flags.botl = 1; continue; } if (flags.mv) { if(multi < COLNO && !--multi) flags.travel = iflags.travel1 = flags.mv = flags.run = 0; domove(); } else { --multi; rhack(save_cm); } } else if (multi == 0) { #ifdef MAIL ckmailstatus(); #endif rhack((char *)0); } if (u.utotype) /* change dungeon level */ deferred_goto(); /* after rhack() */ /* !flags.move here: multiple movement command stopped */ else if (flags.time && (!flags.move || !flags.mv)) flags.botl = 1; if (vision_full_recalc) vision_recalc(0); /* vision! */ /* when running in non-tport mode, this gets done through domove() */ if ((!flags.run || iflags.runmode == RUN_TPORT) && (multi && (!flags.travel ? !(multi % 7) : !(moves % 7L)))) { if (flags.time && flags.run) flags.botl = 1; display_nhwindow(WIN_MAP, FALSE); } } }