annotate map_peptides_to_bed.py @ 1:db90662d26f9 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit a2d6625c1d0c65af83ce12614022f30ccd610444-dirty
author galaxyp
date Mon, 22 Feb 2016 17:30:45 -0500
parents 51f8f9041724
children 704ea6303c4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
1 #!/usr/bin/env python
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
2 """
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
3 #
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
4 #------------------------------------------------------------------------------
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
5 # University of Minnesota
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
6 # Copyright 2014, Regents of the University of Minnesota
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
7 #------------------------------------------------------------------------------
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
8 # Author:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
9 #
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
10 # James E Johnson
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
11 #
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
12 #------------------------------------------------------------------------------
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
13 """
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
14
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
15 """
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
16 Input: list of protein_accessions, peptide_sequence
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
17 GFF3 with fasta
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
18 Output: GFF3 of peptides
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
19
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
20 Filter: Must cross splice boundary
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
21
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
22 """
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
23
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
24 import sys,re,os.path
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
25 import tempfile
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
26 import optparse
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
27 from optparse import OptionParser
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
28 from Bio.Seq import reverse_complement, transcribe, back_transcribe, translate
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
29
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
30 class BedEntry( object ):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
31 def __init__(self, line):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
32 self.line = line
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
33 try:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
34 fields = line.rstrip('\r\n').split('\t')
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
35 (chrom,chromStart,chromEnd,name,score,strand,thickStart,thickEnd,itemRgb,blockCount,blockSizes,blockStarts) = fields[0:12]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
36 seq = fields[12] if len(fields) > 12 else None
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
37 self.chrom = chrom
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
38 self.chromStart = int(chromStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
39 self.chromEnd = int(chromEnd)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
40 self.name = name
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
41 self.score = int(score)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
42 self.strand = strand
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
43 self.thickStart = int(thickStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
44 self.thickEnd = int(thickEnd)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
45 self.itemRgb = itemRgb
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
46 self.blockCount = int(blockCount)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
47 self.blockSizes = [int(x) for x in blockSizes.split(',')]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
48 self.blockStarts = [int(x) for x in blockStarts.split(',')]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
49 self.seq = seq
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
50 except Exception, e:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
51 print >> sys.stderr, "Unable to read Bed entry" % e
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
52 exit(1)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
53 def __str__(self):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
54 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' % (
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
55 self.chrom, self.chromStart, self.chromEnd, self.name, self.score, self.strand, self.thickStart, self.thickEnd, self.itemRgb, self.blockCount,
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
56 ','.join([str(x) for x in self.blockSizes]),
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
57 ','.join([str(x) for x in self.blockStarts]),
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
58 '\t%s' % self.seq if self.seq else '')
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
59 def get_splice_junctions(self):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
60 splice_juncs = []
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
61 for i in range(self.blockCount - 1):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
62 splice_junc = "%s:%d_%d" % (self.chrom, self.chromStart + self.blockSizes[i], self.chromStart + self.blockStarts[i+1])
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
63 splice_juncs.append(splice_junc)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
64 return splice_juncs
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
65 def get_exon_seqs(self):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
66 exons = []
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
67 for i in range(self.blockCount):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
68 # splice_junc = "%s:%d_%d" % (self.chrom, self.chromStart + self.blockSizes[i], self.chromStart + self.blockStarts[i+1])
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
69 exons.append(self.seq[self.blockStarts[i]:self.blockStarts[i] + self.blockSizes[i]])
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
70 if self.strand == '-': #reverse complement
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
71 exons.reverse()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
72 for i,s in enumerate(exons):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
73 exons[i] = reverse_complement(s)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
74 return exons
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
75 def get_spliced_seq(self):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
76 seq = ''.join(self.get_exon_seqs())
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
77 return seq
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
78 def get_translation(self,sequence=None):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
79 translation = None
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
80 seq = sequence if sequence else self.get_spliced_seq()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
81 if seq:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
82 seqlen = len(seq) / 3 * 3;
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
83 if seqlen >= 3:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
84 translation = translate(seq[:seqlen])
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
85 return translation
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
86 def get_translations(self):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
87 translations = []
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
88 seq = self.get_spliced_seq()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
89 if seq:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
90 for i in range(3):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
91 translation = self.get_translation(sequence=seq[i:])
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
92 if translation:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
93 translations.append(translation)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
94 return translations
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
95 ## (start,end)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
96 def get_subrange(self,tstart,tstop):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
97 chromStart = self.chromStart
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
98 chromEnd = self.chromEnd
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
99 r = range(self.blockCount)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
100 if self.strand == '-':
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
101 r.reverse()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
102 bStart = 0
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
103 for x in r:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
104 bEnd = bStart + self.blockSizes[x]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
105 ## print >> sys.stderr, "%d chromStart: %d chromEnd: %s bStart: %s bEnd: %d" % (x,chromStart,chromEnd,bStart,bEnd)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
106 if bStart <= tstart < bEnd:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
107 if self.strand == '+':
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
108 chromStart = self.chromStart + self.blockStarts[x] + (tstart - bStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
109 else:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
110 chromEnd = self.chromStart + self.blockStarts[x] + self.blockSizes[x] - (tstart - bStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
111 if bStart <= tstop < bEnd:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
112 if self.strand == '+':
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
113 chromEnd = self.chromStart + self.blockStarts[x] + (tstop - bStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
114 else:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
115 chromStart = self.chromStart + self.blockStarts[x] + self.blockSizes[x] - (tstop - bStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
116 bStart += self.blockSizes[x]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
117 return(chromStart,chromEnd)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
118 #get the blocks for sub range
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
119 def get_blocks(self,chromStart,chromEnd):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
120 tblockCount = 0
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
121 tblockSizes = []
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
122 tblockStarts = []
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
123 for x in range(self.blockCount):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
124 bStart = self.chromStart + self.blockStarts[x]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
125 bEnd = bStart + self.blockSizes[x]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
126 if bStart > chromEnd:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
127 break
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
128 if bEnd < chromStart:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
129 continue
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
130 cStart = max(chromStart,bStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
131 tblockStarts.append(cStart - chromStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
132 tblockSizes.append(min(chromEnd,bEnd) - cStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
133 tblockCount += 1
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
134 print >> sys.stderr, "tblockCount: %d tblockStarts: %s tblockSizes: %s" % (tblockCount,tblockStarts,tblockSizes)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
135 return (tblockCount,tblockSizes,tblockStarts)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
136
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
137 ## [[start,end,seq,blockCount,blockSizes,blockStarts],[start,end,seq,blockCount,blockSizes,blockStarts],[start,end,seq,blockCount,blockSizes,blockStarts]]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
138 ## filter: ignore translation if stop codon in first exon after ignore_left_bp
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
139 def get_filterd_translations(self,untrimmed=False,filtering=True,ignore_left_bp=0,ignore_right_bp=0):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
140 translations = [None,None,None,None,None,None]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
141 seq = self.get_spliced_seq()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
142 ignore = (ignore_left_bp if self.strand == '+' else ignore_right_bp) / 3
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
143 block_sum = sum(self.blockSizes)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
144 exon_sizes = self.blockSizes
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
145 if self.strand == '-':
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
146 exon_sizes.reverse()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
147 splice_sites = [sum(exon_sizes[:x]) / 3 for x in range(1,len(exon_sizes))]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
148 print >> sys.stderr, "splice_sites: %s" % splice_sites
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
149 junc = splice_sites[0] if len(splice_sites) > 0 else exon_sizes[0]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
150 if seq:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
151 for i in range(3):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
152 translation = self.get_translation(sequence=seq[i:])
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
153 if translation:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
154 tstart = 0
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
155 tstop = len(translation)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
156 if not untrimmed:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
157 tstart = translation.rfind('*',0,junc) + 1
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
158 stop = translation.find('*',junc)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
159 tstop = stop if stop >= 0 else len(translation)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
160 if filtering and tstart > ignore:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
161 continue
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
162 trimmed = translation[tstart:tstop]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
163 #get genomic locations for start and end
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
164 offset = (block_sum - i) % 3
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
165 print >> sys.stderr, "tstart: %d tstop: %d offset: %d" % (tstart,tstop,offset)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
166 if self.strand == '+':
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
167 chromStart = self.chromStart + i + (tstart * 3)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
168 chromEnd = self.chromEnd - offset - (len(translation) - tstop) * 3
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
169 else:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
170 chromStart = self.chromStart + offset + (len(translation) - tstop) * 3
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
171 chromEnd = self.chromEnd - i - (tstart * 3)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
172 #get the blocks for this translation
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
173 tblockCount = 0
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
174 tblockSizes = []
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
175 tblockStarts = []
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
176 for x in range(self.blockCount):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
177 bStart = self.chromStart + self.blockStarts[x]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
178 bEnd = bStart + self.blockSizes[x]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
179 if bStart > chromEnd:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
180 break
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
181 if bEnd < chromStart:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
182 continue
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
183 cStart = max(chromStart,bStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
184 tblockStarts.append(cStart - chromStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
185 tblockSizes.append(min(chromEnd,bEnd) - cStart)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
186 tblockCount += 1
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
187 print >> sys.stderr, "tblockCount: %d tblockStarts: %s tblockSizes: %s" % (tblockCount,tblockStarts,tblockSizes)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
188 translations[i] = [chromStart,chromEnd,trimmed,tblockCount,tblockSizes,tblockStarts]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
189 return translations
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
190 def get_seq_id(self,seqtype='unk:unk',reference='',frame=None):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
191 ## Ensembl fasta ID format
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
192 # >ID SEQTYPE:STATUS LOCATION GENE TRANSCRIPT
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
193 # >ENSP00000328693 pep:splice chromosome:NCBI35:1:904515:910768:1 gene:ENSG00000158815:transcript:ENST00000328693 gene_biotype:protein_coding transcript_biotype:protein_coding
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
194 frame_name = ''
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
195 chromStart = self.chromStart
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
196 chromEnd = self.chromEnd
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
197 strand = 1 if self.strand == '+' else -1
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
198 if frame != None:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
199 block_sum = sum(self.blockSizes)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
200 offset = (block_sum - frame) % 3
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
201 frame_name = '_' + str(frame + 1)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
202 if self.strand == '+':
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
203 chromStart += frame
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
204 chromEnd -= offset
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
205 else:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
206 chromStart += offset
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
207 chromEnd -= frame
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
208 location = "chromosome:%s:%s:%s:%s:%s" % (reference,self.chrom,chromStart,chromEnd,strand)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
209 seq_id = "%s%s %s %s" % (self.name,frame_name,seqtype,location)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
210 return seq_id
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
211 def get_line(self, start_offset = 0, end_offset = 0):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
212 if start_offset or end_offset:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
213 s_offset = start_offset if start_offset else 0
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
214 e_offset = end_offset if end_offset else 0
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
215 if s_offset > self.chromStart:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
216 s_offset = self.chromStart
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
217 chrStart = self.chromStart - s_offset
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
218 chrEnd = self.chromEnd + e_offset
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
219 blkSizes = self.blockSizes
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
220 blkSizes[0] += s_offset
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
221 blkSizes[-1] += e_offset
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
222 blkStarts = self.blockStarts
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
223 for i in range(1,self.blockCount):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
224 blkStarts[i] += s_offset
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
225 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])]]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
226 return '\t'.join(items) + '\n'
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
227 return self.line
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
228
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
229 def __main__():
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
230 #Parse Command Line
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
231 parser = optparse.OptionParser()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
232 parser.add_option( '-t', '--translated_bed', dest='translated_bed', default=None, help='A bed file with added 13th column having a translation' )
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
233 parser.add_option( '-i', '--input', dest='input', default=None, help='Tabular file with peptide_sequence column' )
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
234 parser.add_option( '-p', '--peptide_column', type='int', dest='peptide_column', default=1, help='column ordinal with peptide sequence' )
1
db90662d26f9 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit a2d6625c1d0c65af83ce12614022f30ccd610444-dirty
galaxyp
parents: 0
diff changeset
235 parser.add_option( '-n', '--name_column', type='int', dest='name_column', default=2, help='column ordinal with protein name' )
0
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
236 parser.add_option( '-s', '--start_column', type='int', dest='start_column', default=None, help='column with peptide start position in protein' )
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
237 parser.add_option( '-B', '--bed', dest='bed', default=None, help='Output a bed file with added 13th column having translation' )
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
238 ## parser.add_option( '-G', '--gff3', dest='gff', default=None, help='Output translations to a GFF3 file' )
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
239 ## parser.add_option( '-f', '--fasta', dest='fasta', default=None, help='Protein fasta' )
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
240 parser.add_option( '-T', '--gffTags', dest='gffTags', action='store_true', default=False, help='Add #gffTags to bed output for IGV' )
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
241 parser.add_option( '-d', '--debug', dest='debug', action='store_true', default=False, help='Turn on wrapper debugging to stderr' )
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
242 (options, args) = parser.parse_args()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
243 # Input files
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
244 if options.input != None:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
245 try:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
246 inputPath = os.path.abspath(options.input)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
247 inputFile = open(inputPath, 'r')
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
248 except Exception, e:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
249 print >> sys.stderr, "failed: %s" % e
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
250 exit(2)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
251 else:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
252 inputFile = sys.stdin
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
253 inputBed = None
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
254 if options.translated_bed != None:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
255 inputBed = open(os.path.abspath(options.translated_bed),'r')
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
256 peptide_column = options.peptide_column - 1
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
257 name_column = options.name_column - 1 if options.name_column else None
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
258 start_column = options.start_column - 1 if options.start_column else None
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
259 # Read in peptides
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
260 # peps[prot_name] = [seq]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
261 prot_peps = dict()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
262 unassigned_peps = set()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
263 try:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
264 for i, line in enumerate( inputFile ):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
265 ## print >> sys.stderr, "%3d\t%s" % (i,line)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
266 if line.startswith('#'):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
267 continue
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
268 fields = line.rstrip('\r\n').split('\t')
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
269 ## print >> sys.stderr, "%3d\t%s" % (i,fields)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
270 if peptide_column < len(fields):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
271 peptide = fields[peptide_column]
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
272 prot_name = fields[name_column] if name_column is not None and name_column < len(fields) else None
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
273 if prot_name:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
274 offset = fields[start_column] if start_column is not None and start_column < len(fields) else -1
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
275 if prot_name not in prot_peps:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
276 prot_peps[prot_name] = dict()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
277 prot_peps[prot_name][peptide] = offset
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
278 else:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
279 unassigned_peps.add(peptide)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
280 if options.debug:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
281 print >> sys.stderr, "prot_peps: %s" % prot_peps
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
282 print >> sys.stderr, "unassigned_peps: %s" % unassigned_peps
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
283 except Exception, e:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
284 print >> sys.stderr, "failed: Error reading %s - %s" % (options.input if options.input else 'stdin',e)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
285 exit(1)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
286 # Output files
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
287 bed_fh = None
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
288 ## gff_fh = None
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
289 ## gff_fa_file = None
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
290 gff_fa = None
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
291 outFile = None
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
292 if options.bed:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
293 bed_fh = open(options.bed,'w')
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
294 bed_fh.write('track name="%s" type=bedDetail description="%s" \n' % ('novel_junction_peptides','test'))
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
295 if options.gffTags:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
296 bed_fh.write('#gffTags\n')
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
297 ## if options.gff:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
298 ## gff_fh = open(options.gff,'w')
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
299 ## gff_fh.write("##gff-version 3.2.1\n")
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
300 ## if options.reference:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
301 ## gff_fh.write("##genome-build %s %s\n" % (options.refsource if options.refsource else 'unknown', options.reference))
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
302 try:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
303 for i, line in enumerate( inputBed ):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
304 ## print >> sys.stderr, "%3d:\t%s" % (i,line)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
305 if line.startswith('track'):
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
306 continue
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
307 entry = BedEntry(line)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
308 if entry.name in prot_peps:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
309 for (peptide,offset) in prot_peps[entry.name].iteritems():
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
310 if offset < 0:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
311 offset = entry.seq.find(peptide)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
312 if options.debug:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
313 print >> sys.stderr, "%s\t%s\t%d\t%s\n" % (entry.name, peptide,offset,entry.seq)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
314 if offset >= 0:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
315 tstart = offset * 3
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
316 tstop = tstart + len(peptide) * 3
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
317 if options.debug:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
318 print >> sys.stderr, "%d\t%d\t%d" % (offset,tstart,tstop)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
319 (pepStart,pepEnd) = entry.get_subrange(tstart,tstop)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
320 if options.debug:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
321 print >> sys.stderr, "%d\t%d\t%d" % (offset,pepStart,pepEnd)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
322 if bed_fh:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
323 entry.thickStart = pepStart
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
324 entry.thickEnd = pepEnd
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
325 bedfields = str(entry).split('\t')
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
326 if options.gffTags:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
327 bedfields[3] = "ID=%s;Name=%s" % (entry.name,peptide)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
328 bed_fh.write("%s\t%s\t%s\n" % ('\t'.join(bedfields[:12]),peptide,entry.seq))
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
329 except Exception, e:
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
330 print >> sys.stderr, "failed: Error reading %s - %s" % (options.input if options.input else 'stdin',e)
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
331
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
332 if __name__ == "__main__" : __main__()
51f8f9041724 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/map_peptides_to_bed commit e04ed4b4960d6109a85c1cc68a2bf4931c8751ef-dirty
galaxyp
parents:
diff changeset
333