Debian Codegraph @

atac-driver/gapShifter/extractSequence.C

raw symbols SCIP
1 // This file is part of A2Amapper.
2 // Copyright (c) 2006 J. Craig Venter Institute
3 // Author: Brian Walenz
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received (LICENSE.txt) a copy of the GNU General Public
16 // License along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22
23 #include "atac.H"
24 #include "bio++.H"
25 #include "seqCache.H"
26
27 // Reads a set of matches and outputs sequence that was mapped. Filters matches, etc.
28
29 void
30 extractA(seqCache *A, seqCache *B,
31 FILE *Aoutput, FILE *Boutput,
32 uint32 Aiid,
33 uint32 Biid,
34 atacMatchList &ML) {
35
36 }
37
38
39 void
40 usage(char *name) {
41 fprintf(stderr, "usage: %s [-OP output.fasta] [-t trfile] -m matches\n", name);
42 fprintf(stderr, " OP\n");
43 fprintf(stderr, " -a extract all unmapped sequence in A\n");
44 fprintf(stderr, " -b extract all unmapped sequence in B\n");
45 fprintf(stderr, " -ar extract within run unmapped sequence in A\n");
46 fprintf(stderr, " -br extract within run unmapped sequence in B\n");
47 fprintf(stderr, " BOTH -ar and -br need to be specified!\n");
48 fprintf(stderr, "\n");
49 fprintf(stderr, " -t mask out tandem repeats listed in trfile\n");
50 }
51
52 FILE *
53 openOutputFile(char *name) {
54 errno = 0;
55 FILE *R = fopen(name, "w");
56 if (errno)
57 fprintf(stderr, "Failed to open '%s': %s\n", name, strerror(errno)), exit(1);
58 return(R);
59 }
60
61 int
62 main(int argc, char *argv[]) {
63 char *matchesFile = 0L;
64 FILE *Aoutput = 0L;
65 FILE *Boutput = 0L;
66 uint32 Aiid = ~uint32ZERO;
67 uint32 Biid = ~uint32ZERO;
68
69 int arg=1;
70 while (arg < argc) {
71 if (strcmp(argv[arg], "-m") == 0) {
72 matchesFile = argv[++arg];
73 } else if (strcmp(argv[arg], "-a") == 0) {
74 Aoutput = openOutputFile(argv[++arg]);
75 } else if (strcmp(argv[arg], "-b") == 0) {
76 Boutput = openOutputFile(argv[++arg]);
77
78 } else if (strcmp(argv[arg], "-1") == 0) {
79 Aiid = strtouint32(argv[++arg], 0L);
80 } else if (strcmp(argv[arg], "-2") == 0) {
81 Biid = strtouint32(argv[++arg], 0L);
82 } else {
83 usage(argv[0]);
84 exit(1);
85 }
86 arg++;
87 }
88
89 if (matchesFile == 0L)
90 usage(argv[0]), exit(1);
91
92 atacFile AF(matchesFile);
93 atacMatchList &ML = *AF.matches();
94
95 seqCache *A = new seqCache(AF.assemblyFileA(), 0, true);
96 seqCache *B = new seqCache(AF.assemblyFileB(), 0, true);
97
98 A->loadAllSequences();
99 B->loadAllSequences();
100
101 for (uint32 x=0; x<ML.numMatches(); x++) {
102 atacMatch *m = ML[x];
103
104 if (((Aiid == ~uint32ZERO) || (Aiid == m->iid1)) &&
105 ((Biid == ~uint32ZERO) || (Biid == m->iid2))) {
106
107 if (Aoutput) {
108 seqInCore *S = A->getSequenceInCore(m->iid1);
109
110 fprintf(Aoutput, "%s extracted from iid "uint32FMT" pos "uint32FMT" "uint32FMT" match %s(%s)\n",
111 S->header(), S->getIID(),
112 m->pos1, m->pos1 + m->len1,
113 m->matchuid, m->parentuid);
114 fwrite(S->sequence() + m->pos1, sizeof(char), m->len1, Aoutput);
115 fprintf(Aoutput, "\n");
116 }
117
118 if (Boutput) {
119 seqInCore *S = B->getSequenceInCore(m->iid2);
120
121 fprintf(Boutput, "%s extracted from iid "uint32FMT" pos "uint32FMT" "uint32FMT" match %s(%s)\n",
122 S->header(), S->getIID(),
123 m->pos2, m->pos2 + m->len2,
124 m->matchuid, m->parentuid);
125 fwrite(S->sequence() + m->pos2, sizeof(char), m->len2, Boutput);
126 fprintf(Boutput, "\n");
127 }
128 }
129 }
130
131 if (Aoutput) fclose(Aoutput);
132 if (Boutput) fclose(Boutput);
133
134 return(0);
135 }