C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 4th, 2012, 07:16 PM
machupicchu machupicchu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 21 machupicchu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 52 m 44 sec
Reputation Power: 0
Dna compress

Hi, can someone give me some tips how can I program it!

I want to integrate the part of the programm in this function. start is my first node. thanks for any help.

c Code:
Original - c Code
  1. void compressed()
  2. {
  3.     struct node *q;
  4.     if(start == NULL)
  5.     {
  6.         printf ("\n\nList is empty");
  7.         return;
  8.     }
  9.     q=start;
  10.     printf("\n\nList is : ");
  11.     while(q!=NULL)
  12.     {
  13.        
  14.       if(q->info==q->link)
  15.        
  16.         printf ("%c", q->info);
  17.         q=q->link;
  18.     }
  19.     printf ("\n");
  20.    
  21. }


DNA sequences can be very long. One way to (potentially) conserve space is to group together
sequences of common characters. For example, ‘AAAGTTTACACCT’ could be compressed as
‘A3G1T3A1C1A1C2T1’.
Write a function compress that inputs a linked list DNA sequence, and produces a new linked
list, in which the items in the Nodes are lists of length 2, [x,y], where x is one of the strings
‘A’,’C’,’G’,’T’, and y is the number of times that character appears in consecutive positions
in the sequence.

Reply With Quote
  #2  
Old December 4th, 2012, 07:53 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
Quote:
Originally Posted by instructor
Write a function compress

compress is the function name I expect. Not compressed.

Quote:
Originally Posted by instructor
that inputs a linked list DNA sequence,

I expect compress to take an argument, the head of a singly linked list.

Quote:
Originally Posted by instructor
and produces a new linked list,
Function compress should return a linked list, be it an array or a pointer to some sort of complicated node. void is incorrect.

Quote:
Originally Posted by instructor
in which the items in the Nodes are lists of length 2, [x,y], where x is one of the strings
‘A’,’C’,’G’,’T’, and y is the number of times that character appears in consecutive positions
in the sequence.
Admittedly confusing. Let's clarify "lists of length 2" as "members x and y, x is a character, y is an (perhaps unsigned) int."

We need a new structure. I'd write (others know how to use typedef) (well, actually I'd use someone else's linked list, that of glib)
Code:
#define CB struct compressed_base
CB {
  CB*next;
  char x; /* base is a better name, in my opinion */
  int y; /* I prefer repeats */
};


Now we know our function signature.
Code:
CB*compress(SEQUENCE*dna) {
  ;/* your code here */
}


Dreadfully different from your concept!

Please read the documentation for a function you might find useful,
malloc
__________________
[code]Code tags[/code] are essential for python code!

Last edited by b49P23TIvg : December 4th, 2012 at 07:55 PM.

Reply With Quote
  #3  
Old December 5th, 2012, 12:26 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,905 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 1 h 9 m 41 sec
Reputation Power: 1774
AAAGTTTACACCT
A3G1T3A1C1A1C2T1

It's hardly "compression" when the result is longer than what you started with.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #4  
Old December 5th, 2012, 04:32 AM
mitakeet's Avatar
mitakeet mitakeet is offline
I'm Baaaaaaack!
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jul 2003
Location: Maryland
Posts: 5,538 mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 38 m 46 sec
Reputation Power: 242
A new and exciting homework problem. I guess the OP couldn't be bothered with searching the archives, eh?
__________________

My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
Free code: http://sol-biotech.com/code/.
Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
--Me, I just made it up

The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
--George Bernard Shaw

Reply With Quote
  #5  
Old December 5th, 2012, 05:38 AM
ptr2void ptr2void is offline
I haz teh codez!
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Dec 2003
Posts: 2,511 ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 24 m 43 sec
Reputation Power: 2274
They would have found their own question!

I actually wrote this program for fun at that time. Biology fascinates me.
Comments on this post
salem agrees: I thought it looked familiar - nice catch
__________________
I ♥ ManiacDan & requinix

This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!

Reply With Quote
  #6  
Old December 5th, 2012, 05:52 AM
mitakeet's Avatar
mitakeet mitakeet is offline
I'm Baaaaaaack!
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jul 2003
Location: Maryland
Posts: 5,538 mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 38 m 46 sec
Reputation Power: 242
You might be interested in the National Center for Biotechnology Information (www.ncbi.nlm.nih.gov), they have a toolkit that does all sorts of biology related stuff, including compression of DNA sequences.

Reply With Quote
  #7  
Old December 5th, 2012, 06:38 AM
machupicchu machupicchu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 21 machupicchu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 52 m 44 sec
Reputation Power: 0
I would write the compress function like this, I have already counted my molecules and I want to compress it. I dont know how can I do it in array, but here I tried something. Below you will see my complete program.

