Skip to content

Instantly share code, notes, and snippets.

@timrandg
Created February 28, 2013 06:29
Show Gist options
  • Select an option

  • Save timrandg/5054689 to your computer and use it in GitHub Desktop.

Select an option

Save timrandg/5054689 to your computer and use it in GitHub Desktop.
peptide mapper
#command-line usage:
#% ruby /Users/timrand/Dropbox/NAT1/peptide_mapper3.rb peptide_file target_file
# 1 M 0
# 2 S 0
# 3 P 8 [][][][][][][][]
# 4 A 8 [][][][][][][][]
# 5 G 8 [][][][][][][][]
# 6 S 8 [][][][][][][][]
# 7 C 8 [][][][][][][][]
# 8 D 8 [][][][][][][][]
# 9 L 5 [][][][][]
# 10 A 5 [][][][][]
# 11 E 1 []
# 12 D 1 []
# 13 A 1 []
# 14 A 1 []
# 15 C 1 []
# 16 Q 2 [][]
# 17 L 2 [][]
# 18 Q 2 [][]
# 19 C 2 [][]
# 20 V 2 [][]
#======================================
#Define the target and the peptide list
#======================================
def peptide_list
[ "XXXXXXXX", "PAGSCDLA","PAGSCDLA","PAGSCDLA","PAGSCDLA", "QLQCVIDCA", "LAEDAACQLQCVIDCAAELL", "PAGSCD", "PAGSCD", "PAGSCD", "PAGSCD"]
#File.readlines(ARGV[0]).collect{|line| line.chomp}
end
def target
"MSPAGSCDLAEDAACQLQCVIDCAAELLAEDCLLAEDPAGSCD"
#File.readlines(ARGV[1]).collect{|line| line.chomp}
end
#======================================
#======================================
class String
def digitize_as(dig)
gsub(/./,dig.to_s)
end
def each_with_index(&blk)
split('').each_with_index(&blk)
end
alias :dig_as :digitize_as
end
class Array
# returns an array of column sums from an Array with rows of arrays with digits
# [[0,0,1,1,0,0],
# [0,0,0,1,1,0]].summed_by_site
# => [0,0,1,2,1,0]
def summed_by_site
unless self.empty? #edge case: could be no peptides sites in target, so self is an empty array
collection = Array.new(self.first.length){0}
for r in self do
for i in (0..first.length-1) do
collection[i] = collection[i] + r[i]
end
end
end
collection || []
end
end
#===============================================================
#functions for mapping and printing peptides onto an AA sequence
#===============================================================
#memory for search_and_save
def digitized_hits
@digitized_hits ||= []
end
#helper for map_peptides
def search_and_save(str, query)
pre, match, post = str.partition(query)
unless match.empty?
digitized_hits << (pre.dig_as(0) + match.dig_as(1) + post.dig_as(0)).split('').collect(&:to_i)
mask_str = pre.dig_as(0)+match.dig_as(0)+post #mask the region searched so far and
search_and_save(mask_str, query) #recurse to find other possible hits
end
digitized_hits
end
#returns a digital mapping of peptide alignments
def map_peptides
peptide_list.each do |query|
search_and_save(target, query)
end
digitized_hits
end
def printer arr
printf("%5s %s %2s %s\n" % arr)
end
def graph_bar(i)
amplifier = 1
i = i || 0 #solve edge case: digitized.sum list returns nil for indexing attempts if there are no hits at all, convert to 0
'[]' * i * amplifier
end
aligned_map = map_peptides
target.each_with_index{ |aa,i| printer [i+1, aa, aligned_map.summed_by_site[i], graph_bar(aligned_map.summed_by_site[i])] }
@timrandg

Copy link
Copy Markdown
Author

We get peptides, protein fragments, back from mass spec. Aligning them back on the protein sequence can be informative as it can elucidate whether the entire protein was present or whether it was a splice varient and was missing a region. Or if when selecting an antibody, you can make sure that the version of the protein you are working with contains the region the antibody is made against. This script takes two inputs a text file list of peptides and a text file with the full (longest known) protein sequence. It can handle cases with no peptides matching, peptides matching more than one site (it assigns the peptide to both locations), and overlapping peptides (it creates histograms by amino acid position). This makes mapping peptides child's play. The output columns are as follows:
Amino_acid_index Amino_acid_abbreviation Total_peptides_containing_that_site Horizontal_bar_graph_by_site

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment