summaryrefslogtreecommitdiff
path: root/quikr_train
blob: 9e9caa7d3b582713edb07dd7754fbe579f7aeca5 (plain)
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
#!/usr/bin/python
import numpy as np
import quikr
import os
import sys
import gzip
from subprocess import *
import platform
import argparse

def main():
  """
  You can call this script independently, and will save the 
  trained matrix as a numpy file.
  example: python quikr-train.py -i input.fasta -k 6 -o trained_matrix.npy
 
  """
  parser = argparse.ArgumentParser(description=
  " quikr_train returns a custom trained matrix that can be used with \
    the quikr function. \n You must supply a kmer. \n ")

  parser.add_argument("-i", "--input", help="training database of sequences (fasta format)", required=True)
  parser.add_argument("-o", "--output", help="sensing matrix (text file)", required=True)
  parser.add_argument("-k", "--kmer", help="kmer size (integer)", 
                      type=int, required=False )
  parser.add_argument("-z", "--compress", help="compress output (integer)", 
                      action='store_true', required=False)

  args = parser.parse_args()

  if not os.path.isfile(args.input):
    parser.error( "Input database not found")

  # call the quikr train function, save the output with np.save
  matrix = quikr.quikr_train(args.input, args.kmer)

  if args.compress: 
    output_file = gzip.open(args.output, "wb")
  else:
    output_file = open(args.output, "wb")

  np.save(output_file, matrix)

  return 0
  
if __name__ == "__main__":
    sys.exit(main())