diff options
author | mutantturkey <mutantturke@gmail.com> | 2013-02-22 09:48:27 -0500 |
---|---|---|
committer | mutantturkey <mutantturke@gmail.com> | 2013-02-22 09:48:27 -0500 |
commit | efd654edf66e0a58964fc65ac2df9697123c4744 (patch) | |
tree | c88747c3fa2ad9f44bed6bde4fd06fb855011722 /quikr.py | |
parent | d252aeb1e3a4a45d3a0783ff90da37e381d23d78 (diff) |
require more arguments since people will always be required to have certain ones, simplfies our checks, also remove all out print shapes
Diffstat (limited to 'quikr.py')
-rwxr-xr-x | quikr.py | 50 |
1 files changed, 16 insertions, 34 deletions
@@ -10,6 +10,7 @@ import platform def main(): + parser = argparse.ArgumentParser(description= "Quikr returns the estimated frequencies of batcteria present when given a \ input FASTA file. \n \ @@ -17,43 +18,32 @@ def main(): You must supply a kmer and default lambda if using a custom trained \ matrix.") - parser.add_argument("-f", "--fasta", help="path to a fasta file", required=True) - parser.add_argument("-o", "--output", help="the path to write your probability vector (csv output)", required=True) - parser.add_argument("-t", "--trained-matrix", help="path to a custom trained matrix") + parser.add_argument("-f", "--fasta", help="fasta file", required=True) + parser.add_argument("-o", "--output", help="output path (csv output)", required=True) + parser.add_argument("-t", "--trained-matrix", help="trained matrix", required=True) parser.add_argument("-l", "--lamb", type=int, help="the default lambda value is 10,000") - parser.add_argument("-k", "--kmer", type=int, + parser.add_argument("-k", "--kmer", type=int, required=True, help="specifies which kmer to use, must be used with a custom trained database") args = parser.parse_args() + + # our default lambda is 10,000 + lamb = 10000 - # Do some basic sanity checks + # Make sure our input exist if not os.path.isfile(args.fasta): parser.error( "Input fasta file not found") + + if not os.path.isfile(args.trained_matrix): + parser.error("custom trained matrix not found") - # If we are using a custom trained matrix, we need to do some basic checks - if args.trained_matrix is not None: - trained_matrix_location = args.trained_matrix - - if not os.path.isfile(args.trained_matrix): - parser.error("custom trained matrix not be found") - - if args.kmer is None: - parser.error("A kmer is required when using a custom matrix") - else: - kmer = args.kmer - - if args.lamb is None: - # use 10,000 as default Lambda - input_lambda = 10000 - # If we aren't using a custom trained matrix, load in the defaults - else: - trained_matrix_location = "output.npy" - input_lambda = 10000 - kmer = 6 + # use alternative lambda + if args.lamb is not None: + lamb = args.lamb - xstar = quikr(args.fasta, trained_matrix_location, kmer, input_lambda) + xstar = quikr(args.fasta, args.trained_matrix, args.kmer, lamb) np.savetxt(args.output, xstar, delimiter=",", fmt="%f") return 0 @@ -87,23 +77,15 @@ def quikr(input_fasta_location, trained_matrix_location, kmer, default_lambda): counts = np.loadtxt(count_input.stdout) counts = counts / counts.sum(0) counts = default_lambda * counts - print counts.shape counts = np.concatenate([np.zeros(1), counts]) # load our trained matrix trained_matrix = np.load(trained_matrix_location) - print counts.shape - print trained_matrix.shape - #form the k-mer sensing matrix trained_matrix = trained_matrix * default_lambda; - trained_matrix = np.transpose(trained_matrix); trained_matrix = np.vstack((np.ones(trained_matrix.shape[1]), trained_matrix)) - # trained_matrix = np.transpose(trained_matrix); - - print trained_matrix.shape xstar, rnorm = scipy.optimize.nnls(trained_matrix, counts) |