# Prepare files to make a gene density karyotype image for M franciscanus Analysis Completed by Kate Castellano Purpose: Look at genome wide gene density
  1. Split the genome into 550kb windows and count the number of genes in each window
  2. Multiple window sizes were tried (10 kb, 50kb, 100kb) but a window size of 550kb was picked to match P. lividus paper Figure 1B https://www.cell.com/cell-genomics/pdf/S2666-979X(23)00061-7.pdf)
    1. Get the length of each chromosome (done previously for synteny - see detailed notes)
    2. Edit file for bedtools
    3.     
      #remove ">" symbol before scaffold names
      sed -i 's/>//g' Mfran_chr_length.txt       
      #Add a column with "0" value and then reorder columns with awk
      sed "s/$/\t0/" Mfran_chr_length.txt | awk -v OFS="\t" '{print $1,$3,$2}' > Mfran_chr_length_forBedtools.txt
      #Final output should look like this with Scaffold ID, and then the range (I always do 0 - whatever the length of the chrom is)
      HiC_scaffold_1  0       46325628
        
      
    4. convert gene annotation file to bed format (using awk) and sort with bedtools
    5. Make windows with bedtools make windows, sort with bedtools and count the number of genes within those windows (bedtools map)
    6. Map onto chromosomes using RIdeogram
    7. Tutorial: https://cran.r-project.org/web/packages/RIdeogram/vignettes/RIdeogram.html#:~:text=RIdeogram%20is%20a%20R%20package,genome%2Dwide%20data%20on%20idiograms.