c Code:
Original - c Code
  1. //This function will display all the element(s) in the linked list
  2. void compress()
  3. {
  4.     struct node *q;
  5.     if(start == NULL)
  6.     {
  7.         printf ("\n\nList is empty");
  8.         return;
  9.     }
  10.     q=start;
  11.     printf("\n\nList is : ");
  12.     int A = 0, G =0, T =0, C = 0;
  13.     double An = 0, Gn =0, Tn=0, Cn=0;
  14.     while(q!=NULL)
  15.     {
  16.        
  17.         if(q->info=='A'){A++;}
  18.         if(q->info=='G'){G++;}
  19.         if(q->info=='T'){T++;}
  20.         if(q->info=='C'){C++;}
  21.        
  22.         q=q->link;
  23.     }
  24.     An =A;
  25.     Gn =G;
  26.     Tn =T;
  27.     Cn =C;
  28.     printf ("\n");
  29.     printf ("%c, %d, %c, %d, %c, %d, %c, %d",
  30.     q->info, An, q->info, Gn, q->info, Tn, q->info, Cn, );
  31.    
  32. }/*End of compress() */











This is my complete programm!



c Code:
Original - c Code
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. //Structure declaration for the node
  5. struct node
  6. {
  7.     char info;
  8.     struct node *link;
  9. }*start;
  10.  
  11.  
  12. //This function will create a new linked list
  13. void Create_List(char data){
  14.     struct node *q, *tmp;
  15.     //Dynamic memory is been allocated for a node
  16.     tmp= (struct node*)malloc(sizeof(struct node));
  17.     tmp->info=data;
  18.     tmp->link=NULL;
  19.     if(start==NULL)
  20.     /*If list is empty*/
  21.         start=tmp;
  22.     else{
  23.         /*Element inserted at the end*/
  24.         q=start;
  25.         while(q->link!=NULL)
  26.         if(q->info=='A'){A++;}
  27.         if(q->info=='G'){G++;}
  28.         if(q->info=='T'){T++;}
  29.         if(q->info=='C'){C++;}
  30.         q=q->link;
  31.         q->link=tmp;
  32.  
  33.     }
  34. }
  35.  
  36.  
  37. //This function will display all the element(s) in the linked list
  38. void Display()
  39. {
  40.     struct node *q;
  41.     if(start == NULL)
  42.     {
  43.         printf ("\n\nList is empty");
  44.         return;
  45.     }
  46.     q=start;
  47.     printf("\n\nList is : ");
  48.     while(q!=NULL)
  49.     {
  50.         printf ("%c", q->info);
  51.         q=q->link;
  52.     }
  53.     printf ("\n");
  54.    
  55. }/*End of display() */
  56.  
  57. void Count(int inputMax, char comp)
  58. {
  59.     struct node *q;
  60.     if(start == NULL)
  61.     {
  62.         printf ("\n\nList is empty");
  63.         return;
  64.     }
  65.     q=start;
  66.     printf("\n\nList is : ");
  67.     int A = 0, G =0, T =0, C = 0;
  68.     double Afinal = 0, Gfinal =0, Tfinal=0, Cfinal=0;
  69.     while(q!=NULL)
  70.     {
  71.         if(q->info=='A'){A++;}
  72.         if(q->info=='G'){G++;}
  73.         if(q->info=='T'){T++;}
  74.         if(q->info=='C'){C++;}
  75.         printf("%d \n",C);
  76.         q=q->link;
  77.        
  78.        
  79.     }
  80.     printf ("\n");
  81.    
  82.     Afinal =A;
  83.     Gfinal =G;
  84.     Tfinal =T;
  85.     Cfinal =C;
  86.    
  87.     Afinal =(Afinal/inputMax)*100;
  88.     Gfinal =(Gfinal/inputMax)*100;
  89.     Tfinal =(Tfinal/inputMax)*100;
  90.     Cfinal =(Cfinal/inputMax)*100;
  91.  
  92.     printf("\nA: %lf", Afinal);
  93.     printf("\nG: %lf", Gfinal);
  94.     printf("\nT: %lf", Tfinal);
  95.     printf("\nC: %lf", Cfinal);
  96.    
  97. }/*End of count()*/
  98.  
  99. int main()
  100. {
  101.     unsigned choice,n,i, s=0;
  102.     char m;
  103.     do
  104.     {
  105.         printf("\n 1. Create List\n");
  106.         printf("\n 2. Display \n");
  107.         printf("\n 3. Count\n");
  108.         printf("\nEnter your choice (0 to 3)\n");
  109.         scanf("%d",&choice);
  110.        
  111.         switch (choice)
  112.         {
  113.             case 1:
  114.                 printf ("\n\nHow many nodes you want:");
  115.                 scanf ("%d",&n);
  116.                
  117.                 getchar();
  118.                 s = s + n;
  119.                 for(i = 0;i<n;i++){
  120.                     printf ("\nEnter the element:");
  121.                     scanf ("%c",&m);
  122.                     getchar();
  123.                     if(m == 'A'|| m == 'G'||m == 'T'||m == 'C')
  124.                     {
  125.                         Create_List(m);
  126.                     }
  127.                     else
  128.                     {   printf("-----------------------------------");
  129.                         printf("\nInvalid Element! Try again!\n");
  130.                         printf("-----------------------------------");
  131.                         i--;
  132.                     }
  133.                    
  134.                 }
  135.                 break;
  136.             case 2:
  137.                 Display();
  138.                 break;
  139.             case 3:
  140.                 Count(s, m);
  141.                 break;
  142.             default:
  143.                 printf("-----------------------------------");
  144.                 printf ("\nWRONG CHOICE!");
  145.                 printf("-----------------------------------");
  146.         }
  147.     }
  148.     while (choice !=0);
  149.    
  150.     return 0 ;
  151. }

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Dna compress

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap