File: maqmap_conv.c

package info (click to toggle)
maq 0.7.1-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,500 kB
  • sloc: cpp: 5,025; ansic: 3,333; sh: 3,303; perl: 2,547; makefile: 31
file content (63 lines) | stat: -rw-r--r-- 1,621 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <zlib.h>
#include "maqmap.h"
#include "main.h"

typedef struct
{
	bit8_t seq[MAX_READLEN];
	bit8_t size, map_qual, i1, i2, c[2], flag, alt_qual;
	bit32_t seqid, pos;
	int dist;
} maqmap1_oldaux_t;

void maqmap_conv_core(gzFile fpold, gzFile fpnew)
{
	maqmap_t *mm = maq_new_maqmap();
	bit32_t i, n_reads;
	maqmap1_oldaux_t *mo1, mmo1;
	maqmap1_t *m1, mm1;
	int k, len;
	mo1 = &mmo1; m1 = &mm1;
	memset(m1, 0, sizeof(maqmap1_t));
	/* read the header */
	gzread(fpold, &mm->n_ref, sizeof(int));
	if (mm->n_ref == MAQMAP_FORMAT_NEW) {
		fprintf(stderr, "** New map format is detected. No need to convert the format.\n");
		exit(3);
	}
	mm->ref_name = (char**)calloc(mm->n_ref, sizeof(char*));
	for (k = 0; k != mm->n_ref; ++k) {
		gzread(fpold, &len, sizeof(int));
		mm->ref_name[k] = (char*)malloc(len * sizeof(char));
		gzread(fpold, mm->ref_name[k], len);
	}
	gzread(fpold, &n_reads, sizeof(bit32_t));
	mm->n_mapped_reads = n_reads;
	maqmap_write_header(fpnew, mm);
	maq_delete_maqmap(mm);
	/* read and convert records */
	for (i = 0; i != n_reads; ++i) {
		gzread(fpold, mo1, sizeof(maqmap1_oldaux_t));
		memcpy(m1, mo1, sizeof(maqmap1_oldaux_t));
		sprintf(m1->name, "%u", i);
		gzwrite(fpnew, m1, sizeof(maqmap1_t));
	}
}

int ma_mapass2maq(int argc, char *argv[])
{
	gzFile fpold, fpnew;
	if (argc < 3) {
		fprintf(stderr, "maq mapass2maq <mapass2.map> <maq.map>\n");
		return 1;
	}
	fpold = gzopen(argv[1], "r");
	fpnew = gzopen(argv[2], "w");
	assert(fpold && fpnew);
	maqmap_conv_core(fpold, fpnew);
	gzclose(fpold); gzclose(fpnew);
	return 0;
}