/** * @brief synchronize a container * * @param[in] container The container to synchronize. * * @param[in] state The partial state to synch this container to. * * Synchronizes the container @a container and it's desired children to be as written down in * the WindowStateBase @a state. * * The process involves 3 steps: * 1. find or create any View or ContainerWidget objects required to fill the container. * This will recurse into sub containers. * 2. remove anything that is left over in the @a container. * 3. add the found objects to @a container. */ void ModeSwitcher::synchronizeContainer(ContainerWidget* container, XmlState* state) { QList< AbstractViewWidget* > newContents; // We start by creating a list of what shall be inside the container. Thus we call the // grabXXX methods which will search anything existing and give it to us (in case it is // reusable). If grabXXX won't find anything, it will create something new. // During this run, we recurse into sub-containers. foreach (const XmlState::Ptr& ws, state->children()) { AbstractViewWidget* next = NULL; switch(ws->type()) { case XmlState::WSView: next = grabView(static_cast<XmlStateView*>(ws.data())); break; case XmlState::WSSplitter: next = grabSplitter(static_cast<XmlStateSplitter*>(ws.data())); synchronizeContainer(next->asContainerWidget(), ws.data()); break; case XmlState::WSTab: next = grabTab(static_cast<XmlStateTab* >(ws.data())); synchronizeContainer(next->asContainerWidget(), ws.data()); break; default: break; } Q_ASSERT_X(next, "synchronizeContainer", qPrintable( QString(QLatin1String("Invalid window state (%1) for child " "\"%2\" of container \"%3\"")) .arg(ws->type()) .arg(ws->identifier().toString()) .arg(container->identifier().toString()) )); associateViewContainer(next, ws.data()); newContents.append(next); } // We have now taken all views that we want to reuse "out" of the container, leaving only // the ones which are referenced by mExistingViews but shall no longer be inside this // container. If they will not be reused until the end of this run, killUnsed() will take // care of conserving their content and delete the views. // So, all we need to do here is to take anything that's still inside the container away. while(container->count()) { container->takeAt(container->count() - 1); } // Insert all Views/Containers we want into the ContainerWidget foreach (AbstractViewWidget* viewToAdd, newContents) { container->add(viewToAdd); }
int clean(const char *devFile, const char *logFile, const char *strR1, const char *strR2, const char *strSE, int tmpforcePairs, int tmpPolyATTrim) { int forcePairs = tmpforcePairs; FILE *f = fopen(devFile, "r"); //FILE *f = stderr; FILE *R1 = NULL; FILE *R2 = NULL; FILE *SE = NULL; FILE *log = NULL; struct reads r; struct stats s; int sum = 0, R1_len = 0, R2_len = 0, SE_len = 0; statsConstruct(&s); PolyATTrim = tmpPolyATTrim; while (grabTab(f, &r, &s)) { if ((r.r2).r_header != NULL && (r.r1).r_header != NULL) { s.pe_kept++; if (R1 == NULL) { R1 = fopen(strR1, "a"); } if (R2 == NULL) { R2 = fopen(strR2, "a"); } if ((r.r1).r_header[0] == '@') { if ((r.r1).r_header[strlen((r.r1).r_header)-1] == '1') { fprintf(R1, "%s\n%s\n+\n%s\n", (r.r1).r_header, (r.r1).r_seq, (r.r1).r_qual); (r.r2).r_header[strlen((r.r2).r_header)-1] = '2'; fprintf(R2, "%s\n%s\n+\n%s", (r.r2).r_header, (r.r2).r_seq, (r.r2).r_qual); } else { fprintf(R1, "%s/1\n%s\n+\n%s\n", (r.r1).r_header, (r.r1).r_seq, (r.r1).r_qual); fprintf(R2, "%s/2\n%s\n+\n%s", (r.r2).r_header, (r.r2).r_seq, (r.r2).r_qual); } } else { fprintf(R1, "@%s/1\n%s\n+\n%s\n", (r.r1).r_header, (r.r1).r_seq, (r.r1).r_qual); fprintf(R2, "@%s/2\n%s\n+\n%s", (r.r2).r_header, (r.r2).r_seq, (r.r2).r_qual); } } else if (forcePairs && (r.r1).r_header != NULL) { s.numForcedPairs++; int loc = (strlen((r.r1).r_seq))/2; char cSeq = (r.r1).r_seq[loc]; char cQual = (r.r1).r_qual[loc]; if (R1 == NULL) { R1 = fopen(strR1, "a"); } if (R2 == NULL) { R2 = fopen(strR2, "a"); } if ((r.r1).r_header[0] == '@') { (r.r1).r_seq[loc] = '\0'; (r.r1).r_qual[loc] = '\0'; fprintf(R1, "%s/1\n%s\n+\n%s\n", (r.r1).r_header, (r.r1).r_seq, (r.r1).r_qual); (r.r1).r_seq[loc] = cSeq; (r.r1).r_qual[loc] = cQual; fprintf(R2, "%s/2\n%s\n+\n%s", (r.r1).r_header, reverseComp(&((r.r1).r_seq)[loc]), reverse(&((r.r1).r_qual)[loc])); } else { (r.r1).r_seq[loc] = '\0'; (r.r1).r_qual[loc] = '\0'; fprintf(R1, "@%s/1\n%s\n+\n%s\n", (r.r1).r_header, (r.r1).r_seq, (r.r1).r_qual); (r.r1).r_seq[loc] = cSeq; (r.r1).r_qual[loc] = cQual; fprintf(R2, "@%s/2\n%s\n+\n%s", (r.r1).r_header, reverseComp(&((r.r1).r_seq)[loc]), reverse(&((r.r1).r_qual)[loc])); } } else if ((r.r1).r_header != NULL) { if (SE == NULL) { SE = fopen(strSE, "a"); } s.se_kept++; if ((r.r1).r_header[0] == '@') { fprintf(SE, "%s\n%s\n+\n%s", (r.r1).r_header, (r.r1).r_seq, (r.r1).r_qual); } else { fprintf(SE, "@%s\n%s\n+\n%s", (r.r1).r_header, (r.r1).r_seq, (r.r1).r_qual); } if ((r.r1).r_qual[strlen((r.r1).r_qual)-1] != '\n') { fprintf(SE, "\n"); } } } if (log == NULL) { log = fopen(logFile, "a"); } for (sum = 0; sum < 700; sum++) { R1_len += (s.R1_length[sum] * sum); R2_len += (s.R2_length[sum] * sum); SE_len += (s.SE_length[sum] * sum); } fprintf(log, "A\tT\tG\tC\tN\tPolyA_Removed_Reads\tPolyT_Removed_Reads\tShort_discarded\tPE_Kept\tSE_Kept\tForced_Pairs\tR1_Ave_Len\tR2_Ave_Len\tSE_Ave_Len\tAverageQual\n"); fprintf(log, "%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t\ %.2f\t%.2f\t%.2f\t%.2f\n", s.A, s.T, s.G, s.C, s.N, s.polyATrimmed, s.polyTTrimmed, s.r1_discarded + s.r2_discarded + s.se_discarded, s.pe_kept, s.se_kept, s.numForcedPairs, (float)R1_len/(float)(s.pe_kept), (float)R2_len/(float)(s.pe_kept), (float)SE_len/(float)(s.se_kept), (float)((float)(s.qualTotal)/(float)(s.A + s.T + s.C + s.G + s.N))); if (f != NULL) { fclose(f); } if (R1 != NULL) { fclose(R1); fclose(R2); } if (SE != NULL) { fclose(SE); } if (log != NULL) { fclose(log); } return 1; }