annotate GFFalign.py @ 0:294f5ba28746 draft

"planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
author abims-sbr
date Mon, 30 Nov 2020 18:20:46 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
1 #!/usr/bin/python3
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
2
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
3 import argparse
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
4 import os
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
5 import gffutils
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
6 from Bio import SeqIO
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
7
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
8
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
9 class GeneComp:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
10 # This cass aims to discover the position of the genes in the alignment
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
11 # and to extract informations on the genes characteristics
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
12
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
13 def __init__(self, ccgene, qstart, qend, otgene, dstart, dend, extract, tol, gattr, output=None):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
14 # d* / ot* are the db result, q* / cc the query
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
15 # gene are the gene from maf-tab file
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
16 # start, end are the coordinates '''
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
17 self.otbeg = int(otgene.start) - dstart
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
18 self.otend = int(otgene.end) - dstart
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
19 self.ccbeg = int(ccgene.start) - qstart
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
20 self.ccend = int(ccgene.end) - qstart
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
21 self.tol = tol # how much tolerance in nucleotides
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
22 self.ccname = ccgene.chrom
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
23 self.otname = otgene.chrom
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
24 self.q_outstart = qstart+self.otbeg
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
25 self.q_outend = qstart+self.otend
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
26 self.genelist = []
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
27 self.qstart = qstart
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
28 if extract:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
29 self.fastafile = extract[0]
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
30 self.fastaout = extract[1]
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
31 self.output = output
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
32 self.out = ""
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
33 self.gattr = f"New_annotation='{gattr}'"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
34
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
35 def is_equal(self):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
36 if (self.otbeg - self.tol) <= self.ccbeg <= (self.otbeg + self.tol) and (self.otend - self.tol) <= self.ccend <= (self.otend + self.tol):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
37 self.out = f"{self.ccname}\tprediction\tgene\t{self.q_outstart}\t{self.q_outend}\t.\t{self.qstart}\t.\tID={self.ccname};{self.gattr};Note=confirmed"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
38 return self.out
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
39
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
40 def is_shorter(self):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
41 if (self.otbeg + self.tol) < self.ccbeg and (self.otend - self.tol) > self.ccend:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
42 self.out = f"{self.ccname}\tprediction\tgene\t{self.q_outstart}\t{self.q_outend}\t.\t{self.qstart}\t.\tID={self.ccname};{self.gattr};Note=shorter"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
43 return self.out
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
44 elif (self.otbeg - self.tol) <= self.ccbeg <= (self.otbeg + self.tol) and (self.otend - self.tol) > self.ccend:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
45 self.out = f"{self.ccname}\tprediction\tgene\t{self.q_outstart}\t{self.q_outend}\t.\t{self.qstart}\t.\tID={self.ccname};{self.gattr};Note=shorter_right"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
46 return self.out
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
47 elif (self.otbeg + self.tol) < self.ccbeg and (self.otend - self.tol) <= self.ccend <= (self.otend + self.tol):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
48 self.out = f"{self.ccname}\tprediction\tgene\t{self.q_outstart}\t{self.q_outend}\t.\t{self.qstart}\t.\tID={self.ccname};{self.gattr};Note=shorter_left"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
49 return self.out
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
50
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
51 def is_longer(self):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
52 if (self.otbeg - self.tol) > self.ccbeg and (self.otend + self.tol) < self.ccend:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
53 self.out = f"{self.ccname}\tprediction\tgene\t{self.q_outstart}\t{self.q_outend}\t.\t{self.qstart}\t.\tID={self.ccname};{self.gattr};Note=longer"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
54 return self.out
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
55 elif (self.otbeg - self.tol) <= self.ccbeg <= (self.otbeg + self.tol) and (self.otend + self.tol) < self.ccend:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
56 self.out = f"{self.ccname}\tprediction\tgene\t{self.q_outstart}\t{self.q_outend}\t.\t{self.qstart}\t.\tID={self.ccname};{self.gattr};Note=longer_right"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
57 return self.out
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
58 elif (self.otbeg - self.tol) > self.ccbeg and (self.otend - self.tol) <= self.ccend <= (self.otend + self.tol):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
59 self.out = f"{self.ccname}\tprediction\tgene\t{self.q_outstart}\t{self.q_outend}\t.\t{self.qstart}\t.\tID={self.ccname};{self.gattr};Note=longer_left"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
60 return self.out
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
61
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
62 def is_offset(self):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
63 if (self.otbeg + self.tol) < self.ccbeg < (self.otend - self.tol) and (self.otend + self.tol) < self.ccend:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
64 self.out = f"{self.ccname}\tprediction\tgene\t{self.q_outstart}\t{self.q_outend}\t.\t{self.qstart}\t.\tID={self.ccname};{self.gattr};Note=offset_right"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
65 return self.out
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
66 if (self.otbeg - self.tol) > self.ccbeg and (self.otbeg - self.tol) < self.ccend < self.otend + self.tol:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
67 self.out = f"{self.ccname}\tprediction\tgene\t{self.q_outstart}\t{self.q_outend}\t.\t{self.qstart}\t.\tID={self.ccname};{self.gattr};Note=offset_left"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
68 return self.out
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
69
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
70 def is_different(self):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
71 if self.otbeg - self.tol > self.ccend or self.otend + self.tol < self.otbeg:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
72 self.out = f"{self.ccname}\tprediction\tgene\t{self.q_outstart}\t{self.q_outend}\t.\t{self.qstart}\t.\tID={self.ccname};{self.gattr};Note=new"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
73 return self.out
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
74
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
75 def extract_fasta(self):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
76 with open(self.fastaout,"a") as fileout:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
77 with open(self.fastafile) as filefasta:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
78 for record in SeqIO.parse(filefasta,"fasta"):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
79 if record.id == self.ccname:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
80 fileout.write(f">{self.ccname}_{self.q_outstart}:{self.q_outend}\n{record.seq[self.q_outstart:self.q_outend]}\n")
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
81
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
82 # def extract_stout(self):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
83 # with open(self.fastafile) as filefasta:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
84 # for record in SeqIO.parse(filefasta,"fasta"):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
85 # if record.id == self.ccname:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
86 # print(f">{self.ccname}_{self.q_outstart}:{self.q_outend}\n{record.seq[self.q_outstart:self.q_outend]}")
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
87
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
88
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
89 #def __str__(self):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
90 # return f"{self.ccname}\t{self.q_outstart}\t{self.q_outend}"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
91
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
92
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
93 def fout(self):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
94 try:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
95 if self.__class__.fout.called:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
96 with open(self.output,"a") as fileout:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
97 fileout.write(self.out+"\n")
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
98 except AttributeError:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
99 try:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
100 if os.path.isfile(self.output):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
101 os.remove(self.output)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
102 with open(self.output,"a") as fileout:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
103 #fileout.write("##gff-version 3\n")
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
104 fileout.write(f"##gff-version 3\n{self.out}\n")
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
105 self.__class__.fout.called = True
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
106 self.__class__.fout(self)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
107 except TypeError:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
108 pass
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
109
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
110
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
111 def diff_gene(query_genes, target_genes, dstart, dend, qstart, qend, query_db):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
112 # are the two genes the same?
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
113 if args.extract:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
114 extract = args.extract
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
115 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
116 extract = None
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
117
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
118 if args.tollerance:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
119 tol = args.tollerance
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
120 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
121 tol = 30
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
122
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
123
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
124 for otgene in target_genes:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
125 # gattr is a variable created to store the the annotation of the target gene.
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
126 # It will be use to suggest a functional annotation
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
127 gattr = str(otgene).split("\t")[-1]
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
128 for ccgene in query_genes:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
129 algene = GeneComp(ccgene, qstart, qend, otgene, dstart, dend, extract, tol, gattr)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
130 if "new" in args.verbosity or "all" in args.verbosity:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
131 if algene.is_different():
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
132 algene_out = algene.is_different()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
133 algene_name = algene_out.split("\t")[0]
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
134 algene_start = int(algene_out.split("\t")[3])
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
135 algene_end = int(algene_out.split("\t")[4])
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
136 #print(al_name, al_start, al_end)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
137 #print(list(target_db.region(region=(al_name, al_start, al_end), completely_within=True)))
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
138 if not list(query_db.region(region=(algene_name, algene_start, algene_end), completely_within=False)):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
139 if args.output:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
140 algene.output=args.output
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
141 algene.fout()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
142 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
143 print(algene.is_different())
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
144 if args.extract:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
145 algene.extract_fasta()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
146
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
147 if "shorter" in args.verbosity or "all" in args.verbosity:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
148 if algene.is_shorter():
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
149 if args.output:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
150 algene.output=args.output
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
151 algene.fout()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
152 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
153 print(algene.is_shorter())
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
154 if args.extract:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
155 algene.extract_fasta()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
156 if "longer" in args.verbosity or "all" in args.verbosity:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
157 if algene.is_longer():
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
158 if args.output:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
159 algene.output=args.output
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
160 algene.fout()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
161 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
162 print(algene.is_longer())
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
163 if args.extract:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
164 algene.extract_fasta()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
165 if "offset" in args.verbosity or "all" in args.verbosity:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
166 if algene.is_offset():
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
167 if args.output:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
168 algene.output=args.output
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
169 algene.fout()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
170 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
171 print(algene.is_offset())
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
172 if args.extract:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
173 algene.extract_fasta()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
174 if "confirmed" in args.verbosity:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
175 if algene.is_equal():
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
176 if args.output:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
177 algene.output=args.output
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
178 algene.fout()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
179 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
180 print(algene.is_equal())
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
181 if args.extract:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
182 algene.extract_fasta()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
183
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
184
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
185 def gff_gene_check(GffName, db_name, memory=0):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
186 # The IDs on the GFFs must be unique. Moreover, because only the gene
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
187 # information are needed, all the other information must be removed
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
188 # from the GFFs.
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
189 tempgff=""
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
190 for line in open(GffName):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
191 if line[0] != "#":
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
192 if line.split()[2] == "gene":
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
193 tempgff+=line
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
194
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
195 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
196 tempgff+=line
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
197
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
198 if memory:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
199 # Write the db in memory and return it as variable so it can be used
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
200 # as subclass of _DBCreator
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
201 dbout = gffutils.create_db(tempgff, ":memory:", from_string=True)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
202 return dbout
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
203 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
204 gffutils.create_db(tempgff, db_name, from_string=True)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
205
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
206 def check_strand(start,leng,strand):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
207 if strand == "+":
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
208 end = start+leng
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
209 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
210 end = start-leng
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
211 start,end = end,start
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
212 return(start,end)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
213
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
214 def check_position(line, query_db,target_db):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
215 # check if there is a gene in the aligned area
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
216 # lets' start with the coordinatescharacteristics
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
217 elsp = line.split('\t')
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
218 dname = elsp[1]
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
219 dstart = int(elsp[2])
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
220 dlen = int(elsp[3])
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
221 dstrand = elsp[4]
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
222 qname = elsp[6]
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
223 qstart = int(elsp[7])
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
224 qlen = int(elsp[8])
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
225 qstrand = elsp[9]
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
226
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
227 # check the strand, if - reverse the start and the end
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
228 qstart,qend = check_strand(qstart,qlen,qstrand)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
229 dstart,dend = check_strand(dstart,dlen,dstrand)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
230
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
231 #counter
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
232 d_counter = 0
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
233
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
234 # lists of gene within the coordinates
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
235 target_genes = [ gene for gene in list(target_db.region(region=(dname, dstart, dend), completely_within=True))]
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
236 query_genes = [ gene for gene in list(query_db.region(region=(qname, qstart, qend), completely_within=True))]
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
237
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
238 if len(target_genes):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
239 # and len(query_genes):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
240 ######
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
241 # PER PROVARE HO TOLTO QUESTO, DA CONTROLLARE
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
242 ######
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
243 #if len(target_genes) >= len(query_genes): # the number of genes in the aligned area must be bigger in the target (?)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
244 diff_gene(query_genes, target_genes, dstart, dend, qstart, qend, query_db)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
245
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
246
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
247 if d_counter>=1:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
248 return(d_counter)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
249 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
250 return(0)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
251
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
252
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
253 def main(args):
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
254 fcounter = 0
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
255 # import the GFF library and create (has to be done only once)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
256 # the GFF databases
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
257 target_db = query_db = None
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
258 db_query_name=args.queryGff + "_db"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
259 db_target_name=args.targetGff + "_db"
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
260
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
261 if args.force_database:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
262 # remove the database if required by user
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
263 os.remove(db_query_name)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
264 os.remove(db_target_name)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
265
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
266 if args.use_query_database:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
267 # use the db passed by the user
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
268 query_db = gffutils.FeatureDB(args.use_query_database)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
269 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
270 #create the db
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
271 #gffutils.create_db(args.queryGff, db_query_name)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
272 qdbout = gff_gene_check(args.queryGff, db_query_name, args.memory)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
273
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
274 if args.memory:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
275 query_db = gffutils.FeatureDB(qdbout.dbfn)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
276 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
277 query_db = gffutils.FeatureDB(db_query_name)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
278 # except ValueError:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
279 # print("Please check your GFF file")
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
280 # except:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
281 # raise Exception(f"It seems you already have a db called {db_query_name}. Use the -qu if you want to use it or delete the")
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
282
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
283
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
284 if args.use_target_database:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
285 target_db = gffutils.FeatureDB(args.use_target_database)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
286 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
287 tdbout = gff_gene_check(args.targetGff, db_target_name, args.memory)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
288 if args.memory:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
289 target_db = gffutils.FeatureDB(tdbout.dbfn)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
290 else:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
291 target_db = gffutils.FeatureDB(db_target_name)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
292 # except ValueError:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
293 # print("Please check your GFF file")if "all" in args.verbosity:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
294 # except:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
295 # raise Exception(f"It seems you already have a db called {db_target_name}. Use the -du if you want to use it or delete the")
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
296
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
297 # put the content of the DB in objects
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
298 with open(args.aln) as maftab:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
299 for line in maftab:
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
300 if line[0] != "#":
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
301 fcounter += check_position(line, query_db, target_db)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
302
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
303 if __name__ == '__main__':
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
304 parser = argparse.ArgumentParser(description = '''Tool to extract genes coordinates from a whole genome alignent.
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
305 This script needs an alignement in TAB format and two gff files''')
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
306 parser.add_argument('aln', help='alignment file in TAB format. The suggested way to obtain it is to run Last and\
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
307 than convert the file from MAF to TAB with maf-convert')
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
308 parser.add_argument('queryGff',
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
309 help='''Gff file of the query organism. The gene IDs in the GFF must be unique.''')
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
310 parser.add_argument('targetGff',
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
311 help='''Gff file of the "target" organism. The gene IDs in the GFF must be unique.''')
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
312 parser.add_argument("-uq", "--use-query-database",
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
313 help='''Use this parament if you already have a query gffutils formatted database or
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
314 if it\'s not the first time you run this script''', type=str)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
315 parser.add_argument("-ut", "--use-target-database",
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
316 help='''Use this parament if you already have a target gffutils formatted database or
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
317 if it\'s not the first time you run this script''', type=str)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
318 parser.add_argument("-fd", "--force-database", help="delete old gffutils databases and create new ones", action='store_true')
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
319 parser.add_argument("-m", "--memory", help='''create an in-memory database. This option can't be used with the other DB options.
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
320 probably usefull in Galaxy integration''', action='store_true' )
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
321 parser.add_argument("-e", "--extract",
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
322 help='''Extract the fasta sequence of the new suggested gene. It takes two argument: the fasta file
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
323 of the genome and the name of the output file. This will slow down the process A LOT.''', nargs=2, type=str)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
324 #parser.add_argument("-es", "--extract_stout", help='Like -e but it will print the result in the standard output. FASTER than -e. It need the fasta file', type=str)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
325 parser.add_argument("-o", "--output", help='Name of the output file. Default output is stout', type=str)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
326 parser.add_argument("-t", "--tollerance", help='Interval, in nucleotide, within a gene is considered in the same position. Default 30', default=30, type=int)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
327 parser.add_argument("-v", "--verbosity",
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
328 help='''Output options. If not specify the software shows only the genes that are in the exact position of the
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
329 genes in the target. It\'s possible to show annotated genes that are in aligned regions but that have different lengths or in slightly
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
330 different positions. It's possible to select multiple, space separated, values.''',
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
331 choices=["all","shorter", "longer", "offset", "new", "confirmed"], nargs='*', default='new', type=str)
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
332 #metavar=('all','shorter','longer','shifted','new'),
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
333 #action='append',
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
334 #choices=["all","shorter", "longer", "shifted", "new"], default="new")
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
335 parser.add_argument('--version', action='version', version='0.1.0')
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
336 args = parser.parse_args()
294f5ba28746 "planemo upload for repository https://github.com/abims-sbr/tools-abims/tools/gffalign commit d8aa0e49353e78e5fd772498a1fcf591e2744f99"
abims-sbr
parents:
diff changeset
337 main(args)