-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8243a11
commit 6f558c8
Showing
2 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// | ||
// config.c | ||
// PASSFinder | ||
// | ||
// Created by Georgi Tushev on 07/09/16. | ||
// Copyright © 2016 Scientific Computing. All rights reserved. | ||
// | ||
|
||
#include "config.h" | ||
|
||
const char VERSION[] = "v0.01"; | ||
const char PROGRAM_NAME[] = "FastPASSFinder"; | ||
|
||
int parseSettings(int argc, char *argv[], Settings *config) | ||
{ | ||
// initialize default values | ||
config->input = NULL; | ||
config->maskpoly = NULL; | ||
config->output = NULL; | ||
config->window = DEFAULT_WINDOW; | ||
config->depth = DEFAULT_DEPTH; | ||
config->sizepoly = DEFAULT_SIZEPOLY; | ||
|
||
if(argc < 5) | ||
{ | ||
fprintf(stderr,"Error:: provide input and output streams!\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// do some parsing | ||
for(int i = 1; i < argc; i++) | ||
{ | ||
// current paramter length | ||
uint64_t parameterLength = strlen(argv[i]); | ||
|
||
// check each parameter and its value | ||
if((PARAMETER_CHECK("-h", 2, parameterLength)) || | ||
(PARAMETER_CHECK("--help", 6, parameterLength))) | ||
{ | ||
help(); | ||
} | ||
else if((PARAMETER_CHECK("-v", 2, parameterLength)) || | ||
(PARAMETER_CHECK("--version", 9, parameterLength))) | ||
{ | ||
version(); | ||
} | ||
else if((PARAMETER_CHECK("-w", 2, parameterLength)) || (PARAMETER_CHECK("--window", 8, parameterLength))) | ||
{ | ||
i += 1; | ||
config->window = strtol(argv[i], NULL, 10); | ||
|
||
if (config->window <= 0) | ||
{ | ||
fprintf(stderr, "Error:: window size should be >0!\n"); | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
else if((PARAMETER_CHECK("-d", 2, parameterLength)) || | ||
(PARAMETER_CHECK("--depth", 7, parameterLength))) | ||
{ | ||
i += 1; | ||
config->depth = strtol(argv[i], NULL, 10); | ||
|
||
if(config->depth <= 0) | ||
{ | ||
fprintf(stderr,"Error:: base depth should be >0!\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
} | ||
else if((PARAMETER_CHECK("-p", 2, parameterLength)) || | ||
(PARAMETER_CHECK("--polysize", 10, parameterLength))) | ||
{ | ||
i += 1; | ||
config->sizepoly = strtol(argv[i], NULL, 10); | ||
|
||
if(config->sizepoly <= 0) | ||
{ | ||
fprintf(stderr,"Error:: read poly tail/head size should be >0!\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
} | ||
else if((PARAMETER_CHECK("-i", 2, parameterLength)) || | ||
(PARAMETER_CHECK("--input", 7, parameterLength))) | ||
{ | ||
i += 1; | ||
|
||
config->input = argv[i]; | ||
|
||
if (config->input == NULL) | ||
{ | ||
fprintf(stderr,"Error:: could not open input stream!\n"); | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
else if((PARAMETER_CHECK("-m", 2, parameterLength)) || | ||
(PARAMETER_CHECK("--maskpoly", 10, parameterLength))) | ||
{ | ||
i += 1; | ||
|
||
config->maskpoly = argv[i]; | ||
|
||
if (config->maskpoly == NULL) | ||
{ | ||
fprintf(stderr, "Error:: could not open genome poly mask file!\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
} | ||
else if((PARAMETER_CHECK("-o", 2, parameterLength)) || | ||
(PARAMETER_CHECK("--output", 8, parameterLength))) | ||
{ | ||
i += 1; | ||
|
||
config->output = argv[i]; | ||
|
||
if (config->output == NULL) | ||
{ | ||
fprintf(stderr, "Error:: could not open file output stream!\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
} | ||
else | ||
{ | ||
fprintf(stderr, "Error:: Unknown parameter %s\n", argv[i]); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
|
||
} | ||
|
||
return 0; | ||
} | ||
|
||
int version(void) | ||
{ | ||
fprintf(stderr, "FastPASSFinder %s\n", VERSION); | ||
return 0; | ||
} | ||
|
||
int help(void) | ||
{ | ||
|
||
fprintf(stderr, "\nTool: FastPASSFinder\n"); | ||
fprintf(stderr, "Version: %s\n", VERSION); | ||
fprintf(stderr, "Summary:\n"); | ||
fprintf(stderr, "\tCluster PolyA supported sites from 3'End sequencing.\n"); | ||
fprintf(stderr, "\nUsage:\t%s [OPTIONS] -i/--input <bam/stdin> -m/--maskpoly <bed> -o/--output <bed/stdout>\n", PROGRAM_NAME); | ||
fprintf(stderr, "Options:\n"); | ||
fprintf(stderr, "\t-i/--input BAM/stdin file\n"); | ||
fprintf(stderr, "\t-o/--output BED/stdout file\n"); | ||
fprintf(stderr, "\t-m/--maskpoly BED/stdin file with genomic poly regions\n"); | ||
fprintf(stderr, "\t-w/--window\tsliding window size\n"); | ||
fprintf(stderr, "\t-d/--depth\tminimum number of polyA reads to define PASS\n"); | ||
fprintf(stderr, "\t-p/--polysize\tminimum number of As for tail and Ts for head to define poly stretch\n"); | ||
fprintf(stderr, "\t-h/--help\tprint help message\n"); | ||
fprintf(stderr, "\t-v/--version\tprint current version\n"); | ||
return 1; | ||
} | ||
|
||
int chompNewLine(char *line_buf) | ||
{ | ||
size_t line_length; | ||
line_length = strlen(line_buf) - 1; | ||
if(line_buf[line_length] == '\n') | ||
line_buf[line_length] = '\0'; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// config.h | ||
// PASSFinder | ||
// | ||
// Created by Georgi Tushev on 07/09/16. | ||
// Copyright © 2016 Scientific Computing. All rights reserved. | ||
// | ||
|
||
#ifndef config_h | ||
#define config_h | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
// define some constants | ||
#define MAX_LENGTH 1024 | ||
#define DEFAULT_WINDOW 200 | ||
#define DEFAULT_DEPTH 5 | ||
#define DEFAULT_SIZEPOLY 3 | ||
|
||
// define MIN & MAX macros | ||
#define MIN(a,b) (((a)<(b))?(a):(b)) | ||
#define MAX(a,b) (((a)>(b))?(a):(b)) | ||
|
||
// define our parameter checking macro | ||
#define PARAMETER_CHECK(param, paramLen, actualLen) (strncmp(argv[i], param, MIN(actualLen, paramLen))== 0) && (actualLen == paramLen) | ||
|
||
|
||
// define parameters | ||
typedef struct _Settings | ||
{ | ||
char *input; | ||
char *maskpoly; | ||
char *output; | ||
int64_t window; | ||
int64_t depth; | ||
int64_t sizepoly; | ||
} Settings; | ||
|
||
// function declarations | ||
int chompNewLine(char *); | ||
int parseSettings(int, char **, Settings *); | ||
int help(void); | ||
int version(void); | ||
|
||
#endif /* config_h */ |