aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2014-01-17 14:28:49 -0500
committerCalvin Morrison <mutantturkey@gmail.com>2014-01-17 14:28:49 -0500
commitb09eecbec7e7cca1c133ba5923f55713cf7a78cf (patch)
tree6ff08efad3b5dcd2aef32905b4637625d6c8d6ea /src
parentecc00aae08c06ae2da5629533ef69d7c5ffd86fe (diff)
update makefile and make a src directory
Diffstat (limited to 'src')
-rw-r--r--src/melting_range.c58
-rw-r--r--src/strstream.c52
-rw-r--r--src/strstreamone.c43
3 files changed, 153 insertions, 0 deletions
diff --git a/src/melting_range.c b/src/melting_range.c
new file mode 100644
index 0000000..2c89195
--- /dev/null
+++ b/src/melting_range.c
@@ -0,0 +1,58 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+float melting_temperature(char *mer) {
+
+ float a = 0;
+ float c = 0;
+ float g = 0;
+ float t = 0;
+ int i = 0;
+
+ for(i = 0; i < strlen(mer); i++) {
+ switch(mer[i]) {
+ case 'A':
+ a++;
+ break;
+ case 'C':
+ c++;
+ break;
+ case 'G':
+ g++;
+ break;
+ case 'T':
+ t++;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if(strlen(mer) < 13)
+ return ((a+t) * 2) + ((c+g) * 4);
+ else
+ return 64.9 + 41.0*(g+c-16.4)/(a+t+g+c);
+}
+
+int main(int argc, char **argv){
+
+ if(argc < 3) {
+ printf("please supply the min and max as stdargs");
+ exit(EXIT_FAILURE);
+ }
+ float min = atof(argv[1]);
+ float max = atof(argv[2]);
+
+ char mer[24] = { 0 };
+ int count = 0;
+
+ while(fscanf(stdin, "%s\t%d\n", &mer, &count) == 2) {
+ float temp = melting_temperature(mer);
+ if( (temp > min) && (temp < max) )
+ printf("%s\t%d\n", mer, count);
+ }
+
+ exit(EXIT_SUCCESS);
+}
diff --git a/src/strstream.c b/src/strstream.c
new file mode 100644
index 0000000..f4a296e
--- /dev/null
+++ b/src/strstream.c
@@ -0,0 +1,52 @@
+// find string in
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char **argv){
+
+ char buffer[BUFSIZ] = { 0 };
+ char *buf, *start;
+ ssize_t len = 0;
+
+ int save_size = 0;
+ int cpy = 0;
+
+ unsigned long long pos = 0;
+ unsigned long long cpy_size = 0;
+
+ int i = 0;
+
+ // get max argument length
+ for(i = 1; i < argc; i++) {
+ int len = strlen(argv[i]);
+ if(len > save_size)
+ save_size = len;
+ }
+
+ cpy = save_size - 1;
+ cpy_size = BUFSIZ - cpy;
+
+ buf = buffer;
+ start = buf + cpy;
+
+ // copy our first cpy length into the first part of our buffer
+ len = fread(buffer, 1, cpy, stdin);
+ if(len == 0)
+ exit(EXIT_FAILURE);
+
+ // read into "start" (buf + cpy) from stdin
+ while((len = fread(start, 1, cpy_size, stdin)) != 0) {
+ for(i = 1; i < argc; i++) {
+ char *p = buffer;
+ while((p = strstr(p, argv[i])) != NULL) {
+ printf("%d %llu\n", i - 1, pos + (p - buffer));
+ p++;
+ }
+ }
+ memcpy(buffer, buffer + len, cpy);
+ pos = pos + len;
+ }
+ return 0;
+}
diff --git a/src/strstreamone.c b/src/strstreamone.c
new file mode 100644
index 0000000..68da309
--- /dev/null
+++ b/src/strstreamone.c
@@ -0,0 +1,43 @@
+// find string in
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char **argv){
+
+ char buffer[BUFSIZ] = { 0 };
+ char *buf, *start;
+ ssize_t len = 0;
+
+ int cpy = 0;
+
+ unsigned long long pos = 0;
+ unsigned long long cpy_size = 0;
+
+ // get max argument length
+ int save_size = strlen(argv[1]);
+
+ cpy = save_size - 1;
+ cpy_size = BUFSIZ - cpy;
+
+ buf = buffer;
+ start = buf + cpy;
+
+ // copy our first cpy length into the first part of our buffer
+ len = fread(buffer, 1, cpy, stdin);
+ if(len == 0)
+ exit(EXIT_FAILURE);
+
+ // read into "start" (buf + cpy) from stdin
+ while((len = fread(start, 1, cpy_size, stdin)) != 0) {
+ char *p = buffer;
+ while((p = strstr(p, argv[1])) != NULL) {
+ printf("%llu\n", pos + (p - buffer));
+ p++;
+ }
+ memcpy(buffer, buffer + len, cpy);
+ pos = pos + len;
+ }
+ return 0;
+}