<commit_before># == Schema Information
#
# Table name: sequences
#
#  id       :integer(4)      not null, primary key
#  sequence :string(50)      not null
#  lca      :integer(3)
#  lca_il   :integer(3)
#

class Sequence < ActiveRecord::Base
  
  has_many :peptides
  has_many :original_peptides, :foreign_key  => "original_sequence_id", :primary_key  => "id", :class_name   => 'Peptide'
  
  def lineages(equate_il = true)
    if equate_il
      l = Lineage.find_by_sql("
      SELECT DISTINCT lineages.*
      FROM unipept.peptides 
      INNER JOIN unipept.uniprot_entries ON (uniprot_entries.id = peptides.uniprot_entry_id) 
      INNER JOIN unipept.lineages ON (uniprot_entries.taxon_id = lineages.taxon_id)
      WHERE peptides.sequence_id = #{id}")
    else
      l = Lineage.find_by_sql("
      SELECT DISTINCT lineages.*
      FROM unipept.peptides 
      INNER JOIN unipept.uniprot_entries ON (uniprot_entries.id = peptides.uniprot_entry_id) 
      INNER JOIN unipept.lineages ON (uniprot_entries.taxon_id = lineages.taxon_id)
      WHERE peptides.original_sequence_id = #{id}")
    end
    return l
  end
  
  def calculate_lca(equate_il = true)
    if equate_il
      if lca_il.nil?
        write_attribute(:lca_il, Lineage.calculate_lca(lineages(true)))
        save
      end
      return lca_il
    else
      if lca.nil?
        write_attribute(:lca, Lineage.calculate_lca(lineages(false)))
        save
      end
      return lca
    end
  end
                        
end<commit_msg>small improvement in counter code<commit_after># == Schema Information
#
# Table name: sequences
#
#  id       :integer(4)      not null, primary key
#  sequence :string(50)      not null
#  lca      :integer(3)
#  lca_il   :integer(3)
#

class Sequence < ActiveRecord::Base
  
  has_many :peptides
  has_many :original_peptides, :foreign_key  => "original_sequence_id", :primary_key  => "id", :class_name   => 'Peptide'
  
  def lineages(equate_il = true)
    if equate_il
      l = Lineage.find_by_sql("
      SELECT DISTINCT lineages.*
      FROM unipept.peptides 
      INNER JOIN unipept.uniprot_entries ON (uniprot_entries.id = peptides.uniprot_entry_id) 
      INNER JOIN unipept.lineages ON (uniprot_entries.taxon_id = lineages.taxon_id)
      WHERE peptides.sequence_id = #{id}")
    else
      l = Lineage.find_by_sql("
      SELECT DISTINCT lineages.*
      FROM unipept.peptides 
      INNER JOIN unipept.uniprot_entries ON (uniprot_entries.id = peptides.uniprot_entry_id) 
      INNER JOIN unipept.lineages ON (uniprot_entries.taxon_id = lineages.taxon_id)
      WHERE peptides.original_sequence_id = #{id}")
    end
    return l
  end
  
  def calculate_lca(equate_il = true)
    if equate_il
      if lca_il.nil?
        lca_il = Lineage.calculate_lca(lineages(true))
        write_attribute(:lca_il, lca_il) unless lca_il==-1
        save
      end
      return lca_il
    else
      if lca.nil?
        lca = Lineage.calculate_lca(lineages(false))
        write_attribute(:lca, lca) unless lca==-1
        save
      end
      return lca
    end
  end
                        
end
{'fraction_non_alphanumeric': 0.08712487899322362, 'fraction_numerical': 0.003872216844143272, 'mean_word_length': 2.651354534746761, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5287111', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1072, 'n_words': 235}