Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script To Calculate Word Frequency For Many Sequences

    Hello!

    Who can help me with a writing a script?

    1. For each file in the set (archive, probably):

    Open input nucleotide sequence (.embl format is desirable, but fasta format is possible);

    Calculate the observable frequency for all possible words based on input word size (e.g. number of all possible words for word size = 3 (triplet) is 64). Obs. Frequency = Obs Count/Total count [Сompseq is work in a similar way, but not support a batch processing].

    Shift the reading frame by 1 nucleotide and repeat the previous step (number of shifts = word size - 1). The file with frequencies for each file in the set save as name_of_the_file(id of a contig).dic(+word size). It looks sth like this (word size = 2):



    2. Make a summary file, something like this (example for word size = 2)

  • #2
    example usage: cat hg20/chr1.fa | ./kmer3

    Code:
    -bash-4.1$ cat kmer3.c
    
    /*
    vi kmer3.c ; gcc -Wall -O3  kmer3.c -o kmer3  -lm 
    */
    
    #include <stdio.h>
    #include <string.h>
    #include <stdio.h>
    #include <ctype.h>
    #include <errno.h>
    #include <assert.h>
    
    long int x3[4][4][4];
    
    int acgt_index(char c)
    {
        if (c=='A') return 0;
        else if (c=='C') return 1;
        else if (c=='G') return 2;
        else if (c=='T') return 3;
        return -1;
    }
    
    
    void wrapup3(void)
    {
       int i,j,k; 
    
       for (i=0;i<4;i++)
       for (j=0;j<4;j++)
       for (k=0;k<4;k++)
       {
           if (i==0) {printf("A");} else if (i==1) {printf("C");} else if (i==2) {printf("G");}  else if (i==3) {printf("T"); }
           if (j==0) {printf("A");} else if (j==1) {printf("C");} else if (j==2) {printf("G");} else if (j==3) {printf("T"); }
           if (k==0) {printf("A");} else if (k==1) {printf("C");} else if (k==2) {printf("G");} else if (k==3) {printf("T"); }
           printf(" %ld\n",x3[i][j][k]);
       }
    }
    
    int is[4];
    
    static int kmer(void)
    {
       int on_head = 0;
       int c;
       long int cnt = (long int)0;
    
        while (1)
        {
             c = getchar();
             cnt++;
             if (c==-1) break;
             if (c=='>') {on_head=1; continue; }
             if ((c=='\r')|| (c=='\n')) {on_head=0; continue; }
             if (on_head == 1) continue;
             is[0] = is[1];
             is[1] = is[2];
             is[2] = acgt_index(toupper(c));
             if (is[0] == -1) continue;
             if (is[1] == -1) continue;
             if (is[2] == -1) continue;
             x3[is[0]][is[1]][is[2]]++;
       }
       return 0;
    }
    
    int main(int argc, char *argv[])
    {
        kmer();
        wrapup3();
        return 0;
    }
    Last edited by Richard Finney; 06-27-2015, 11:06 AM.

    Comment


    • #3
      How to run this script?
      Originally posted by Richard Finney View Post
      example usage: cat hg20/chr1.fa | ./kmer3

      Code:
      -bash-4.1$ cat kmer3.c
      
      /*
      vi kmer3.c ; gcc -Wall -O3  kmer3.c -o kmer3  -lm 
      */
      
      #include <stdio.h>
      #include <string.h>
      #include <stdio.h>
      #include <ctype.h>
      #include <errno.h>
      #include <assert.h>
      
      long int x3[4][4][4];
      
      int acgt_index(char c)
      {
          if (c=='A') return 0;
          else if (c=='C') return 1;
          else if (c=='G') return 2;
          else if (c=='T') return 3;
          return -1;
      }
      
      
      void wrapup3(void)
      {
         int i,j,k; 
      
         for (i=0;i<4;i++)
         for (j=0;j<4;j++)
         for (k=0;k<4;k++)
         {
             if (i==0) {printf("A");} else if (i==1) {printf("C");} else if (i==2) {printf("G");}  else if (i==3) {printf("T"); }
             if (j==0) {printf("A");} else if (j==1) {printf("C");} else if (j==2) {printf("G");} else if (j==3) {printf("T"); }
             if (k==0) {printf("A");} else if (k==1) {printf("C");} else if (k==2) {printf("G");} else if (k==3) {printf("T"); }
             printf(" %ld\n",x3[i][j][k]);
         }
      }
      
      int is[4];
      
      static int kmer(void)
      {
         int on_head = 0;
         int c;
         long int cnt = (long int)0;
      
          while (1)
          {
               c = getchar();
               cnt++;
               if (c==-1) break;
               if (c=='>') {on_head=1; continue; }
               if ((c=='\r')|| (c=='\n')) {on_head=0; continue; }
               if (on_head == 1) continue;
               is[0] = is[1];
               is[1] = is[2];
               is[2] = acgt_index(toupper(c));
               if (is[0] == -1) continue;
               if (is[1] == -1) continue;
               if (is[2] == -1) continue;
               x3[is[0]][is[1]][is[2]]++;
         }
         return 0;
      }
      
      int main(int argc, char *argv[])
      {
          kmer();
          wrapup3();
          return 0;
      }

      Comment


      • #4
        Create source code using text editor, past in code.
        Name the file kmer3.c

        Compile with
        gcc -Wall -O3 kmer3.c -o kmer3 -lm

        Program takes standard input.
        Example ...
        cat hg20/chr1.fa | ./kmer3

        fastas only unless you hack it.

        Comment

        Latest Articles

        Collapse

        • seqadmin
          Essential Discoveries and Tools in Epitranscriptomics
          by seqadmin


          The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist on Modified Bases...
          Yesterday, 07:01 AM
        • seqadmin
          Current Approaches to Protein Sequencing
          by seqadmin


          Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
          04-04-2024, 04:25 PM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by seqadmin, 04-11-2024, 12:08 PM
        0 responses
        37 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-10-2024, 10:19 PM
        0 responses
        41 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-10-2024, 09:21 AM
        0 responses
        35 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-04-2024, 09:00 AM
        0 responses
        55 views
        0 likes
        Last Post seqadmin  
        Working...
        X