UVA-1368 DNA Consensus String

Source: Internet
Author: User

DNA Consensus String
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &%llu

Submit Status

Description

Figure 1.DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of four different nucleotides, namely adenine, thymine, guanine, and cytosine as shown in Figure 1. If we represent a nucleotide by it initial character, a DNA strand can be regarded as a long string (sequence of characte RS) consisting of the four characters A, T, G, and C. For example, assume we were given some part of a DNA strand which was composed of the following sequence of nucleotides:


' Thymine-adenine-adenine-cytosine-thymine-guanine-cytosine-cytosine-guanine-adenine-thymine '


Then we can represent the above DNA strand with the string "Taactgccgat." The biologist Prof Ahn found that a gene X commonly exists in the DNA strands of five different kinds of animals, namely Dogs, cats, horses, cows, and monkeys. He also discovered the DNA sequences of the gene X from each animal were very alike. See Figure 2.


TD valign= "BASELINE" align= "left" Nowrap>cat:
  dna sequence of Gene X
GCATATGGCTGTGCA
dog: GCAAATGGCTGTGCA
horse: gctaatgggtgtcca
cow: GCAAATGGCTGTGCA
monkey: GCAAATCGGTGAGCA


Figure 2. DNA sequences of Gene X in five animals.


Prof. Ahn thought that humans might also has the gene X and decided to search for the DNA sequence of X in human DNA. However, before searching, he should define a representative DNA sequence of Gene X because its sequences is not exactly The same in the DNA of the five animals. He decided to use the Hamming distance to define the representative sequence. The Hamming distance is the number of different characters at each position from both strings of equal length. For example, assume we is given the strings 'Agcat"and"Ggaat." The Hamming distance of these, strings is 2 because the 1st and the 3rd characters of the and the strings of the. Using the Hamming distance, we can define a representative string for a set of multiple strings of equal length. Given a set of strings S = s1,..., smof lengthNThe consensus error between a stringyof lengthNand the SetSIs the sum of the Hamming distances betweenyAnd each siInchS. If the consensus error betweenyandSIs the minimum among all possible stringsyof lengthN,yis called a consensus string ofS. For example, given the three strings "Agcat" ``agact"and"Ggaat"The consensus string of the given strings is"Agaat"Because the sum of the Hamming distances between"Agaat"And the three strings is 3 which is minimal. The consensus string is a unique, but in general, there can be more than one consensus string.) We use the consensus string as a representative of the DNA sequence. For the example of Figure 2 above, a consensus string of gene X is 'GCAAATGGCTGTGCA"And the consensus error is 7.

InputYour program was to read from standard input. The input consists ofTTest cases. The number of test casesTis given on the first line of the input. Each test case starts with a line containing the integersmandNWhich is separated by a single space. The integerm(4m)Represents the number of DNA sequences andN(4n)Represents the length of the DNA sequences, respectively. In each of the nextmLines, each of the DNA sequence is given.OutputYour program is-to-write to standard output. Print the consensus string in the first line of all case and the consensus error in the second line for each case. If there exists more than one consensus string, print the lexicographically smallest consensus string. The following shows sample input and output for three test cases.Sample Input
3 5 8 Tatgatac taagctac AAAGATCC tgagatac taagatgt 4 acgtacgtac ccgtacgtag gcgtacgtat tcgtacgtaa 6 ATGTTACCAT AAGTTA Cgat AACAAAGCAA AAGTTACCTT AAGTTACCAA TACTTACCAA
Sample Output
Taagatac 7 Acgtacgtaa 6 AAGTTACCAA 12

 #include <iostream> #include <cstring> #include <string> #include < Cstdio>using namespace Std;char s[100][1005];int main () {int casen;cin >> casen;while (casen--) {int m, n;cin > > M >> n;for (int i = 0; i < m; i++) cin >> S[i];int A, C, G, T;char ans[1005];for (int i = 0; i < n;  i++) {A = C = G = T = 0;for (int j = 0; J < m; J + +) {switch (S[j][i]) {case ' A ': a++; break;case ' C ': C + +; Break;case ' G ': g++; Break;case ' T ': t++; Break;}} if (a >= c && a >= G && a >= T) ans[i] = ' a '; else if (C > a && c >= g && c >= t) ans[i] = ' C ', else if (G > C && g > A && G >= T) ans[i] = ' G '; else if (T > G && ; T > A && T > C) ans[i] = ' t ';} Ans[n] = ' n '; int sum = 0;for (int i = 0; i < m;i++) for (int j = 0; J < n;j++) if (s[i][j]! = ans[j]) sum++;cout <& Lt Ans << endl;cout << sum << Endl;}} 



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UVA-1368 DNA Consensus String

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.