comparison yac.py @ 3:6b8adacd4750 draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
author artbio
date Wed, 26 Jul 2017 19:15:08 -0400
parents da29af78a960
children ffcd42f85b61
comparison
equal deleted inserted replaced
2:f59c643b00fc 3:6b8adacd4750
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # yac = yet another clipper 2 # yac = yet another clipper
3 # v 1.2.1 - 23-08-2014 - Support FastQ output 3 # v 1.2.1 - 23-08-2014 - Support FastQ output
4 # v 1.1.0 - 23-08-2014 - argparse implementation 4 # v 1.1.0 - 23-08-2014 - argparse implementation
5 # Usage yac.py $input $output $adapter_to_clip $min $max $Nmode
6 # Christophe Antoniewski <drosofff@gmail.com> 5 # Christophe Antoniewski <drosofff@gmail.com>
7 6
8 import sys
9 import string
10 import argparse 7 import argparse
11 from itertools import islice 8 from itertools import islice
12 9
13 10
14 def Parser(): 11 def Parser():
15 the_parser = argparse.ArgumentParser() 12 the_parser = argparse.ArgumentParser()
16 the_parser.add_argument( 13 the_parser.add_argument(
17 '--input', action="store", nargs='+', help="input fastq files") 14 '--input', action="store", nargs='+', help="input fastq files")
18 the_parser.add_argument( 15 the_parser.add_argument(
19 '--output', action="store", type=str, help="output, clipped fasta file") 16 '--output', action="store", type=str,
17 help="output, clipped fasta file")
20 the_parser.add_argument( 18 the_parser.add_argument(
21 '--output_format', action="store", type=str, help="output format, fasta or fastq") 19 '--output_format', action="store", type=str,
20 help="output format, fasta or fastq")
22 the_parser.add_argument( 21 the_parser.add_argument(
23 '--adapter_to_clip', action="store", type=str, help="adapter sequence to clip") 22 '--adapter_to_clip', action="store", type=str,
23 help="adapter sequence to clip")
24 the_parser.add_argument( 24 the_parser.add_argument(
25 '--min', action="store", type=int, help="minimal size of clipped sequence to keep") 25 '--min', action="store", type=int,
26 help="minimal size of clipped sequence to keep")
26 the_parser.add_argument( 27 the_parser.add_argument(
27 '--max', action="store", type=int, help="maximal size of clipped sequence to keep") 28 '--max', action="store", type=int,
29 help="maximal size of clipped sequence to keep")
28 the_parser.add_argument('--Nmode', action="store", type=str, choices=[ 30 the_parser.add_argument('--Nmode', action="store", type=str, choices=[
29 "accept", "reject"], help="accept or reject sequences with N for clipping") 31 "accept", "reject"],
32 help="accept or reject Ns in clipped sequences")
30 args = the_parser.parse_args() 33 args = the_parser.parse_args()
31 args.adapter_to_clip = args.adapter_to_clip.upper() 34 args.adapter_to_clip = args.adapter_to_clip.upper()
32 return args 35 return args
33 36
34 37
35 class Clip: 38 class Clip:
36 39
37 def __init__(self, inputfile, outputfile, output_format, adapter, minsize, maxsize, Nmode): 40 def __init__(self, inputfile, outputfile, output_format,
41 adapter, minsize, maxsize, Nmode):
38 self.inputfile = inputfile 42 self.inputfile = inputfile
39 self.outputfile = outputfile 43 self.outputfile = outputfile
40 self.output_format = output_format 44 self.output_format = output_format
41 self.adapter = adapter 45 self.adapter = adapter
42 self.minsize = int(minsize) 46 self.minsize = int(minsize)
43 self.maxsize = int(maxsize) 47 self.maxsize = int(maxsize)
44 self.Nmode = Nmode 48 self.Nmode = Nmode
45 49
46 def motives(sequence): 50 def motives(sequence):
47 '''return a list of motives for perfect (6nt) or imperfect (7nt with one mismatch) search on import string module''' 51 '''
52 return a list of motives for perfect (6nt) or
53 imperfect (7nt with one mismatch) search on import string module
54 '''
48 sequencevariants = [ 55 sequencevariants = [
49 sequence[0:6]] # initializes the list with the 6mer perfect match 56 sequence[0:6]] # initializes list with 6mer perfect match
50 dicsubst = {"A": "TGCN", "T": "AGCN", "G": "TACN", "C": "GATN"} 57 dicsubst = {"A": "TGCN", "T": "AGCN", "G": "TACN", "C": "GATN"}
51 for pos in enumerate(sequence[:6]): 58 for pos in enumerate(sequence[:6]):
52 for subst in dicsubst[pos[1]]: 59 for subst in dicsubst[pos[1]]:
53 sequencevariants.append( 60 sequencevariants.append(
54 sequence[:pos[0]] + subst + sequence[pos[0] + 1:7]) 61 sequence[:pos[0]] + subst + sequence[pos[0] + 1:7])
98 105
99 def main(*argv): 106 def main(*argv):
100 instanceClip = Clip(*argv) 107 instanceClip = Clip(*argv)
101 instanceClip.handle_io() 108 instanceClip.handle_io()
102 109
110
103 if __name__ == "__main__": 111 if __name__ == "__main__":
104 args = Parser() 112 args = Parser()
105 id = 0 113 id = 0
106 for inputfile in args.input: 114 for inputfile in args.input:
107 main(inputfile, args.output, args.output_format, 115 main(inputfile, args.output, args.output_format,