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
          Recent Advances in Sequencing Analysis Tools
          by seqadmin


          The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
          05-06-2024, 07:48 AM
        • 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...
          04-22-2024, 07:01 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by seqadmin, Yesterday, 06:57 AM
        0 responses
        11 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 05-06-2024, 07:17 AM
        0 responses
        15 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 05-02-2024, 08:06 AM
        0 responses
        19 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-30-2024, 12:17 PM
        0 responses
        24 views
        0 likes
        Last Post seqadmin  
        Working...
        X