annotate translate_bed_sequences.py @ 0:d723eb657f1d draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
author galaxyp
date Mon, 25 Jan 2016 12:21:21 -0500
parents
children 4221664a2bd0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
1 #!/usr/bin/env python
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
2 """
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
3 #
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
4 #------------------------------------------------------------------------------
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
5 # University of Minnesota
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
6 # Copyright 2014, Regents of the University of Minnesota
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
7 #------------------------------------------------------------------------------
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
8 # Author:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
9 #
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
10 # James E Johnson
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
11 #
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
12 #------------------------------------------------------------------------------
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
13 """
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
14
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
15 """
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
16 Input: BED file (12 column) + 13th sequence column appended by extract_genomic_dna
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
17 Output: Fasta of 3-frame translations of the spliced sequence
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
18
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
19 """
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
20
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
21 import sys,re,os.path
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
22 import tempfile
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
23 import optparse
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
24 from optparse import OptionParser
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
25 from Bio.Seq import reverse_complement, transcribe, back_transcribe, translate
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
26
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
27 class BedEntry( object ):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
28 def __init__(self, line):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
29 self.line = line
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
30 try:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
31 fields = line.rstrip('\r\n').split('\t')
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
32 (chrom,chromStart,chromEnd,name,score,strand,thickStart,thickEnd,itemRgb,blockCount,blockSizes,blockStarts) = fields[0:12]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
33 seq = fields[12] if len(fields) > 12 else None
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
34 self.chrom = chrom
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
35 self.chromStart = int(chromStart)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
36 self.chromEnd = int(chromEnd)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
37 self.name = name
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
38 self.score = int(score)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
39 self.strand = strand
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
40 self.thickStart = int(thickStart)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
41 self.thickEnd = int(thickEnd)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
42 self.itemRgb = itemRgb
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
43 self.blockCount = int(blockCount)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
44 self.blockSizes = [int(x) for x in blockSizes.split(',')]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
45 self.blockStarts = [int(x) for x in blockStarts.split(',')]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
46 self.seq = seq
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
47 except Exception, e:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
48 print >> sys.stderr, "Unable to read Bed entry" % e
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
49 exit(1)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
50 def __str__(self):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
51 return '%s\t%d\t%d\t%s\t%d\t%s\t%d\t%d\t%s\t%d\t%s\t%s%s' % (
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
52 self.chrom, self.chromStart, self.chromEnd, self.name, self.score, self.strand, self.thickStart, self.thickEnd, self.itemRgb, self.blockCount,
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
53 ','.join([str(x) for x in self.blockSizes]),
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
54 ','.join([str(x) for x in self.blockStarts]),
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
55 '\t%s' % self.seq if self.seq else '')
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
56 def get_splice_junctions(self):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
57 splice_juncs = []
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
58 for i in range(self.blockCount - 1):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
59 splice_junc = "%s:%d_%d" % (self.chrom, self.chromStart + self.blockSizes[i], self.chromStart + self.blockStarts[i+1])
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
60 splice_juncs.append(splice_junc)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
61 return splice_juncs
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
62 def get_exon_seqs(self):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
63 exons = []
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
64 for i in range(self.blockCount):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
65 # splice_junc = "%s:%d_%d" % (self.chrom, self.chromStart + self.blockSizes[i], self.chromStart + self.blockStarts[i+1])
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
66 exons.append(self.seq[self.blockStarts[i]:self.blockStarts[i] + self.blockSizes[i]])
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
67 if self.strand == '-': #reverse complement
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
68 exons.reverse()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
69 for i,s in enumerate(exons):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
70 exons[i] = reverse_complement(s)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
71 return exons
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
72 def get_spliced_seq(self):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
73 seq = ''.join(self.get_exon_seqs())
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
74 return seq
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
75 def get_translation(self,sequence=None):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
76 translation = None
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
77 seq = sequence if sequence else self.get_spliced_seq()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
78 if seq:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
79 seqlen = len(seq) / 3 * 3;
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
80 if seqlen >= 3:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
81 translation = translate(seq[:seqlen])
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
82 return translation
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
83 def get_translations(self):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
84 translations = []
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
85 seq = self.get_spliced_seq()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
86 if seq:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
87 for i in range(3):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
88 translation = self.get_translation(sequence=seq[i:])
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
89 if translation:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
90 translations.append(translation)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
91 return translations
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
92 ## (start,end)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
93 def get_subrange(self,tstart,tstop):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
94 chromStart = self.chromStart
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
95 chromEnd = self.chromEnd
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
96 r = range(self.blockCount)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
97 if self.strand == '-':
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
98 r.reverse()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
99 bStart = 0
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
100 for x in r:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
101 bEnd = bStart + self.blockSizes[x]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
102 if bStart <= tstart < bEnd:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
103 if self.strand == '+':
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
104 chromStart = self.chromStart + self.blockStarts[x] + (tstart - bStart)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
105 else:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
106 chromEnd = self.chromStart + self.blockStarts[x] + (tstart - bStart)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
107 if bStart <= tstop < bEnd:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
108 if self.strand == '+':
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
109 chromEnd = self.chromStart + self.blockStarts[x] + (tstop - bStart)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
110 else:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
111 chromStart = self.chromStart + self.blockStarts[x] + self.blockSizes[x] - (tstop - bStart)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
112 bStart += self.blockSizes[x]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
113 return(chromStart,chromEnd)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
114 #get the blocks for sub range
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
115 def get_blocks(self,chromStart,chromEnd):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
116 tblockCount = 0
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
117 tblockSizes = []
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
118 tblockStarts = []
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
119 for x in range(self.blockCount):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
120 bStart = self.chromStart + self.blockStarts[x]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
121 bEnd = bStart + self.blockSizes[x]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
122 if bStart > chromEnd:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
123 break
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
124 if bEnd < chromStart:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
125 continue
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
126 cStart = max(chromStart,bStart)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
127 tblockStarts.append(cStart - chromStart)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
128 tblockSizes.append(min(chromEnd,bEnd) - cStart)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
129 tblockCount += 1
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
130 ## print >> sys.stderr, "tblockCount: %d tblockStarts: %s tblockSizes: %s" % (tblockCount,tblockStarts,tblockSizes)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
131 return (tblockCount,tblockSizes,tblockStarts)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
132 ## [(start,end,seq,blockCount,blockSizes,blockStarts),(start,end,seq,blockCount,blockSizes,blockStarts),(start,end,seq,blockCount,blockSizes,blockStarts)]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
133 ## filter: ignore translation if stop codon in first exon after ignore_left_bp
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
134 def get_filterd_translations(self,untrimmed=False,filtering=True,ignore_left_bp=0,ignore_right_bp=0,debug=False):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
135 translations = [None,None,None,None,None,None]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
136 seq = self.get_spliced_seq()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
137 ignore = (ignore_left_bp if self.strand == '+' else ignore_right_bp) / 3
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
138 block_sum = sum(self.blockSizes)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
139 exon_sizes = [x for x in self.blockSizes]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
140 if self.strand == '-':
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
141 exon_sizes.reverse()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
142 splice_sites = [sum(exon_sizes[:x]) / 3 for x in range(1,len(exon_sizes))]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
143 if debug:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
144 print >> sys.stderr, "splice_sites: %s" % splice_sites
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
145 junc = splice_sites[0] if len(splice_sites) > 0 else exon_sizes[0]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
146 if seq:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
147 for i in range(3):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
148 translation = self.get_translation(sequence=seq[i:])
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
149 if translation:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
150 tstart = 0
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
151 tstop = len(translation)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
152 offset = (block_sum - i) % 3
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
153 if debug:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
154 print >> sys.stderr, "frame: %d\ttstart: %d tstop: %d offset: %d\t%s" % (i,tstart,tstop,offset,translation)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
155 if not untrimmed:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
156 tstart = translation.rfind('*',0,junc) + 1
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
157 stop = translation.find('*',junc)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
158 tstop = stop if stop >= 0 else len(translation)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
159 offset = (block_sum - i) % 3
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
160 trimmed = translation[tstart:tstop]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
161 if debug:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
162 print >> sys.stderr, "frame: %d\ttstart: %d tstop: %d offset: %d\t%s" % (i,tstart,tstop,offset,trimmed)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
163 if filtering and tstart > ignore:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
164 continue
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
165 #get genomic locations for start and end
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
166 if self.strand == '+':
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
167 chromStart = self.chromStart + i + (tstart * 3)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
168 chromEnd = self.chromEnd - offset - (len(translation) - tstop) * 3
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
169 else:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
170 chromStart = self.chromStart + offset + (len(translation) - tstop) * 3
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
171 chromEnd = self.chromEnd - i - (tstart * 3)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
172 #get the blocks for this translation
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
173 (tblockCount,tblockSizes,tblockStarts) = self.get_blocks(chromStart,chromEnd)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
174 translations[i] = (chromStart,chromEnd,trimmed,tblockCount,tblockSizes,tblockStarts)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
175 if debug:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
176 print >> sys.stderr, "tblockCount: %d tblockStarts: %s tblockSizes: %s" % (tblockCount,tblockStarts,tblockSizes)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
177 # translations[i] = (chromStart,chromEnd,trimmed,tblockCount,tblockSizes,tblockStarts)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
178 return translations
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
179 def get_seq_id(self,seqtype='unk:unk',reference='',frame=None):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
180 ## Ensembl fasta ID format
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
181 # >ID SEQTYPE:STATUS LOCATION GENE TRANSCRIPT
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
182 # >ENSP00000328693 pep:splice chromosome:NCBI35:1:904515:910768:1 gene:ENSG00000158815:transcript:ENST00000328693 gene_biotype:protein_coding transcript_biotype:protein_coding
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
183 frame_name = ''
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
184 chromStart = self.chromStart
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
185 chromEnd = self.chromEnd
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
186 strand = 1 if self.strand == '+' else -1
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
187 if frame != None:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
188 block_sum = sum(self.blockSizes)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
189 offset = (block_sum - frame) % 3
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
190 frame_name = '_' + str(frame + 1)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
191 if self.strand == '+':
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
192 chromStart += frame
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
193 chromEnd -= offset
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
194 else:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
195 chromStart += offset
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
196 chromEnd -= frame
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
197 location = "chromosome:%s:%s:%s:%s:%s" % (reference,self.chrom,chromStart,chromEnd,strand)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
198 seq_id = "%s%s %s %s" % (self.name,frame_name,seqtype,location)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
199 return seq_id
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
200 def get_line(self, start_offset = 0, end_offset = 0):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
201 if start_offset or end_offset:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
202 s_offset = start_offset if start_offset else 0
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
203 e_offset = end_offset if end_offset else 0
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
204 if s_offset > self.chromStart:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
205 s_offset = self.chromStart
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
206 chrStart = self.chromStart - s_offset
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
207 chrEnd = self.chromEnd + e_offset
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
208 blkSizes = self.blockSizes
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
209 blkSizes[0] += s_offset
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
210 blkSizes[-1] += e_offset
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
211 blkStarts = self.blockStarts
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
212 for i in range(1,self.blockCount):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
213 blkStarts[i] += s_offset
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
214 items = [str(x) for x in [self.chrom,chrStart,chrEnd,self.name,self.score,self.strand,self.thickStart,self.thickEnd,self.itemRgb,self.blockCount,','.join([str(x) for x in blkSizes]),','.join([str(x) for x in blkStarts])]]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
215 return '\t'.join(items) + '\n'
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
216 return self.line
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
217
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
218 def __main__():
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
219 #Parse Command Line
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
220 parser = optparse.OptionParser()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
221 parser.add_option( '-i', '--input', dest='input', help='BED file (tophat junctions.bed) with sequence column added' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
222 parser.add_option( '-o', '--output', dest='output', help='Translations of spliced sequence')
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
223 parser.add_option( '-b', '--bed_format', dest='bed_format', action='store_true', default=False, help='Append translations to bed file instead of fasta' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
224 parser.add_option( '-D', '--fa_db', dest='fa_db', default=None, help='Prefix DB identifier for fasta ID line, e.g. generic' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
225 parser.add_option( '-s', '--fa_sep', dest='fa_sep', default='|', help='fasta ID separator defaults to pipe char, e.g. generic|ProtID|description' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
226 parser.add_option( '-B', '--bed', dest='bed', default=None, help='Output a bed file with added 13th column having translation' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
227 parser.add_option( '-G', '--gff3', dest='gff', default=None, help='Output translations to a GFF3 file' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
228 parser.add_option( '-S', '--seqtype', dest='seqtype', default='pep:splice', help='SEQTYPE:STATUS for fasta ID line' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
229 parser.add_option( '-P', '--id_prefix', dest='id_prefix', default='', help='prefix for the sequence ID' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
230 parser.add_option( '-R', '--reference', dest='reference', default=None, help='Genome Reference Name for fasta ID location ' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
231 parser.add_option( '-r', '--refsource', dest='refsource', default=None, help='Source for Genome Reference, e.g. Ensembl, UCSC, or NCBI' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
232 parser.add_option( '-Q', '--score_name', dest='score_name', default=None, help='include in the fasta ID line score_name:score ' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
233 parser.add_option( '-l', '--leading_bp', dest='leading_bp', type='int', default=None, help='leading number of base pairs to ignore when filtering' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
234 parser.add_option( '-t', '--trailing_bp', dest='trailing_bp', type='int', default=None, help='trailing number of base pairs to ignore when filtering' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
235 parser.add_option( '-U', '--unfiltered', dest='filtering', action='store_false', default=True, help='Do NOT filterout translation with stop codon in the first exon' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
236 parser.add_option( '-u', '--untrimmed', dest='untrimmed', action='store_true', default=False, help='Do NOT trim from splice site to stop codon' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
237 parser.add_option( '-L', '--min_length', dest='min_length', type='int', default=None, help='Minimun length (to first stop codon)' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
238 parser.add_option( '-M', '--max_stop_codons', dest='max_stop_codons', type='int', default=None, help='Filter out translations with more than max_stop_codons' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
239 parser.add_option( '-d', '--debug', dest='debug', action='store_true', default=False, help='Turn on wrapper debugging to stdout' )
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
240 (options, args) = parser.parse_args()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
241 # Input files
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
242 if options.input != None:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
243 try:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
244 inputPath = os.path.abspath(options.input)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
245 inputFile = open(inputPath, 'r')
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
246 except Exception, e:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
247 print >> sys.stderr, "failed: %s" % e
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
248 exit(2)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
249 else:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
250 inputFile = sys.stdin
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
251 # Output files
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
252 bed_fh = None
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
253 gff_fh = None
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
254 gff_fa_file = None
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
255 gff_fa = None
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
256 outFile = None
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
257 if options.output == None:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
258 #write to stdout
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
259 outFile = sys.stdout
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
260 if options.gff:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
261 gff_fa_file = tempfile.NamedTemporaryFile(prefix='gff_fasta_',suffix=".fa",dir=os.getcwd()).name
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
262 gff_fa = open(gff_fa_file,'w')
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
263 else:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
264 try:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
265 outPath = os.path.abspath(options.output)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
266 outFile = open(outPath, 'w')
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
267 except Exception, e:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
268 print >> sys.stderr, "failed: %s" % e
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
269 exit(3)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
270 if options.gff:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
271 gff_fa_file = outPath
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
272 if options.bed:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
273 bed_fh = open(options.bed,'w')
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
274 bed_fh.write('track name="%s" description="%s" \n' % ('novel_junctioni_translations','test'))
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
275 if options.gff:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
276 gff_fh = open(options.gff,'w')
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
277 gff_fh.write("##gff-version 3.2.1\n")
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
278 if options.reference:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
279 gff_fh.write("##genome-build %s %s\n" % (options.refsource if options.refsource else 'unknown', options.reference))
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
280 leading_bp = 0
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
281 trailing_bp = 0
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
282 if options.leading_bp:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
283 if options.leading_bp >= 0:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
284 leading_bp = options.leading_bp
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
285 else:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
286 print >> sys.stderr, "failed: leading_bp must be positive"
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
287 exit(5)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
288 if options.trailing_bp:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
289 if options.trailing_bp >= 0:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
290 trailing_bp = options.trailing_bp
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
291 else:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
292 print >> sys.stderr, "failed: trailing_bp must be positive"
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
293 exit(5)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
294 # Scan bed file
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
295 try:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
296 for i, line in enumerate( inputFile ):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
297 if line.startswith('track'):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
298 if outFile and options.bed_format:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
299 outFile.write(line)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
300 continue
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
301 entry = BedEntry(line)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
302 strand = 1 if entry.strand == '+' else -1
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
303 translations = entry.get_translations()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
304 if options.debug:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
305 exon_seqs = entry.get_exon_seqs()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
306 exon_sizes = [len(seq) for seq in exon_seqs]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
307 splice_sites = [sum(exon_sizes[:x]) / 3 for x in range(1,len(exon_sizes))]
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
308 print >> sys.stderr, entry.name
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
309 print >> sys.stderr, line.rstrip('\r\n')
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
310 print >> sys.stderr, "exons: %s" % exon_seqs
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
311 print >> sys.stderr, "%s" % splice_sites
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
312 for i,translation in enumerate(translations):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
313 print >> sys.stderr, "frame %d: %s" % (i+1,translation)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
314 print >> sys.stderr, "splice: %s" % (''.join(['^' if (((j*3)+i)/3) in splice_sites else '-' for j in range(len(translation))]))
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
315 print >> sys.stderr, ""
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
316 if options.bed_format:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
317 tx_entry = "%s\t%s\n" % (line.rstrip('\r\n'),'\t'.join(translations))
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
318 outFile.write(tx_entry)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
319 else:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
320 translations = entry.get_filterd_translations(untrimmed=options.untrimmed,filtering=options.filtering,ignore_left_bp=leading_bp,ignore_right_bp=trailing_bp,debug=options.debug)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
321 for i,tx in enumerate(translations):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
322 if tx:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
323 (chromStart,chromEnd,translation,blockCount,blockSizes,blockStarts) = tx
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
324 if options.min_length != None and len(translation) < options.min_length:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
325 continue
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
326 if options.max_stop_codons != None and translation.count('*') > options.max_stop_codons:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
327 continue
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
328 frame_name = '_%s' % (i + 1)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
329 pep_id = "%s%s%s" % (options.id_prefix,entry.name,frame_name)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
330 if bed_fh:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
331 bed_fh.write('%s\t%d\t%d\t%s\t%d\t%s\t%d\t%d\t%s\t%d\t%s\t%s\t%s\n' % (str(entry.chrom),chromStart,chromEnd,pep_id,entry.score,entry.strand,chromStart,chromEnd,entry.itemRgb,blockCount,','.join([str(x) for x in blockSizes]),','.join([str(x) for x in blockStarts]),translation))
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
332 location = "chromosome:%s:%s:%s:%s:%s" % (options.reference,entry.chrom,chromStart,chromEnd,strand)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
333 score = " %s:%s" % (options.score_name,entry.score) if options.score_name else ''
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
334 seq_description = "%s %s%s" % (options.seqtype, location, score)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
335 seq_id = "%s " % pep_id
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
336 if options.fa_db:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
337 seq_id = "%s%s%s%s" % (options.fa_db,options.fa_sep,pep_id,options.fa_sep)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
338 fa_id = "%s%s" % (seq_id,seq_description)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
339 fa_entry = ">%s\n%s\n" % (fa_id,translation)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
340 outFile.write(fa_entry)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
341 if gff_fh:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
342 if gff_fa:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
343 gff_fa.write(fa_entry)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
344 gff_fh.write("##sequence-region %s %d %d\n" % (entry.chrom,chromStart + 1,chromEnd - 1))
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
345 gff_fh.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\tID=%s\n" % (entry.chrom,'splice_junc','gene',chromStart + 1,chromEnd - 1,entry.score,entry.strand,0,pep_id))
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
346 for x in range(blockCount):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
347 start = chromStart+blockStarts[x] + 1
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
348 end = start + blockSizes[x] - 1
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
349 phase = (3 - sum(blockSizes[:x]) % 3) % 3
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
350 gff_fh.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\tParent=%s;ID=%s_%d\n" % (entry.chrom,'splice_junc','CDS',start,end,entry.score,entry.strand,phase,pep_id,pep_id,x))
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
351 """
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
352 ##gff-version 3
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
353 ##sequence-region 19 1 287484
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
354 19 MassSpec peptide 282299 287484 10.0 - 0 ID=TEARLSFYSGHSSFGMYCMVFLALYVQ
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
355 19 MassSpec CDS 287474 287484 . - 0 Parent=TEARLSFYSGHSSFGMYCMVFLALYVQ;transcript_id=ENST00000269812
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
356 19 MassSpec CDS 282752 282809 . - 1 Parent=TEARLSFYSGHSSFGMYCMVFLALYVQ;transcript_id=ENST00000269812
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
357 19 MassSpec CDS 282299 282310 . - 0 Parent=TEARLSFYSGHSSFGMYCMVFLALYVQ;transcript_id=ENST00000269812
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
358 """
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
359 if bed_fh:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
360 bed_fh.close()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
361 if gff_fh:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
362 if gff_fa:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
363 gff_fa.close()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
364 else:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
365 outFile.close()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
366 gff_fa = open(gff_fa_file,'r')
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
367 gff_fh.write("##FASTA\n")
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
368 for i, line in enumerate(gff_fa):
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
369 gff_fh.write(line)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
370 gff_fh.close()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
371 except Exception, e:
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
372 print >> sys.stderr, "failed: Error reading %s - %s" % (options.input if options.input else 'stdin',e)
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
373
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
374 if __name__ == "__main__" : __main__()
d723eb657f1d planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/translate_bed_sequences commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
375