I have a FIMO output, the input sequences were putative promoter sequences of several species. I want to graph the positions of these motifs along a horizontal graph, but I want to filter the data by clustering the motifs by family, e.g. all the zinc finger motifs being represented by one color, all the helix loop helix motifs being represented by one color, etc. How would I go about clustering the raw .tsv file?

  • $\begingroup$ Please explain what FIMO is, and show the first few lines from your raw .tsv file. What language / tool would you like to use for clustering? Is this something you'd do directly in the FIMO tool, or externally using another program? $\endgroup$
    – gringer
    Feb 4 at 18:54
  • $\begingroup$ JohnDoe23, are you looking for an output like the one shown here: bioinformatics.stackexchange.com/a/20132/3967 $\endgroup$
    – acvill
    Feb 7 at 21:56

2 Answers 2


Comment: I don't understand what you mean by "I want to graph the positions of these motifs along a horizontal graph"? Are you talking about a Manhatten plot? Or something else? And I'm not sure about "filter the data by clustering the motifs by family". What type of clustering do you want to perform?

Without further information/description it's difficult to understand what you're trying to do. If possible, please edit your question with an example of what your desired output. Also please indicate the language you're using for your visualisation, e.g. R, python, other.

Answer: I may have completely misunderstood, but perhaps this approach could be adapted to suit. Using the example FIMO output file from https://meme-suite.org/meme/doc/examples/fimo_example_output_files/fimo.html?man_type=web:

#> For example usage please run: vignette('qqman')
#> Citation appreciated but not required:
#> Turner, (2018). qqman: an R package for visualizing GWAS results using Q-Q and manhattan plots. Journal of Open Source Software, 3(25), 731

fimo_df <- read_tsv("~/Desktop/fimo.tsv", comment = "#") %>%
  rename("SNP" = motif_id, "CHR" = sequence_name, "BP" = start,
         "P" = `p-value`, "zscore" = `q-value`) %>%
  mutate(CHR = case_when(str_detect(CHR, "X") ~ "23",
                         str_detect(CHR, "Y") ~ "24",
                         TRUE ~ CHR)) %>%
  mutate(CHR = parse_number(CHR)) %>%
  select(-c(stop, strand, matched_sequence))
#> Rows: 1494 Columns: 10
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: "\t"
#> chr (5): motif_id, motif_alt_id, sequence_name, strand, matched_sequence
#> dbl (5): start, stop, score, p-value, q-value
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

manhattan(fimo_df, p = "zscore", logp = TRUE, ylab = "q-score",
          genomewideline = FALSE, suggestiveline = FALSE,
          main = "Manhattan plot of TF motifs", 
          chrlabs = c(1:19, "X", "Y"))

If you want to colour the points by TF motif (or by 'cluster'), perhaps ggplot would be appropriate, e.g.

axis_set <- fimo_df |>
  group_by(CHR) |>
  summarize(center = mean(BP, na.rm = TRUE))

ylim <- fimo_df |>
  filter(P == min(P)) |>
  mutate(ylim = abs(floor(log10(P))) + 2) |>

ggplot(fimo_df, aes(x = BP, y = -log10(P),
                    color = as.factor(CHR), 
                    size = -log10(P))) +
  geom_point(alpha = 0.75) +
  # scale_x_continuous(label = sort(axis_set$CHR), breaks = sort(axis_set$center)) +
  scale_y_continuous(expand = c(0, 0), limits = c(3.95, ylim)) +
  scale_color_manual(values = rep(
    c("#276FBF", "#183059"),
  )) +
  scale_size_continuous(range = c(0.5, 3)) +
  theme_minimal() +
    legend.position = "none",
    panel.grid.major.x = element_blank(),
    panel.grid.minor.x = element_blank(),
  ) +
  gghighlight(motif_alt_id == "TBP")
#> Warning: Tried to calculate with group_by(), but the calculation failed.
#> Falling back to ungrouped filter operation...

Created on 2024-02-05 with reprex v2.1.0

Does that help at all?


How do you know the "family" to which your motifs belong? If the source for the motifs that FIMO matched is, say, JASPAR Vertebrata CORE, then you might reasonably decide to use JASPAR's "structural class" as provided by their pre-computed "Annotation table" in JASPAR CORE Vertebrates clustering.

Assuming you are using JASPAR and you do make this decision...

Your "raw .tsv file" is in FIMO Results TSV Format. "Joining" it with a downloaded copy of the "Annotation table" serves to annotate it with additional columns, having the effect you seek of clustering the FIMO results on the "structural class" of each matched motif. Joining can be implemented following Running queries directly against CSV or JSON using the sqlite-utils command-line utility.

How you would then plot these features and encode the class as a color requires more detailed description what the plot is supposed to represent or look like. For instance, do you "want to graph the positions of these motifs along a horizontal graph" with coordinates taken with respect to the TSS of the transcript from which the promoter is taken?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.