Assignment 3/assignment3.rb
# 2. searches for 'CTTCTT' repeat in exons from each ArabidopsisSubNetwork_GeneList.txt genes and
# adds repeats as Bio::Feature object of each Bio::Sequence object
2. searches for 'CTTCTT' repeat in exons from each ArabidopsisSubNetwork_GeneList.txt genes and
adds repeats as Bio::Feature object of each Bio::Sequence object
2 . searches for ' CTTCTT ' repeat in exons from each ArabidopsisSubNetwork_GeneList . txt genes and adds repeats as Bio :: Feature object of each Bio :: Sequence object
def add_repeat_features(file)
  @all_biosequence = Hash.new
  File.open(file).each do |gene|
    gene.strip! 
    response = fetch("http://www.ebi.ac.uk/Tools/dbfetch/dbfetch?db=ensemblgenomesgene&format=embl&id=#{gene}")
    if response
      record = response.body
      entry = Bio::EMBL.new(record)
      positions = Array.new 
      bioseq = entry.to_biosequence
      bioseq.features.each do |feature|
        next unless feature.feature == 'exon'
        locations = feature.locations
        location = locations.locations
        location.each do |loc|
          exon = bioseq.subseq(loc.from, loc.to)
          next if exon == nil 
            if loc.strand == 1
              rep_for =(Bio::Sequence::NA.new("CTTCTT")).to_re
              if exon.match(rep_for)
                position_match_ex = exon.index(rep_for)
                position_match_seq = [position_match_ex + loc.from, position_match_ex + loc.from + 5]
                bioseq.features << create_features("#{position_match_seq[0]}..#{position_match_seq[1]}",loc.strand) unless positions.include?(position_match_seq)
                @all_biosequence[gene] = bioseq
                positions << position_match_seq
              else 
                @all_biosequence[gene] = bioseq 
              end
            elsif loc.strand == -1
              rep_rev =(Bio::Sequence::NA.new("AAGAAG")).to_re
              if exon.match(rep_rev)
                position_match_ex = exon.index(rep_rev)
                position_match_seq = [position_match_ex + loc.from, position_match_ex + loc.from + 5]
                bioseq.features << create_features("complement(#{position_match_seq[0]}..#{position_match_seq[1]})",loc.strand) unless positions.include?(position_match_seq)
                @all_biosequence[gene] = bioseq
                positions << position_match_seq
              else
                @all_biosequence[gene] = bioseq
              end
            end  
        end
      end
    end
  end
  return @all_biosequence 
end
def add_repeat_features ( file ) @all_biosequence = Hash . new File . open ( file ) . each do | gene | gene . strip! response = fetch ( "http://www.ebi.ac.uk/Tools/dbfetch/dbfetch?db=ensemblgenomesgene&format=embl&id=#{gene}" ) if response record = response . body entry = Bio :: EMBL . new ( record ) positions = Array . new bioseq = entry . to_biosequence bioseq . features . each do | feature | next unless feature . feature == 'exon' locations = feature . locations location = locations . locations location . each do | loc | exon = bioseq . subseq ( loc . from , loc . to ) next if exon == nil if loc . strand == 1 rep_for = ( Bio :: Sequence :: NA . new ( "CTTCTT" ) ) . to_re if exon . match ( rep_for ) position_match_ex = exon . index ( rep_for ) position_match_seq = [ position_match_ex + loc . from , position_match_ex + loc . from + 5 ] bioseq . features << create_features ( "#{position_match_seq[0]}..#{position_match_seq[1]}" , loc . strand ) unless positions . include? ( position_match_seq ) @all_biosequence [ gene ] = bioseq positions << position_match_seq else @all_biosequence [ gene ] = bioseq end elsif loc . strand == - 1 rep_rev = ( Bio :: Sequence :: NA . new ( "AAGAAG" ) ) . to_re if exon . match ( rep_rev ) position_match_ex = exon . index ( rep_rev ) position_match_seq = [ position_match_ex + loc . from , position_match_ex + loc . from + 5 ] bioseq . features << create_features ( "complement(#{position_match_seq[0]}..#{position_match_seq[1]})" , loc . strand ) unless positions . include? ( position_match_seq ) @all_biosequence [ gene ] = bioseq positions << position_match_seq else @all_biosequence [ gene ] = bioseq end end end end end end return @all_biosequence end
2. searches for 'CTTCTT' repeat in exons from each ArabidopsisSubNetwork_GeneList.txt genes and
adds repeats as Bio::Feature object of each Bio::Sequence object
2 . searches for ' CTTCTT ' repeat in exons from each ArabidopsisSubNetwork_GeneList . txt genes and adds repeats as Bio :: Feature object of each Bio :: Sequence object
# new hash to store each Bio::Sequence object # for each gene in file... # AGI locus code without '\n' # search for gene info in ensemblgenomesgene database  # store database record as a Bio::EMBL object # creating a new array to store positions of 'CTTCTT' repeats # convert EMBL record to Bio::Sequence object # features method of Bio::Sequence Class creates Bio::Feature array objects # iterating over array objects # feature method of Bio::Feature Class is the type of feature (i.e: exon, gene...) # next iteration unless feature = exon # locations method of Bio::Feature Class creates Bio::Locations object # locations method of Bio::Locations Class creates an array of Bio::Location objects # iterating over each Bio::Location object of the array # subtract exon sequence from original sequence with 'subseq' method --> always forward strand! # with positions from Bio::Location object obtained with 'from' and 'to' mehods  # these positions correspond always to forward strand  # next iteration if there is not exon sequence (nil) # if exon is in the forward strand... # search for 'CTTCTT' repeat  # defining sequence repeat # if exon contains the 'CTTCTT' repeat... # get start position of match 'CTTCTT' in exon # positions (start and end) of match 'CTTCTT' in whole sequence  # adding repeat 'CTTCTT' feature (with create_features method defined below) unless same 'CTTCTT' positions have just been added --> avoid repeating the same 'CTTCTT' feature  # adding the Bio::Sequence object to the hash with AGI locus code as key # adding positions to array # if exon is in the forward strand... # search for 'AAGAAG' repeat (reverse complement of 'CTTCTT') # defining sequence repeat # if exon contains the 'AAGAAG' repeat... # start position of match 'AAGAAG' in exon # positions (start and end) of match 'AAGAAG' in whole sequence 
file
<not_specific>