annotate yac.py @ 6:acbf910cd2ae draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit a3e2a5c2c8d914a574ef35b0f1864ddbde70611b
author artbio
date Mon, 28 Nov 2022 22:17:36 +0000
parents f7947c5a18b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
acbf910cd2ae planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit a3e2a5c2c8d914a574ef35b0f1864ddbde70611b
artbio
parents: 4
diff changeset
1 #!/usr/bin/python3
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
2 # yac = yet another clipper
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
3 # Christophe Antoniewski <drosofff@gmail.com>
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
4
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
5 import argparse
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
6 from itertools import islice
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
7
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
8
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
9 def Parser():
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
10 the_parser = argparse.ArgumentParser()
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
11 the_parser.add_argument(
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
12 '--input', action="store", nargs='+', help="input fastq files")
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
13 the_parser.add_argument(
1
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
14 '--output', action="store", type=str,
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
15 help="output, clipped fasta file")
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
16 the_parser.add_argument(
1
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
17 '--output_format', action="store", type=str,
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
18 help="output format, fasta or fastq")
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
19 the_parser.add_argument(
1
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
20 '--adapter_to_clip', action="store", type=str,
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
21 help="adapter sequence to clip")
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
22 the_parser.add_argument(
1
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
23 '--min', action="store", type=int,
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
24 help="minimal size of clipped sequence to keep")
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
25 the_parser.add_argument(
1
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
26 '--max', action="store", type=int,
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
27 help="maximal size of clipped sequence to keep")
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
28 the_parser.add_argument('--Nmode', action="store", type=str, choices=[
1
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
29 "accept", "reject"],
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
30 help="accept or reject Ns in clipped sequences")
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
31 args = the_parser.parse_args()
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
32 args.adapter_to_clip = args.adapter_to_clip.upper()
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
33 return args
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
34
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
35
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
36 class Clip:
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
37
1
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
38 def __init__(self, inputfile, outputfile, output_format,
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
39 adapter, minsize, maxsize, Nmode):
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
40 self.inputfile = inputfile
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
41 self.outputfile = outputfile
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
42 self.output_format = output_format
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
43 self.adapter = adapter
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
44 self.minsize = int(minsize)
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
45 self.maxsize = int(maxsize)
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
46 self.Nmode = Nmode
3
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
47 for line in open(inputfile):
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
48 if line[0] == "@":
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
49 self.inputformat = "fastq"
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
50 break
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
51 elif line[0] == ">":
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
52 self.inputformat = "fasta"
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
53
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
54 def motives(sequence):
1
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
55 '''
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
56 return a list of motives for perfect (6nt) or
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
57 imperfect (7nt with one mismatch) search on import string module
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
58 '''
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
59 sequencevariants = [
1
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
60 sequence[0:6]] # initializes list with 6mer perfect match
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
61 dicsubst = {"A": "TGCN", "T": "AGCN", "G": "TACN", "C": "GATN"}
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
62 for pos in enumerate(sequence[:6]):
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
63 for subst in dicsubst[pos[1]]:
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
64 sequencevariants.append(
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
65 sequence[:pos[0]] + subst + sequence[pos[0] + 1:7])
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
66 return sequencevariants
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
67 self.adaptmotifs = motives(self.adapter)
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
68
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
69 def scanadapt(self, adaptmotives=[], sequence="", qscore=""):
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
70 '''scans sequence for adapter motives'''
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
71 match_position = sequence.rfind(adaptmotives[0])
3
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
72 if qscore:
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
73 if match_position != -1:
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
74 return sequence[:match_position], qscore[:match_position]
3
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
75 for motif in adaptmotives[1:]:
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
76 match_position = sequence.rfind(motif)
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
77 if match_position != -1:
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
78 return sequence[:match_position], qscore[:match_position]
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
79 return sequence, qscore
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
80 else:
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
81 if match_position != -1:
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
82 return sequence[:match_position]
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
83 for motif in adaptmotives[1:]:
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
84 match_position = sequence.rfind(motif)
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
85 if match_position != -1:
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
86 return sequence[:match_position]
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
87 return sequence
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
88
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
89 def write_output(self, id, read, qscore, output):
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
90 if self.output_format == "fasta":
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
91 block = ">{0}\n{1}\n".format(id, read)
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
92 else:
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
93 block = "@HWI-{0}\n{1}\n+\n{2}\n".format(id, read, qscore)
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
94 output.write(block)
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
95
3
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
96 def fasta_in_write_output(self, id, read, output):
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
97 output.write(">{0}\n{1}\n".format(id, read))
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
98
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
99 def handle_io_fastq(self):
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
100 '''Open input fastq file, pass read sequence and read qscore to
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
101 scanadapt function. Pass clipped read and qscore to output function.'''
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
102 id = 0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
103 output = open(self.outputfile, "a")
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
104 with open(self.inputfile, "r") as input:
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
105 block_gen = islice(input, 1, None, 2)
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
106 for i, line in enumerate(block_gen):
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
107 if i % 2:
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
108 qscore = line.rstrip()
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
109 else:
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
110 read = line.rstrip()
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
111 continue
4
f7947c5a18b8 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 48768de9d682fb80c4981cd52ef724fdf8f6961e
artbio
parents: 3
diff changeset
112 try:
f7947c5a18b8 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 48768de9d682fb80c4981cd52ef724fdf8f6961e
artbio
parents: 3
diff changeset
113 trimmed_read, trimmed_qscore = self.scanadapt(
f7947c5a18b8 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 48768de9d682fb80c4981cd52ef724fdf8f6961e
artbio
parents: 3
diff changeset
114 self.adaptmotifs, read, qscore)
f7947c5a18b8 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 48768de9d682fb80c4981cd52ef724fdf8f6961e
artbio
parents: 3
diff changeset
115 except ValueError:
f7947c5a18b8 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 48768de9d682fb80c4981cd52ef724fdf8f6961e
artbio
parents: 3
diff changeset
116 continue
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
117 if self.minsize <= len(trimmed_read) <= self.maxsize:
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
118 if (self.Nmode == "reject") and ("N" in trimmed_read):
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
119 continue
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
120 id += 1
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
121 self.write_output(id, trimmed_read, trimmed_qscore, output)
3
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
122 output.close()
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
123
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
124 def handle_io_fasta(self):
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
125 '''Open input fasta file, pass header and read sequence to scanadapt
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
126 function. Pass clipped read and qscore to output function.'''
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
127 id = 0
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
128 output = open(self.outputfile, "a")
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
129 with open(self.inputfile, "r") as input:
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
130 block_gen = islice(input, 1, None, 2)
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
131 for i, line in enumerate(block_gen):
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
132 read = line.rstrip()
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
133 trimmed_read = self.scanadapt(self.adaptmotifs, read)
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
134 if self.minsize <= len(trimmed_read) <= self.maxsize:
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
135 if (self.Nmode == "reject") and ("N" in trimmed_read):
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
136 continue
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
137 id += 1
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
138 self.fasta_in_write_output(id, trimmed_read, output)
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
139 output.close()
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
140
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
141
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
142 def main(*argv):
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
143 instanceClip = Clip(*argv)
3
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
144 if instanceClip.inputformat == "fasta":
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
145 instanceClip.handle_io_fasta()
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
146 else:
94d67b195acd planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 6884c90d521932ae0981532929db9f5f44c8b4a2
artbio
parents: 2
diff changeset
147 instanceClip.handle_io_fastq()
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
148
1
7c913274e22a planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit 7edb6f8c9744ec9bccee42aecf80207f0984330c
artbio
parents: 0
diff changeset
149
0
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
150 if __name__ == "__main__":
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
151 args = Parser()
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
152 for inputfile in args.input:
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
153 main(inputfile, args.output, args.output_format,
ad6b978daa2e planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/yac_clipper commit e9cf2978954c546bb90eb11931f9cfd6562156f3
artbio
parents:
diff changeset
154 args.adapter_to_clip, args.min, args.max, args.Nmode)