int test_quick_sort() {
    struct dlist* list_to_sort = NULL;

    list_to_sort = generate_dlist();
    print_dlist(list_to_sort);
    //quick_sort(list_to_sort);
    struct dlist* tmp = get_element_by_index(list_to_sort, 1);
    printf("5 element - %d %p\n", tmp->data, tmp);
    print_dlist(list_to_sort);
    free_dlist(list_to_sort);
    return 0;
}
Example #2
0
char *assemble_direct(GapIO *io, int display, double max_mism,
		      char *inlist, int do_alignments, int enter_all) {
    consen_info *ci = NULL;
    SeqInfo *si;
    int ierr;
    char *file;
    int name, dir, pos, tol, maxpads = 25;
    int contig, rnum;
    align_info *ai;
    char *rname;
    int old_clen, count = 1;
    void *dl;
    char *res;
    
    dl = alloc_dlist();

    if (do_alignments)
	/* Calculate consensus */
	if (NULL == (ci = all_consensus(io, consensus_cutoff)))
	    return NULL;

    /* Loop around each input file */
    if (-1 == set_active_list(inlist))
        return NULL;
    while (file = get_active_list_item()) {
	UpdateTextOutput();
	vmessage("Processing number %8d: %s\n", count++, file);
	
	/*
	 * The last argument controls whether to set the QL/QR based on
	 * SL/SR. "1" disables SL/SR use, which is what we need when copying
	 * data in generated by extract_seq. FIXME: this could break things
	 * for other data sources though, unless explicit QL/QR values have
	 * been used.
	 */
	if (NULL == (si = read_sequence_details(file, 1))) {
	    verror(ERR_WARN, "directed_assembly", "couldn't read '%s'", file);
	    add_to_dlist(dl, file);
	    vmessage("  failed\n");
	    continue;
	}
	if (si->start < 0)
	    si->start = 0;
	if (si->end > si->length+1)
	    si->end = si->length+1;

	if (si->end - si->start <= 1 || si->length < 1) {
	    verror(ERR_WARN, "directed assembly", "sequence '%s' too short",
		   file);
	    add_to_dlist(dl, file);
	    freeSeqInfo(si);
	    vmessage("  failed\n");
	    continue;
	}

	if (NULL == (rname = read_sequence_name(si))) {
	    verror(ERR_WARN, "directed_assembly", "no name found for '%s'",
		   file);
	    add_to_dlist(dl, file);
	    freeSeqInfo(si);
	    vmessage("  failed\n");
	    continue;
	}

	/* FIXME: perform caching of names (also template and vector names) */
	if (get_gel_num(io, rname, GGN_NAME) > 0) {
	    verror(ERR_WARN, "directed_assembly",
		   "reading '%s' already exists", rname);
	    add_to_dlist(dl, file);
	    vmessage("  failed\n");
	    freeSeqInfo(si);
	    continue;
	}

	if (exp_Nentries(si->e, EFLT_AP) == 0) {
	    verror(ERR_WARN, "directed_assembly", "no AP line in '%s'", file);
	    add_to_dlist(dl, file);
	    vmessage("  failed\n");
	    freeSeqInfo(si);
	    continue;
	}

	if (0 != AP_parse(io, rname, exp_get_entry(si->e, EFLT_AP),
			  &name, &dir, &pos, &contig, &tol)) {
	    verror(ERR_WARN, "directed_assembly", "invalid AP line in '%s'.",
		   file);
	    name = 0;

	    if (!enter_all) {
		verror(ERR_WARN, "directed_assembly",
		       "invalid AP line in '%s'", file);
		add_to_dlist(dl, file);
		vmessage("  failed\n");
		freeSeqInfo(si);
		continue;
	    }
	}

	ai = NULL;

	if (name != 0) {
	    if (tol >= 0 && do_alignments) {
		/* Align with existing contig */
		ai = assemble_align(io, si, ci, contig, &pos, dir, tol,
				    display, maxpads, max_mism, &ierr);
		if (NULL == ai) {
		    if (ierr == 2) {
			vmessage("  Percentage mismatch is too high\n");
			name = 0;
		    } else if (ierr == 3) {
			vmessage("  Reading does not overlap\n");
			name = 0;
		    } else if (ierr == 4) {
			vmessage("  Reading does not overlap "
				 "within tolerance\n");
			name = 0;
		    } else {
			verror(ERR_WARN, "directed_assembly",
			       "failed to align reading '%s'", file);
			name = 0;
		    }

		    if (!enter_all) {
			add_to_dlist(dl, file);
			freeSeqInfo(si);
			continue;
		    }
		}
	    }
	}

	if (name == 0) {
	    /* new contig */
	    vmessage("  Creating new contig\n");
	    if (-1 == io_init_contig(io, NumContigs(io)+1))
		return NULL;

	    contig=NumContigs(io);
	    io_clnbr(io, contig) = 0;
	    io_crnbr(io, contig) = 0;
	    io_clength(io, contig) = 0;
	    pos = 0;
	}

	old_clen = io_clength(io, contig);
	if (-1 == (rnum = enter_reading(io, si, dir, ai, contig, pos)))
	    return NULL;
	
	if (-1 == link_reading(io, name, rnum, contig, pos))
	    return NULL;

	freeSeqInfo(si);
	if (ai) {
	    xfree(ai->res);
	    xfree(ai);
	}

	if (do_alignments) {
	    if (-1 == recalc_consensus(io, ci, contig, pos,
				       ABS(io_length(io, rnum)),
				       old_clen, io_clength(io, contig))) {
		verror(ERR_WARN, "directed_assembly",
		       "failed to recalculate consensus - quitting");
		return NULL;
	    }
	}
    }

    remove_contig_holes_all(io);

    flush2t(io);
    if (do_alignments)
	free_all_consensus(ci);

    res = strdup(read_dlist(dl));
    free_dlist(dl);

    return res;
}