-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathTFReferenceGenerator.cpp
More file actions
126 lines (100 loc) · 2.87 KB
/
Copy pathTFReferenceGenerator.cpp
File metadata and controls
126 lines (100 loc) · 2.87 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* Copyright (C) 2011 Ion Torrent Systems, Inc. All Rights Reserved */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <getopt.h> // for getopt_long
#include <assert.h>
#include "IonVersion.h"
#include "TFs.h"
#include "dbgmem.h"
using namespace std;
// TODO: Replace me with a cute python script
void usage ()
{
fprintf (stdout, "TFReferenceGenerator - Convert DefaultTFs.conf to fasta\n");
fprintf (stdout, "options:\n");
fprintf (stdout, " --TF\t\tSpecify filename containing Test Fragments to map to.\n");
fprintf (stdout, " --key\tOnly convert TFs with this key. (default ATCG)\n");
fprintf (stdout, "\n");
fprintf (stdout, "usage:\n");
fprintf (stdout, " TFReferenceGenerator output.fasta\n");
fprintf (stdout, "\n");
exit(1);
}
#ifdef _DEBUG
void memstatus(void)
{
memdump();
dbgmemClose();
}
#endif /* _DEBUG */
int main(int argc, char *argv[])
{
#ifdef _DEBUG
atexit(memstatus);
dbgmemInit();
#endif /* _DEBUG */
printf ("%s - %s-%s (%s)\n\n", argv[0],
IonVersion::GetVersion().c_str(), IonVersion::GetRelease().c_str(), IonVersion::GetSvnRev().c_str());
fflush (stdout);
string key = "ATCG";
char *TFoverride = NULL;
int c;
int option_index = 0;
static struct option long_options[] = {
{"TF", required_argument, NULL, 0},
{"key", required_argument, NULL, 0},
{NULL, 0, NULL, 0}};
while ((c = getopt_long(argc, argv, "", long_options, &option_index)) != -1) {
switch (c) {
case (0):
if (long_options[option_index].flag != 0)
break;
if (strcmp(long_options[option_index].name, "TF") == 0)
TFoverride = optarg;
if (strcmp(long_options[option_index].name, "key") == 0)
key = optarg;
break;
default:
fprintf(stderr, "Unrecognized option (%c)\n", c);
exit(1);
}
}
// Pick up the sff filename
if (optind >= argc)
usage();
// open up our TF config file
TFs tfs("TACG");
if (TFoverride != NULL) { // TF config file was specified on command line
if (tfs.LoadConfig(TFoverride) == false) {
fprintf (stderr, "Error: Specified TF config file, '%s', was not found.\n", TFoverride);
exit(1);
}
}
else { // Search for TF config file and open it
char *tfConfigFileName = tfs.GetTFConfigFile();
if (tfConfigFileName == NULL) {
fprintf (stderr, "Error: No TF config file was found.\n");
exit(1);
}
else {
tfs.LoadConfig(tfConfigFileName);
free (tfConfigFileName);
}
}
TFInfo *tfInfo = tfs.Info();
int numTFs = tfs.Num();
FILE *fasta = fopen(argv[optind],"w");
if (!fasta) {
printf("Failed to open %s\n", argv[optind]);
exit(1);
}
for(int tf = 0; tf < numTFs; tf++) {
if (key != tfInfo[tf].key)
continue;
fprintf(fasta,">%s\n", tfInfo[tf].name);
fprintf(fasta,"%s\n", tfInfo[tf].seq);
}
fclose(fasta);
}