Answers.Body: <p>What you are missing is the accuracy of the prediction, this is the next step and must be &gt;80%, preferably &gt;85% and &gt;90% is good in biological systems. If its lower than 80% you'll need to adjust the training. Following this there are issues with false positives and false negatives.</p>
  <p>The method of using seems fine for mapping sequence motifs to transcription factors, which is my interpretation of your question. There must have been vectorisation of the sequence data and this is not trivial.</p>
  <p>To answer your question, which you might be asking, you cannot produce an automated heatmap of sequence motif in relation to the transcriptor factor binding. You simply input a sequence and the associated transcription factors are revealed. Unless you vectorised your transcription factors somehow and associated this with a sequence motif.</p>
  <p>To produce a heatmap, which again is what I suspect you are requesting, you do this via iteration. So you need a bit of coding. Thus you take all relevant sequence motifs - particularly those that have not been trained - and input them into deep learning algorithm and map which motifs associate with which binding factors and assign a numerical score to given groups of sequence motifs. Any graphics program can then be used to convert this to a heat map. Deciding 'taxonomic groups' for the sequence motifs is subject to your discretion. If you've given the transcription factors and trained this onto the sequence motifs, then classification of transcription factors I suspect would be much easier.</p>
  <p>Heatmaps are produced in other machine learning approaches, i.e. which exclude deep learning, but your next step is percentage accuracy regardless of approach.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-22T22:46:23.220Z
Answers.LastActivityDate: 2022-02-22T11:24:04.883Z
Answers.LastEditDate: 2022-02-22T11:24:04.883Z
Answers.UserDisplayName: M__
Body: <p>I created a basic CNN architecture using Tensorflow to classify transcription factor binding sites. My aim is to somehow extract and visualize sequence logos from the convolutional kernels. The model looks like this:</p>
  <pre class="lang-py prettyprint-override"><code>model = tf.keras.models.Sequential()
  model.add(tf.keras.layers.Conv2D(128, (1, 24), padding='same', input_shape=(1, 101, 4), activation='relu'))
  model.add(tf.keras.layers.GlobalMaxPool2D())
  # ...
  </code></pre>
  <p>I am using the supplement <a href="http://cnn.csail.mit.edu/motif_discovery/" rel="nofollow noreferrer">dataset</a> from <a href="https://www.researchgate.net/publication/304002757_Convolutional_neural_network_architectures_for_predicting_DNA-protein_binding" rel="nofollow noreferrer">this publication</a></p>
  <p>What I tried so far is that I have trained the model and created a new model out of it which has only an input layer and an output layer that contains the weights of the original convolution kernels:</p>
  <pre class="lang-py prettyprint-override"><code>test_model = tf.keras.models.Model(inputs=model.inputs, outputs=model.layers[0].output)
  feature_maps = test_model.predict(x)
  </code></pre>
  <p>I have ran a prediction on a sequence and plotted out a convolution kernel:
  <a href="https://i.sstatic.net/j7CKEl.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/j7CKEl.png" alt="Convolution kernel plot" /></a></p>
  <p>At this point I got a bit stuck as I am not sure how can I move forward with this in the direction of visualizing the sequence logos.</p>
  
Tags: <python><machine-learning><tensorflow>
Title: How to extract and visualize sequence logos from CNN kernels?
ThreadText: # How to extract and visualize sequence logos from CNN kernels?
  
  (Asked by: username_0 on 2022-01-22)
  
  I created a basic CNN architecture using Tensorflow to classify transcription factor binding sites. My aim is to somehow extract and visualize sequence logos from the convolutional kernels. The model looks like this:
  
  ```py
  model = tf.keras.models.Sequential()
  model.add(tf.keras.layers.Conv2D(128, (1, 24), padding='same', input_shape=(1, 101, 4), activation='relu'))
  model.add(tf.keras.layers.GlobalMaxPool2D())
  # ...
  
  ```
  
  I am using the supplement [dataset](http://cnn.csail.mit.edu/motif_discovery/) from [this publication](https://www.researchgate.net/publication/304002757_Convolutional_neural_network_architectures_for_predicting_DNA-protein_binding)
  
  What I tried so far is that I have trained the model and created a new model out of it which has only an input layer and an output layer that contains the weights of the original convolution kernels:
  
  ```py
  test_model = tf.keras.models.Model(inputs=model.inputs, outputs=model.layers[0].output)
  feature_maps = test_model.predict(x)
  
  ```
  
  I have ran a prediction on a sequence and plotted out a convolution kernel:
  [![Convolution kernel plot](https://i.sstatic.net/j7CKEl.png)](https://i.sstatic.net/j7CKEl.png)
  
  At this point I got a bit stuck as I am not sure how can I move forward with this in the direction of visualizing the sequence logos.
  
  **Tags:** python, machine-learning, tensorflow
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-01-22. Score: 0
  
  What you are missing is the accuracy of the prediction, this is the next step and must be >80%, preferably >85% and >90% is good in biological systems. If its lower than 80% you'll need to adjust the training. Following this there are issues with false positives and false negatives.
  
  The method of using seems fine for mapping sequence motifs to transcription factors, which is my interpretation of your question. There must have been vectorisation of the sequence data and this is not trivial.
  
  To answer your question, which you might be asking, you cannot produce an automated heatmap of sequence motif in relation to the transcriptor factor binding. You simply input a sequence and the associated transcription factors are revealed. Unless you vectorised your transcription factors somehow and associated this with a sequence motif.
  
  To produce a heatmap, which again is what I suspect you are requesting, you do this via iteration. So you need a bit of coding. Thus you take all relevant sequence motifs - particularly those that have not been trained - and input them into deep learning algorithm and map which motifs associate with which binding factors and assign a numerical score to given groups of sequence motifs. Any graphics program can then be used to convert this to a heat map. Deciding 'taxonomic groups' for the sequence motifs is subject to your discretion. If you've given the transcription factors and trained this onto the sequence motifs, then classification of transcription factors I suspect would be much easier.
  
  Heatmaps are produced in other machine learning approaches, i.e. which exclude deep learning, but your next step is percentage accuracy regardless of approach.
  
  
  ---
  
  