<commit_before>class GenomeRelationshipsController < ApplicationController

  def index

    respond_to do |format|
      format.json do
        # a big mess.

        @min_related = Integer(params[:min_related] || 0)

        params[:genome_id] = 1

        # find all genome relationships where genome_id is params[:genome_id]
        # then find all genome relationships whose genome_id is in the related
        # genome ids.
        genome_relationships = 
          unless params[:genome_id].nil?
            GenomeRelationship.cache {
              # find all genomes related to this genome
              genomes_related = GenomeRelationship.where(genome: params[:genome_id]).all
              related_to_genome = GenomeRelationship.where(genome: genomes_related).all
              genomes_related + related_to_genome
            }
          else
            GenomeRelationship.all
          end

        # get a list of all genomes included in the genome relationships
        genomes = (genome_relationships.map(&:genome) +
                   genome_relationships.map(&:related_genome)).uniq

        # build graph nodes
        # also make a 0-based indexed array of genomes (for referencing the
        # genomes in the links)
        genomes_list = []
        nodes = genomes.map do |genome|
          genomes_list << genome.id
          { name: genome.organism, group: genome.organism.split[1] }<commit_msg>fixed graph building<commit_after>class GenomeRelationshipsController < ApplicationController

  def index

    respond_to do |format|
      format.json do
        # a big mess.

        @min_related = Integer(params[:min_related] || 0)

        # find all genome relationships where genome_id is params[:genome_id]
        # then find all genome relationships whose genome_id is in the related
        # genome ids.
        genome_relationships = 
          unless params[:genome_id].nil?
            # find all genomes related to this genome
            genomes_related = GenomeRelationship.where(genome: params[:genome_id]).all
            # find relationships within genomes that are related to this genome
            related_relationships = GenomeRelationship.where(genome_id: genomes_related.map(&:related_genome_id)).all
            # combine, use to build graph
            genomes_related + related_relationships
          else
            GenomeRelationship.all
          end

        # get a list of all genomes included in the genome relationships
        # (this list is highly redundant so uniq it, also sometimes there are
        # nils so just remove them).
        genomes = (genome_relationships.map(&:genome) +
                   genome_relationships.map(&:related_genome)).uniq.compact

        # build graph nodes
        # also make a 0-based indexed array of genomes (for referencing the
        # genomes in the links)
        genomes_list = []
        nodes = genomes.map do |genome|
          genomes_list << genome.id
          { name: genome.organism, group: genome.organism.split[1] }
{'fraction_non_alphanumeric': 0.0672158154859967, 'fraction_numerical': 0.0023064250411861617, 'mean_word_length': 2.30718954248366, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '4886029', 'n_tokens_mistral': 843, 'n_tokens_neox': 737, 'n_words': 239}