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
          Strategies for Sequencing Challenging Samples
          by seqadmin


          Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
          03-22-2024, 06:39 AM
        • seqadmin
          Techniques and Challenges in Conservation Genomics
          by seqadmin



          The field of conservation genomics centers on applying genomics technologies in support of conservation efforts and the preservation of biodiversity. This article features interviews with two researchers who showcase their innovative work and highlight the current state and future of conservation genomics.

          Avian Conservation
          Matthew DeSaix, a recent doctoral graduate from Kristen Ruegg’s lab at The University of Colorado, shared that most of his research...
          03-08-2024, 10:41 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by seqadmin, Yesterday, 06:37 PM
        0 responses
        11 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, Yesterday, 06:07 PM
        0 responses
        10 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 03-22-2024, 10:03 AM
        0 responses
        51 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 03-21-2024, 07:32 AM
        0 responses
        68 views
        0 likes
        Last Post seqadmin  
        Working...
        X