Find strings in array using C#.Net [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I built an app of Numerology based on Name.
I'm beginner using C#.net and I have trouble of functions when I input name.
It's only 1 character that the program was detected.
For Example : Jane is not contained in Arrays but only J is contained in Arrays.
I really appreciate if someone gives another simple algorithms.
string[] Array0 = { " " };
string[] Array1 = { "A", "J", "S" };
string[] Array2 = { "B", "K", "T" };
string[] Array3 = { "C", "L", "U" };
string[] Array4 = { "D", "M", "V" };
string[] Array5 = { "E", "N", "W" };
string[] Array6 = { "F", "O", "X" };
string[] Array7 = { "G", "P", "Y" };
string[] Array8 = { "H", "Q", "Z" };
string[] Array9 = { "I", "R" };
string tempName = Name.ToUpper();
foreach (string x in Array1) {
if (x.Contains(tempName))
{
Response.Write("Your name is contained in Array");
}
else {
Response.Write("Your name is Not Contained in Array");
}
}

Try this:
List<string[]> _array = new List<string[]>() { new string[] {"A", "J", "S"}, new string[] { "B", "K", "T" },new string [] {"C", "L", "U"},
new string[] {"D", "M", "V"}, new string[] { "E", "N", "W" }, new string[] { "F", "O", "X" },
new string[] { "G", "P", "Y" },new string[] { "H", "Q", "Z" }, new string[] { "I", "R" }};
bool _result = _array.Select(a => a.Any(s => Name.ToUpper().Contains(s))).FirstOrDefault();
if(_result)
Response.Write("Your name is contained in Array");
else
Response.Write("Your name is Not Contained in Array");
This code will check for any occurance of Name in array list.

Related

What is the mistake in this code for generating a random password? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have written this code to generate a random password. When I run it I get an error saying that public Main() method is supposed in public class.
using System;
namespace Rnadom_Password_generator
{
class Program
{
void Main()
{
string[] allCharacters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "U", "V", "W", "Q", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "7", "9", "0", "!", "#", "#", "$", "%", "^", "&", "*", "(", ")", "-", "=", "+", "*", "/"};
string password = "";
Random character = new Random();
int passwordLength = 10;
for (int i = 0; i < passwordLength; i++)
{
int rnadomNum = character.Next(0, allCharacters.Length);
password += allCharacters[rnadomNum];
Console.WriteLine(password);
}
}
}
}
What should I do?
Make sure your main method is static. Like this.
using System;
namespace Rnadom_Password_generator
{
class Program
{
static void Main(string[] args)
{
string[] allCharacters = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "U", "V", "W", "Q", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "7", "9", "0", "!", "#", "#", "$", "%", "^", "&", "*", "(", ")", "-", "=", "+", "*", "/" };
string password = "";
Random character = new Random();
int passwordLength = 10;
for (int i = 0; i < passwordLength; i++)
{
int rnadomNum = character.Next(0, allCharacters.Length);
password += allCharacters[rnadomNum];
Console.WriteLine(password);
}
}
}
}

StackOverflow with Random Name Generator in C# [duplicate]

This question already has answers here:
Random name generator in c#
(8 answers)
Closed 1 year ago.
using System;
namespace npcnames
{
class Program
{
static string RandomVowel()
{
Random rand = new Random();
string[] Vowels = new string[5] { "a", "e", "i", "o", "u" };
int index = rand.Next(Vowels.Length);
string Vowel = Vowels[index];
return Vowel;
}
static string RandomConsonant()
{
Random rand = new Random();
string[] Consonants = new string[21] { "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z" };
int index = rand.Next(Consonants.Length);
string Consonant = Consonants[index];
return Consonant;
}
static string MaleName()
{
string malename = RandomConsonant() + RandomVowel() + RandomConsonant() + RandomVowel() + RandomConsonant();
return MaleName();
}
static string FemaleName()
{
string femalename = RandomVowel() + RandomConsonant() + RandomVowel() + RandomConsonant() + RandomVowel();
return FemaleName();
}
static void generateFemaleName(int from, int to, int step)
{
for (int a = from; a <= to; a = a + step)
{
Console.WriteLine("Female:");
Console.WriteLine(a + FemaleName());
}
}
static void generateMaleName(int from, int to, int step)
{
for (int b = from; b <= to; b = b + step)
{
Console.WriteLine("Male:");
Console.WriteLine(b + MaleName());
}
}
static void Main(string[] args)
{
generateFemaleName(1,10,1);
Console.WriteLine();
generateMaleName(1,10,1);
}
}
Hi guys I'm new to coding and everything, if anyone can help me how to resolve this issue I would really appreciate it. Problem is that in my code I keep getting stack overflow and I don't know how to prevent it to execute my program normally. The purpose of the program is to generate male and female names of the random selected vowels and consonants in the list of 10 for each.
The issue is here:
static string FemaleName()
{
string femalename = RandomVowel() + RandomConsonant() + RandomVowel() + RandomConsonant() + RandomVowel();
return FemaleName(); // <== bam!
}
Change:
return FemaleName();
to:
return femalename;
The short story is the method is continually calling itself. It's exactly the same for MaleName().
Also, while we are fixing things, Random initialization should be outside the method:
private static Random rand = new Random();
static string RandomConsonant()
{
string[] Consonants = new string[21] { "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z" };
int index = rand.Next(Consonants.Length);
string Consonant = Consonants[index];
return Consonant;
}
It will be fixed if you change
return MaleName();
to
return malename;
and the same for
return FemaleName();
to
return femalename;
It is the string that you want to return.

Adding multiple values on list

Is it possible to add multiple items into list or adding a list of values into a list.
here is my current pseudo code to do it:
List<string> myList = new List<string>();
myList.add("a","b","c","d","e","f","g");
myList.add("h","i","j","k","l","m","n");
myList.add("a1","a2","a3");
and my expected result is:
[["a","b","c","d","e","f","g"], ["h","i","j","k","l","m","n"], ["a1","a2","a3"]]
Any suggestions/comments TIA.
What you are asking for is a List<List<string>>. There are probably better structures for storing your data but since you haven't given any context, you can do this:
var myList = new List<List<string>>();
And add items like this:
myList.Add(new List<string> { "a", "b", "c", "d", "e", "f", "g" });
myList.Add(new List<string> { "h", "i", "j", "k", "l", "m", "n" });
myList.Add(new List<string> { "a1", "a2", "a3" });
Or in one piece of code using a collection initialiser:
var myList = new List<List<string>>
{
new List<string> { "a", "b", "c", "d", "e", "f", "g" },
new List<string> { "h", "i", "j", "k", "l", "m", "n" },
new List<string> { "a1", "a2", "a3" }
};
Should be as easy as
var myList = new List<List<string>>()
{
new List<string> { "a", "b", "c", "d", "e", "f", "g" },
new List<string> { "h", "i", "j", "k", "l", "m", "n" },
new List<string> { "a1", "a2", "a3" },
};
// OR
var myarray = new[]
{
new[] { "a", "b", "c", "d", "e", "f", "g" },
new[] { "h", "i", "j", "k", "l", "m", "n" },
new[] { "a1", "a2", "a3" },
};
Additional Resources
Object and Collection Initializers (C# Programming Guide)
C# lets you instantiate an object or collection and perform member
assignments in a single statement.
Collection initializers
Collection initializers let you specify one or more element
initializers when you initialize a collection type that implements
IEnumerable and has Add with the appropriate signature as an instance
method or an extension method. The element initializers can be a
simple value, an expression, or an object initializer. By using a
collection initializer, you do not have to specify multiple calls; the
compiler adds the calls automatically.

Moving specific elements after others but not to top or bottom

Assume I have an array of
{ "w", "w", "z", "a", "c", "r", "f", "d", "e", "c", "g", "f", "m", "z" }
and I have a rule that all "c" should be moved before "f".
The goal to to keep as closest order to the original as possible while following the rule(s).
A real world example is a an app which knows that some plugin "A" should be higher than some plugin "B" in a load list.
So the expected result would be:
Moved c before first f:
{ "w", "w", "z", "a", "c", "r", "c"<<, "f", "d", "e", "g", "f", "m", "z" }
or
Moved f after last c:
{ "w", "w", "z", "a", "c", "r", "d", "e", "c", >>"f", "g", "f", "m", "z" }
Is it possible to use LINQ or anything ready for such purpose?
I tried OrderBy(x => x == "c" ? 0 : x == "f" ? 1 : (int?)null) but it moves elements to the end instead. I want to sort only specific elements with each other but keep their position relatively to other elements when possible.
UPDATE
The solution should work for any inputs:
public static char GetLetter(Random rand)
{
string chars = "abcdefghijklmnopqrstuvwxyz";
int num = rand.Next(0, chars.Length - 1);
return chars[num];
}
public static IEnumerable<string> Sort(IEnumerable<string> enumerable, string first, string second)
{
???
}
static void Main(string[] args)
{
Random rand = new Random();
string[] input = Enumerable.Range(1, 10).Select(x => GetLetter(rand) + "").ToArray();
var result = Sort(Sort(input, "c", "f"), "m", "e");
}
Supporting multiple elements ("m", "c", "f") and multiple rules is desirable if it doesn't complicate things too much.
This method does what you want:
public static IEnumerable<string> Sort(this IEnumerable<string> enumerable, string first, string second)
{
return enumerable.TakeWhile(s => s != second)
.Concat(enumerable.SkipWhile(s => s != second).OrderBy(a => a != first));
}
The idea is that first the part of the list is taken until the first f (in this case). Then the remaining part is appended to it, sorted by the c characters first.
A drawback is that the list is enumerated twice (partly). If this is performance-critical you should go for an alternative that enumerates only once.
This is a solution:
string[] ch = {"a", "c", "f", "d", "e", "c", "g", "f", "m"};
var res = ch.Select((item, index) => new { item, index })
.OrderBy(x => x.item == "c" ? 0 : Convert.ToInt32(x.index))
.Select(c => c.item).ToArray();
The output:
If In understood your question correctly I think you need to have a array rules in which you will defined the rules like which character should come first. Here I am adding a test considering your seniors. You can modify the rules and use it.
[Test]
public void CustomOrderByTests()
{
char[] ch = { 'a', 'c', 'f', 'd', 'e', 'c', 'g', 'f', 'm' };
char[] rules = { 'a', 'f', 'c' };
var result = rules.Intersect(ch).Union(ch);
char[] expected = { 'a', 'f', 'c', 'd', 'e', 'g', 'm' };
CollectionAssert.AreEqual(result, expected);
}
If you want duplicate element at same position before use Array.Sort() overload it will short the result without removing the duplicates
Array.Sort(rules, ch);
now your ch array will have sorted array.

How to complete getting substrings of a genome encoding a given amino acid sequence

The Peptide Encoding Problem consists on Finding substrings of a genome encoding a given amino acid sequence.
The genetic code describes the translation of an RNA 3-mer (codon) into one of 20 different amino acids. The first three circles, moving from the inside out, represent the 1st, 2nd, and 3rd nucleotides of a given codon. The 4th, 5th, and 6th circles define the translated amino acid in three ways: the amino acid’s full name, its 3-letter abbreviation, and its single-letter abbreviation. Three of the 64 total RNA codons are stop codons, which halt translation and implicitly add a 21st stop symbol to the amino acid alphabet.
The problem consists on having
Input: A DNA string Text and an amino acid string Peptide.
and
Output: All substrings of Text encoding Peptide (if any such substrings exist).
Sample Input:
ATGGCCATGGCCCCCAGAACTGAGATCAATAGTACCCGTATTAACGGGTGA
MA
Sample Output:
ATGGCC
GGCCAT
ATGGCC
the result is gotten by reading triplets so, ATGGCC encodes MA, GGCCAT inverse would be CCGGTA written backwards so it is in fact ATGGCC (CCGGTA.reverse)
the complement of genetic code is C-G, G-C, T-A and A-T
So to solve this problem I first use already defined arrays
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
using System.Collections;
class Program
{
private static string[] CODONS = {
"TTT", "TTC", "TTA", "TTG", "TCT",
"TCC", "TCA", "TCG", "TAT", "TAC", "TGT", "TGC", "TGG", "CTT",
"CTC", "CTA", "CTG", "CCT", "CCC", "CCA", "CCG", "CAT", "CAC",
"CAA", "CAG", "CGT", "CGC", "CGA", "CGG", "ATT", "ATC", "ATA",
"ATG", "ACT", "ACC", "ACA", "ACG", "AAT", "AAC", "AAA", "AAG",
"AGT", "AGC", "AGA", "AGG", "GTT", "GTC", "GTA", "GTG", "GCT",
"GCC", "GCA", "GCG", "GAT", "GAC", "GAA", "GAG", "GGT", "GGC",
"GGA", "GGG", };
private static string[] AMINOS_PER_CODON = {
"F", "F", "L", "L", "S", "S",
"S", "S", "Y", "Y", "C", "C", "W", "L", "L", "L", "L", "P", "P",
"P", "P", "H", "H", "Q", "Q", "R", "R", "R", "R", "I", "I", "I",
"M", "T", "T", "T", "T", "N", "N", "K", "K", "S", "S", "R", "R",
"V", "V", "V", "V", "A", "A", "A", "A", "D", "D", "E", "E", "G",
"G", "G", "G", };
private static string[] AMINO_ABBREVIATIONS = {
"F", "L", "I", "M", "V",
"S", "P", "T", "A", "Y", "H", "Q", "N", "K", "D", "E", "C", "W",
"R", "G" };
private static string[] FULL_NAMES = {
"phenylalanine", "leucine",
"isoleucine", "methionine", "valine", "serine", "proline",
"threonine", "alanine", "tyrosine", "histidine", "glutamine",
"asparagine", "lysine", "aspartic acid", "glutamic acid",
"cysteine", "tryptophan", "arginine", "glycine" };
static void Main()
{
//then input is DNA
string dna = "TTCGAATCCGTATTGCTTTGGTTGGTTGAGAGAGCGACCTACATTGCTAGTCAGAATAGGTGATTCACACAAAGCTTAGCACCTGGGCAGCACCCCGTGATGTAAACCTATGGGAACTAAGGGAGTCCTGCGGTTTTAGCCAGCAAGCGAGCCGGCAGGAACACTCATACCATCGGACGCGTTTGACGCCTCCCCGGAAAGGAAGTATTTGAGCCTCATTATTACGTATTGCCCGTTAGTCGACAAATCAAGCCCTCGTACGCAGCTTATTCGTACGACGTGGAGGCGTTCCCACGGGCCTAACACGATTGGAACACCACCATAGTAGTGTGGTTCAAATACCTCCTTTGGAGATCTAGAGCTTCACTCTGATTCTAGAGGCAACTTTACAATCGCTCTACGAAATTGTATGGACATCATCAACCGGATATTCTGGGGCGGTAGAATTTCTTTTGTTCGAATCGCTCTAGGCCAGGATCAAATTAATTGAATTGCGGACTCAAGGATCGCGATAGCCGACACATCGGACGCTGTAGAAAGCCAGTCTCTGGATTTAATCCACCCTCTATGTTTGACAAAGCACTAAAACGGGATAGTTTCGGGTGGTATAAGTTTCCCAAGACGATTGCATCGCAATTCATCAACAACCATGAACTTACTGTTTTAGTACTTCCACACACCTTGTTAAATTACGCCTTTACTTCATGTTGCGGTGTGTGTTAGATAGTGTGCAGCTACAAGTCTACCGCCATCGCAGCTCGGGATACCGGCAGATGAGATGGTCCTGAGCTCGTACCGGACTCAAACTTTTTCCTTTACTACCTAGGAATCGCCCATGCGAATTTGTCGGACACACACCATTACATTAACGTCACAACAGCTACTGTTAGAATTTTGCTCTTGCAAATCCTGGAAAGAGTTAAAAAAACTCTTCCGCGCGCCAATAGGGTAAATAATAGATAGCCAGACGGCTGTAAGAGGTGATGACATTTGCAACAATCATGCTGTCGCATCTTCCGCAAGTTCATGTCGCGCCTAGGCAATGGATCTGCGAATGGGGGCCACGGGGTATGAACTACGGAATTCTAAGAAAGTTGCCATCCAGAGTTAAGGGTTTGAGGCTAGTTGCATCGCTGGTAACGAACTACCTCATTACTTGGACGCGCAGTGTGACTTCACTCCTGTATAGCGATGATGCCAAGCAGGAATTAGCAAATCTGAAGAGCGTTTCCAAACTGGCCACTTGGACTGACACCTATCGCGGGGGATTTCAGCGCGTGTCGCTCTCACATGAGAGCTGCCGTCAGGAGCGGTAGAGTTTAGAGAGGAATGCGACAAACTCCCTATTCACCTCTCTGGTGATGTAAGGATATTTACGCTTAGTTCTATGCCAGGCTTAGGGCCTCTCGGAACTTTGGTGAGTCCTTATTAATTGATGCTACCTCTCCCTTACCTTCGCCCCAAGTCACGTAGAAGTACTCAATCCTGCTACATGATAATCAAATATTTCCAACGTTGGGAAATCGGTGACATCACATACTAGTTAAGAAACCACTGTCAGTGAACTTATATCCGGGGGAGAAAATCTACTAACTTACATACGCTGTGCGAGCAGTTTTCATTATAAGAAAATATACTCCCGAGGTACCGCATCAAGCACGACATTCCCGGAGAGCATAACATTTCGGTGCACCTGCTTTTGTGCGCTTGCTTGCGGTTATTTATAAACTACGCACAAGGCGCAAACCGCAGTGCGCATGTTTTCTCCGCCTGGCTAGAACTCGACATTCTCGTCAACGCCAATCTATGTGAGAGGATTTAGACCTCTGTGAAAACGAGTCCCTCTATAGAATAAATACCCAGATGCCAATGGGGGTTCTATCCGATGGCAGTGCATGGAGTGGTGGCTCCAGATTAAGGATGAGGAGAGGTAAAGATAACAGTTCGGTCGCCACGACGCGTTGCCAATCGAAATATCAGTACTAAAAGGCCCACCGCTCCGCTTTAGTCCGACTTTACATCCTGTGGAAATTGTCGAACGGAGGCTACATCGGGCTATATGAGTGTGAAAACCTATACTTCTCGCGTCGTTACTCAGTGCCGGTCTCCTGTTTCCCCCAGTCTTACGTACCCTTATTGATATTTGCTTCACGTTGAAACGTCCTAACGCAGCGTAAAGAGGTGTTTGAACCTCATTACTATAAAATCGCGATCGAAGGTAGACTACATACGCAAACGCCGAAACCCTCAGTTGGCCTTGTTGCAAGTATGGAACGTTGTAAAATTTTTCCTAGACGTTGAGCTATCGGTACAAGGTCGTTAGCGTCCTTACCCTTCACTTATATGCCCGACAAAACGCGGGTCCTAGTGCAGTGGTGGGAGCTTGGAATCCCGCAATACAAGGACAACCTGTATCTCGTTCGGCGTTCCGCGATCACTCGATCCCGAACCACTCCAAGCCTGGTTGATCAGCAAAAGCGGAAGGATGGATAAAGGGCTACTGGTTAATGGATGTAAACTTCCAATGATGAAATCCTGGAAACGAGGGATCGGGTTACGGTGGCGAACGGGGTACGGCAACGTGGCTATCTAGAGCCCGACGTTACGACTCATGTACATGCTGCTACGTGGTTGAAGCTGACGTTCAGATGAAGCAGTACTGAGTCCTAGGGCTTACTACTACTCCAATAGGTCTGGCCGGCCAGATACAAAAGTTCGTGGCGGCTCACCCCCTTTCTGGCGGGTGTAGCTTGCTGACCGGTTTGCTCGATAACACAGGCTAGCGAATAGTAATGAGGTTCGAAAACCTCTTTCCAACGACTGAAAGGGTCTACACGAACTATCTACATTTCCCCGCCCATGTCCTTCCGTCTGGTTGCTTCTGGAGATCCTTTCGCATTATACCGCAGCGTAGTGGCTCTGGCATATATGAAAAAATCCTTCTGTGGGTATTTGTGCCATCACTTATTGTTCGTACCGATATGGGATTACAAGTGCGATGTGATAATAAGCGAAGAAGCCAACATGTTACACTGTTCATGCGCTCCGGGTAATGTGCGGGCACCATGCTCAGTTCCCGCTCGCAGTTGTCACTGTCCCTGTTTCGGCACCATAATCAACATTTCCACGGCCACGCTGGTGAATAACCGAGGATACCGAAGTACAGCAAGAATGAGAGCGGGACTCCTCCATCTGCTTGTAATACGCCTTCAAGATAGTCCATAAAACGGTCGGGGTCTTGTTTCGGACTAGCCGCTTTGAAACGGTGCATAGTTGTGTCAAGTGTGGACATTGGCTTTCTATCCTCGTCAGCGATCCTCGGAAAGACTCGGGCAGTCGCCCCGAATCGTAATTAGGTAGTAGTGCGGCTCAAAAACTTCCTTCGACCTAACCGCTATAATGTTCGTAGATATAAATTTCGTTTCAGTATTAACAGGCGCACCGTATATATACGGAATGGTGTCGCCCCATTAGCTGCTCGCCAATATTTATCTAAGACCGCGCGCGTCTAGCGCCTTTAGTAGTTGCACCCGAGTATAGTAATGGGGTTCGAAGACTTCCTTCGCAAGGCTGCCATACTGTATCACAAGTACTGACGGAGCCCCGGAGGAGTGCAGGATACGGCAAAGGAGACCATTACCGGGGCATGAGTCCAAGTTAGCCCGTTAGGTGAAGGACGCTGATACAATAGTGAATCCGTTACTGAAAGGTTTAGAAGACCGGGGGGCTCGCACTAGGTCCAAATATTATGAACCCTACTCCTGCAACTGAATTGGCCGTCCAGGCGATATTTAAAAGGGGTTACTAGCAGGTTCATCGGAGCCCGTACTCCTTCCGGGCATAGTCGTTCGACGGGTAGAAATTCATCCAGTCGTGCCGGATACCCCGAGAATACCCCTATTTTTTGATCCTTCACCATCATCGTCCGCGGACTCATCTAAGTACCTCAGACCGAAACTGTTATCGTAGCGAAGAGCGAACTCGAATGACATCGCTTGTCCAACAGGGAAAATATGTAAAGTATATGCAGATTATTATAGGAAGATCACAAACTCCATCGCGCCTAGGCCAAAGACTTGCCAGAACAACATCTCTTCCAGAGCAAGGAAGTGTTTGAACCTCACTATTATCGAGAGAAGTCCCATGAATTTATAATAGTGAGGCTCAAAAACTTCCTTCATCGTCGGGCGCTGGGGCGAGCTAGGCTTCCCTAGCCGTCATTACTGTACCCACGCCAAATATTATCGAGTATGACTACGAAGCCTTCACAAGGGGCTGCAGTAACAGACTAACTCACGCACACCGCAACTACTATCCTAAATTGAGTAAGAAAACCCTCGACTATAGCCCTTGAATTAAATTCGCTATTTAAGGAAGACCGCGCTTCCGCTCGCCCGCGTATAGTTTACCAGTCCCAAGAAACATGTGTGGCCAGCCTACCTGAAGAGCTGTGTAAAGATAGATTCTGACATCCTCAAAAAGAAGTTTTCGAGCCGCACTACTACGCACGGAGCTCCGTTATTCAAGGCATGTCGAAGTACAGCGTGGTGGCCTCTCCTGTTCTCCACCCCAGCTAAACCCACCTTGTTCGAATTCGCGCAACTGTATATGACATGAACACTTACAGGGGTTAGAAGTTACTGCAACCAAGATAGAGCTCGTCGAAGTAATAGTGCGGTTCAAAAACTTCCTTCAATTGGTCTCATCACTTAAATTTAAGAGCTATTGTGAGTACAGGTACGGATGCGGCTTCAGTGGATCTTCAGCATTCATTCCTTGTAGTAATGGGGTTCGAAGACTTCCTTGCCAGGGTACCAAACAAGTCTTGCGCATCCTCCTCCCTAAGGAGGTATTTGAACCCCACTATTACCCACGATAGAACATGCAGGGTTTGATAGTGGAACACCTTTTAGAATCTGGGGATAAATTCCCAGGACTAATGTATGGCTGTAGTAATGAGGTTCAAAAACCTCCTTTTCAGGTGGATCGCAGGCCGTGCTGCCTCACAAGCTGGGACGCCGTCCACGGTATAGCCGGCGTCGGCAGTTACTGTGAAATAGCGGAAACTCGATCCCAATATATCATCTTACGTTTGGCGCCCAATAGTCGCCCAGTACCCGTTGACAGTTCTTTAACTCGGCTTAGAACTACTAGACAGGTTCAACCGAACCTTGCCCTAGTTCCCACTCCCGTAATTCATTTGGGTTTGCATCTAGAATACTGGAGGGTGCATAGACGAAACGTGTACGTCGGAGAAAACGTAAGAAAATGACCTAGACTCATAGTAGTGAGGTTCGAAGACTTCCTTTCAGTGAAATCGATCCACCACTCGCCGCGAAGAGATAATAGCATAGAGCACAAGTGCGCGAGTAGAGAAAAAGGCTATCCCAACCGGGCACGTCCTTCGTGTTTGGCGTTTACATACGGCACCCCGTTTCTGCACGTTAACCGTCTAGTATCCAACGGTGGATGGCGGACGCTAGACTATAGATATGAGATATCGAGACCTGGAGCTGGGTGTGGCTGCAGCCCGGGTCATTGCGGGCTGTGAATTCAAGGGCATGTAAACAAGCGTATATCGAACAGTGGATGGGCACCTGCAATACTCACGGTAGAGTTAGCTCACAGGATTCACGTTGAGGACTATGAGTCCCTCTTCGCTAGCAGTCTGGGGGGATATGGAGTTTAATAGCTTGACGTAGTAATGGGGCTCAAACACCTCTTTGTGTGAGCACAGCTACTTGCATTAAGAGATTCTAAACAGCGATCATCTCGGCTATTTCGGGCCAGCCTTTTCGGCAGGATGTTATGTAGCATTTCTGGAAGCTTCCCCCTCGAATCTACTAGTGGTGAGAAGATGCCCCACCGATATTACTCTTTAATCTTGAGAAACCTAAAACCGATCTGACCTCAGACGGGCGGCTCCCACCCGAGGATAAACTCGTCAATAATAATGTGGCTCGAACACTTCTTTTCTCACTAGGCTTTTACGACACGCCACATGTATTTAAGCATCTACCTAACTTGTGTCTGCTGATATACAGCGCATTCTACGCCCAACCTACCAATTACTTCAACGTAGTGCGTGGCTAAAATTCAGGGGAGCTTCATCTCTGTCTTAATTTGAAGGTTCTTCCGGGGCGTTTGGGAATCTTCGTGCCTTTTGCGAGGTTAAGGTATCAAAGAAGTTTTCGAACCACATTATTACCGCCTTAAGCACCGGCGCATCCTGCTCGTGACAACTCTACCCTGCCCTGATAAAGGCACTGAACGTTCCAGAGAGTGCATCATTGACACGCGAGCAGGCCACAGTAGCCACAAGACGTATGGGTGATTATAGAATTGGTGGAGGTGTTGTTAACGATCAGGAGGACATTAGTGGGAGTTAGGAAAGACCCTATGTTCTCTCTATCGCGGACTTGTAACTTGACAAGCAAAAGGGTAAGAGAGCTGCACACCGAAGCAGGCCCTTCCTATACCTGTTTTTCCTACGCGTAGAGAGGAATCCAGAAAGGTGATAATTGGCATTCGATGAAAAAACAGTGTGCCACTGACTTAGTTCTATATGTGAAGAGCCTGTTAGCACGTGACGGCGGCCTTGGTATAGAGCCCTTAATGGTCTCCATCGCGTAGTAATGGGGCTCGAAAACCTCCTTACTTGGGATTGCGTGGCCTCCTTGTGAGTCATACACAAGGCTTAGGGCTATGGGGCGATACACTCCTTTTCGCGGCGCATGGGGCGGTGATGCCTACATAGTAGTAGTGACTGCCTTTCTGGGGGGCTATTTGTGGATGACCAACACCTGACCAGCGATGCAATCGCTAGGGGAGGTACACCTCTCATATGTTACAACAATCACCGAATTGTGTTTCGAATTCGAATCAAGTTTGCGGTGTCGACCAGATCTGGTCTTGCTGCCATACCGGGTTCGCCGCCTCCGGTGGATAGAACTGCATCTTAAGACATCTGGACCCAGCGGTAAGTAGCGGGAAGAGTTTAGAGTCATTCGTACAACTACAGGCTAAGGGCTTACTGGGGAGTTGTTGTAGGGCATAAAGATCGCCCCATGACTTTTCGTACTTTCCCCGATAGTTCACTCGCAGCGAGCTGCGGCTGGGCTTCGCCACACGAGTACGGGCAACATTTATCTCCTCTAATCACTGGGCACCGCGCGAGGAAATAGAAAACCCTAATCAGTGCTCATGGGCGCATCTATTGGTCTCCGCATGCACGATGCCGCGGAGTGCTTAGTTGTCCCTGCATAATCTTCGTAGATGTATAAGAGATTACCTATTTATTCGGTTTCGGTTCTAGACGTACCTTGCCGCATGAGTATAGGCTAATGAACTGAGTTGGCGCCAGAGGGAAAGGCATAATAATGCGGCTCGAATACTTCCTTAAGGAAGTATTCGAACCACATTACTAT";
//The given peptide
string givenPeptide = "KEVFEPHYY";
char[] givenPeptideArray = givenPeptide.ToCharArray() ;
string codon="";
string auxCodon="";
string convertedCodon = "";
string clean = "";
int pivot = 0;
int foundFlag = 0;
string cleanReverse = "";
int foundFlagReverse = 0;
string convertedCodonReverse = "";
//so the idea I was working was to loop dna string until getting to 3*givenPeptide.Length
//because dna is red 3 by 3...
//then get givenPeptide.Length and compare each char of given peptide with encoded
//letter of scanned triplet
//so for example first givenpeptide is 'M' so I would search for 'ATG'
//then, if found increment a counter and then search for next 'GCC' etc...
//however When testing with longer string I do not get complete result
//I have
for (int pos = 0; pos < dna.Length - (3*givenPeptide.Length) ; pos++) {
pivot = pos;
for (int codonPos = 0; codonPos < givenPeptide.Length; codonPos++)
{
codon = dna.Substring(pivot, 3);
auxCodon = givenPeptideArray[codonPos].ToString();
convertedCodon = codonToAminoAcid(codon);
convertedCodonReverse = codonToAminoAcid(DNAComplement(codon));
if (auxCodon.Equals(convertedCodon) )
{
foundFlag++;
clean += codon;
}
else
{
foundFlag = 0;
clean = "";
}
if (foundFlag == givenPeptide.Length)
{
Console.WriteLine(clean);
foundFlag = 0;
clean = "";
}
//reverse
if (auxCodon.Equals(convertedCodonReverse))
{
foundFlagReverse++;
cleanReverse += codon;
}
else
{
foundFlagReverse = 0;
cleanReverse = "";
}
if (foundFlagReverse == givenPeptide.Length)
{
Console.WriteLine(cleanReverse);
foundFlagReverse = 0;
cleanReverse = "";
}
pivot+=3;
}
}
}//end main
public static string DNAComplement(string dna)
{
char[] array = dna.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
char let = array[i];
if (let == 'A') array[i] = 'T';
else if (let == 'T') array[i] = 'A';
else if (let == 'C') array[i] = 'G';
else if (let == 'G') array[i] = 'C';
}
Array.Reverse(array);
return new string(array);
}
public static string codonToAminoAcid(String codon)
{
for (int k = 0; k < CODONS.Length ; k++)
{
if (CODONS[k].Equals (codon))
{
return AMINOS_PER_CODON[k];
}
}
// never reach here with valid codon
return "X";
}
}//end class
I should get
AAGGAAGTATTTGAGCCTCATTATTAC
AAAGAGGTGTTTGAACCTCATTACTAT
AAGGAGGTATTTGAACCCCACTATTAC
AAAGAAGTTTTCGAACCACATTATTAC
AAGGAAGTGTTTGAACCTCACTATTAT
AAAGAAGTTTTCGAGCCGCACTACTAC
AAGGAAGTATTCGAACCACATTACTAT
ATAATAATGCGGCTCGAATACTTCCTT
GTAGTAATGGGGCTCGAAAACCTCCTT
GTAGTAATGAGGTTCAAAAACCTCCTT
GTAGTAATGGGGTTCGAAGACTTCCTT
ATAATAGTGAGGCTCAAAAACTTCCTT
ATAGTAATGGGGTTCGAAGACTTCCTT
GTAGTAGTGCGGCTCAAAAACTTCCTT
ATAGTAATGAGGTTCGAAAACCTCTTT
ATAATAATGTGGCTCGAACACTTCTTT
GTAGTAATGGGGCTCAAACACCTCTTT
ATAGTAGTGAGGTTCGAAGACTTCCTT
GTAATAGTGCGGTTCAAAAACTTCCTT
ATAGTAGTGTGGTTCAAATACCTCCTT
However I am only getting:
AAGGAAGTATTTGAGCCTCATTATTAC
AAAGAGGTGTTTGAACCTCATTACTAT
AAGGAAGTGTTTGAACCTCACTATTAT
AAAGAAGTTTTCGAGCCGCACTACTAC
AAGGAGGTATTTGAACCCCACTATTAC
AAAGAAGTTTTCGAACCACATTATTAC
I was thinking on problem and It seems the problem is I am not looping all string each time...
It looks like the problem is two-fold. Your outer for loop doesn't go far enough to catch the very end of the dna string. Secondly, it appears that reversing individual codons doesn't work and that you have to take the entire (givenPeptideLength * 3) character string before getting the complement. The following changes output the strings you put in your example so I'm hopeful that it does what you want. It has the benefit of being much more concise as well.
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
using System.Collections;
namespace DNA
{
class Program
{
private static string[] CODONS = {
"TTT", "TTC", "TTA", "TTG", "TCT",
"TCC", "TCA", "TCG", "TAT", "TAC", "TGT", "TGC", "TGG", "CTT",
"CTC", "CTA", "CTG", "CCT", "CCC", "CCA", "CCG", "CAT", "CAC",
"CAA", "CAG", "CGT", "CGC", "CGA", "CGG", "ATT", "ATC", "ATA",
"ATG", "ACT", "ACC", "ACA", "ACG", "AAT", "AAC", "AAA", "AAG",
"AGT", "AGC", "AGA", "AGG", "GTT", "GTC", "GTA", "GTG", "GCT",
"GCC", "GCA", "GCG", "GAT", "GAC", "GAA", "GAG", "GGT", "GGC",
"GGA", "GGG", };
private static string[] AMINOS_PER_CODON = {
"F", "F", "L", "L", "S", "S",
"S", "S", "Y", "Y", "C", "C", "W", "L", "L", "L", "L", "P", "P",
"P", "P", "H", "H", "Q", "Q", "R", "R", "R", "R", "I", "I", "I",
"M", "T", "T", "T", "T", "N", "N", "K", "K", "S", "S", "R", "R",
"V", "V", "V", "V", "A", "A", "A", "A", "D", "D", "E", "E", "G",
"G", "G", "G", };
private static string[] AMINO_ABBREVIATIONS = {
"F", "L", "I", "M", "V",
"S", "P", "T", "A", "Y", "H", "Q", "N", "K", "D", "E", "C", "W",
"R", "G" };
private static string[] FULL_NAMES = {
"phenylalanine", "leucine",
"isoleucine", "methionine", "valine", "serine", "proline",
"threonine", "alanine", "tyrosine", "histidine", "glutamine",
"asparagine", "lysine", "aspartic acid", "glutamic acid",
"cysteine", "tryptophan", "arginine", "glycine" };
public static string DNAComplement(string dna)
{
char[] array = dna.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
char let = array[i];
if (let == 'A') array[i] = 'T';
else if (let == 'T') array[i] = 'A';
else if (let == 'C') array[i] = 'G';
else if (let == 'G') array[i] = 'C';
}
Array.Reverse(array);
return new string(array);
}
public static string StringToAminoAcid(String input)
{
string result = "";
for (int i = 0; i < input.Length; i += 3)
{
result += codonToAminoAcid(input.Substring(i, 3));
}
return result;
}
public static string codonToAminoAcid(String codon)
{
for (int k = 0; k < CODONS.Length; k++)
{
if (CODONS[k].Equals(codon))
{
return AMINOS_PER_CODON[k];
}
}
// never reach here with valid codon
return "X";
}
static void Main()
{
//then input is DNA
string dna = "TTCGAATCCGTATTGCTTTGGTTGGTTGAGAGAGCGACCTACATTGCTAGTCAGAATAGGTGATTCACACAAAGCTTAGCACCTGGGCAGCACCCCGTGATGTAAACCTATGGGAACTAAGGGAGTCCTGCGGTTTTAGCCAGCAAGCGAGCCGGCAGGAACACTCATACCATCGGACGCGTTTGACGCCTCCCCGGAAAGGAAGTATTTGAGCCTCATTATTACGTATTGCCCGTTAGTCGACAAATCAAGCCCTCGTACGCAGCTTATTCGTACGACGTGGAGGCGTTCCCACGGGCCTAACACGATTGGAACACCACCATAGTAGTGTGGTTCAAATACCTCCTTTGGAGATCTAGAGCTTCACTCTGATTCTAGAGGCAACTTTACAATCGCTCTACGAAATTGTATGGACATCATCAACCGGATATTCTGGGGCGGTAGAATTTCTTTTGTTCGAATCGCTCTAGGCCAGGATCAAATTAATTGAATTGCGGACTCAAGGATCGCGATAGCCGACACATCGGACGCTGTAGAAAGCCAGTCTCTGGATTTAATCCACCCTCTATGTTTGACAAAGCACTAAAACGGGATAGTTTCGGGTGGTATAAGTTTCCCAAGACGATTGCATCGCAATTCATCAACAACCATGAACTTACTGTTTTAGTACTTCCACACACCTTGTTAAATTACGCCTTTACTTCATGTTGCGGTGTGTGTTAGATAGTGTGCAGCTACAAGTCTACCGCCATCGCAGCTCGGGATACCGGCAGATGAGATGGTCCTGAGCTCGTACCGGACTCAAACTTTTTCCTTTACTACCTAGGAATCGCCCATGCGAATTTGTCGGACACACACCATTACATTAACGTCACAACAGCTACTGTTAGAATTTTGCTCTTGCAAATCCTGGAAAGAGTTAAAAAAACTCTTCCGCGCGCCAATAGGGTAAATAATAGATAGCCAGACGGCTGTAAGAGGTGATGACATTTGCAACAATCATGCTGTCGCATCTTCCGCAAGTTCATGTCGCGCCTAGGCAATGGATCTGCGAATGGGGGCCACGGGGTATGAACTACGGAATTCTAAGAAAGTTGCCATCCAGAGTTAAGGGTTTGAGGCTAGTTGCATCGCTGGTAACGAACTACCTCATTACTTGGACGCGCAGTGTGACTTCACTCCTGTATAGCGATGATGCCAAGCAGGAATTAGCAAATCTGAAGAGCGTTTCCAAACTGGCCACTTGGACTGACACCTATCGCGGGGGATTTCAGCGCGTGTCGCTCTCACATGAGAGCTGCCGTCAGGAGCGGTAGAGTTTAGAGAGGAATGCGACAAACTCCCTATTCACCTCTCTGGTGATGTAAGGATATTTACGCTTAGTTCTATGCCAGGCTTAGGGCCTCTCGGAACTTTGGTGAGTCCTTATTAATTGATGCTACCTCTCCCTTACCTTCGCCCCAAGTCACGTAGAAGTACTCAATCCTGCTACATGATAATCAAATATTTCCAACGTTGGGAAATCGGTGACATCACATACTAGTTAAGAAACCACTGTCAGTGAACTTATATCCGGGGGAGAAAATCTACTAACTTACATACGCTGTGCGAGCAGTTTTCATTATAAGAAAATATACTCCCGAGGTACCGCATCAAGCACGACATTCCCGGAGAGCATAACATTTCGGTGCACCTGCTTTTGTGCGCTTGCTTGCGGTTATTTATAAACTACGCACAAGGCGCAAACCGCAGTGCGCATGTTTTCTCCGCCTGGCTAGAACTCGACATTCTCGTCAACGCCAATCTATGTGAGAGGATTTAGACCTCTGTGAAAACGAGTCCCTCTATAGAATAAATACCCAGATGCCAATGGGGGTTCTATCCGATGGCAGTGCATGGAGTGGTGGCTCCAGATTAAGGATGAGGAGAGGTAAAGATAACAGTTCGGTCGCCACGACGCGTTGCCAATCGAAATATCAGTACTAAAAGGCCCACCGCTCCGCTTTAGTCCGACTTTACATCCTGTGGAAATTGTCGAACGGAGGCTACATCGGGCTATATGAGTGTGAAAACCTATACTTCTCGCGTCGTTACTCAGTGCCGGTCTCCTGTTTCCCCCAGTCTTACGTACCCTTATTGATATTTGCTTCACGTTGAAACGTCCTAACGCAGCGTAAAGAGGTGTTTGAACCTCATTACTATAAAATCGCGATCGAAGGTAGACTACATACGCAAACGCCGAAACCCTCAGTTGGCCTTGTTGCAAGTATGGAACGTTGTAAAATTTTTCCTAGACGTTGAGCTATCGGTACAAGGTCGTTAGCGTCCTTACCCTTCACTTATATGCCCGACAAAACGCGGGTCCTAGTGCAGTGGTGGGAGCTTGGAATCCCGCAATACAAGGACAACCTGTATCTCGTTCGGCGTTCCGCGATCACTCGATCCCGAACCACTCCAAGCCTGGTTGATCAGCAAAAGCGGAAGGATGGATAAAGGGCTACTGGTTAATGGATGTAAACTTCCAATGATGAAATCCTGGAAACGAGGGATCGGGTTACGGTGGCGAACGGGGTACGGCAACGTGGCTATCTAGAGCCCGACGTTACGACTCATGTACATGCTGCTACGTGGTTGAAGCTGACGTTCAGATGAAGCAGTACTGAGTCCTAGGGCTTACTACTACTCCAATAGGTCTGGCCGGCCAGATACAAAAGTTCGTGGCGGCTCACCCCCTTTCTGGCGGGTGTAGCTTGCTGACCGGTTTGCTCGATAACACAGGCTAGCGAATAGTAATGAGGTTCGAAAACCTCTTTCCAACGACTGAAAGGGTCTACACGAACTATCTACATTTCCCCGCCCATGTCCTTCCGTCTGGTTGCTTCTGGAGATCCTTTCGCATTATACCGCAGCGTAGTGGCTCTGGCATATATGAAAAAATCCTTCTGTGGGTATTTGTGCCATCACTTATTGTTCGTACCGATATGGGATTACAAGTGCGATGTGATAATAAGCGAAGAAGCCAACATGTTACACTGTTCATGCGCTCCGGGTAATGTGCGGGCACCATGCTCAGTTCCCGCTCGCAGTTGTCACTGTCCCTGTTTCGGCACCATAATCAACATTTCCACGGCCACGCTGGTGAATAACCGAGGATACCGAAGTACAGCAAGAATGAGAGCGGGACTCCTCCATCTGCTTGTAATACGCCTTCAAGATAGTCCATAAAACGGTCGGGGTCTTGTTTCGGACTAGCCGCTTTGAAACGGTGCATAGTTGTGTCAAGTGTGGACATTGGCTTTCTATCCTCGTCAGCGATCCTCGGAAAGACTCGGGCAGTCGCCCCGAATCGTAATTAGGTAGTAGTGCGGCTCAAAAACTTCCTTCGACCTAACCGCTATAATGTTCGTAGATATAAATTTCGTTTCAGTATTAACAGGCGCACCGTATATATACGGAATGGTGTCGCCCCATTAGCTGCTCGCCAATATTTATCTAAGACCGCGCGCGTCTAGCGCCTTTAGTAGTTGCACCCGAGTATAGTAATGGGGTTCGAAGACTTCCTTCGCAAGGCTGCCATACTGTATCACAAGTACTGACGGAGCCCCGGAGGAGTGCAGGATACGGCAAAGGAGACCATTACCGGGGCATGAGTCCAAGTTAGCCCGTTAGGTGAAGGACGCTGATACAATAGTGAATCCGTTACTGAAAGGTTTAGAAGACCGGGGGGCTCGCACTAGGTCCAAATATTATGAACCCTACTCCTGCAACTGAATTGGCCGTCCAGGCGATATTTAAAAGGGGTTACTAGCAGGTTCATCGGAGCCCGTACTCCTTCCGGGCATAGTCGTTCGACGGGTAGAAATTCATCCAGTCGTGCCGGATACCCCGAGAATACCCCTATTTTTTGATCCTTCACCATCATCGTCCGCGGACTCATCTAAGTACCTCAGACCGAAACTGTTATCGTAGCGAAGAGCGAACTCGAATGACATCGCTTGTCCAACAGGGAAAATATGTAAAGTATATGCAGATTATTATAGGAAGATCACAAACTCCATCGCGCCTAGGCCAAAGACTTGCCAGAACAACATCTCTTCCAGAGCAAGGAAGTGTTTGAACCTCACTATTATCGAGAGAAGTCCCATGAATTTATAATAGTGAGGCTCAAAAACTTCCTTCATCGTCGGGCGCTGGGGCGAGCTAGGCTTCCCTAGCCGTCATTACTGTACCCACGCCAAATATTATCGAGTATGACTACGAAGCCTTCACAAGGGGCTGCAGTAACAGACTAACTCACGCACACCGCAACTACTATCCTAAATTGAGTAAGAAAACCCTCGACTATAGCCCTTGAATTAAATTCGCTATTTAAGGAAGACCGCGCTTCCGCTCGCCCGCGTATAGTTTACCAGTCCCAAGAAACATGTGTGGCCAGCCTACCTGAAGAGCTGTGTAAAGATAGATTCTGACATCCTCAAAAAGAAGTTTTCGAGCCGCACTACTACGCACGGAGCTCCGTTATTCAAGGCATGTCGAAGTACAGCGTGGTGGCCTCTCCTGTTCTCCACCCCAGCTAAACCCACCTTGTTCGAATTCGCGCAACTGTATATGACATGAACACTTACAGGGGTTAGAAGTTACTGCAACCAAGATAGAGCTCGTCGAAGTAATAGTGCGGTTCAAAAACTTCCTTCAATTGGTCTCATCACTTAAATTTAAGAGCTATTGTGAGTACAGGTACGGATGCGGCTTCAGTGGATCTTCAGCATTCATTCCTTGTAGTAATGGGGTTCGAAGACTTCCTTGCCAGGGTACCAAACAAGTCTTGCGCATCCTCCTCCCTAAGGAGGTATTTGAACCCCACTATTACCCACGATAGAACATGCAGGGTTTGATAGTGGAACACCTTTTAGAATCTGGGGATAAATTCCCAGGACTAATGTATGGCTGTAGTAATGAGGTTCAAAAACCTCCTTTTCAGGTGGATCGCAGGCCGTGCTGCCTCACAAGCTGGGACGCCGTCCACGGTATAGCCGGCGTCGGCAGTTACTGTGAAATAGCGGAAACTCGATCCCAATATATCATCTTACGTTTGGCGCCCAATAGTCGCCCAGTACCCGTTGACAGTTCTTTAACTCGGCTTAGAACTACTAGACAGGTTCAACCGAACCTTGCCCTAGTTCCCACTCCCGTAATTCATTTGGGTTTGCATCTAGAATACTGGAGGGTGCATAGACGAAACGTGTACGTCGGAGAAAACGTAAGAAAATGACCTAGACTCATAGTAGTGAGGTTCGAAGACTTCCTTTCAGTGAAATCGATCCACCACTCGCCGCGAAGAGATAATAGCATAGAGCACAAGTGCGCGAGTAGAGAAAAAGGCTATCCCAACCGGGCACGTCCTTCGTGTTTGGCGTTTACATACGGCACCCCGTTTCTGCACGTTAACCGTCTAGTATCCAACGGTGGATGGCGGACGCTAGACTATAGATATGAGATATCGAGACCTGGAGCTGGGTGTGGCTGCAGCCCGGGTCATTGCGGGCTGTGAATTCAAGGGCATGTAAACAAGCGTATATCGAACAGTGGATGGGCACCTGCAATACTCACGGTAGAGTTAGCTCACAGGATTCACGTTGAGGACTATGAGTCCCTCTTCGCTAGCAGTCTGGGGGGATATGGAGTTTAATAGCTTGACGTAGTAATGGGGCTCAAACACCTCTTTGTGTGAGCACAGCTACTTGCATTAAGAGATTCTAAACAGCGATCATCTCGGCTATTTCGGGCCAGCCTTTTCGGCAGGATGTTATGTAGCATTTCTGGAAGCTTCCCCCTCGAATCTACTAGTGGTGAGAAGATGCCCCACCGATATTACTCTTTAATCTTGAGAAACCTAAAACCGATCTGACCTCAGACGGGCGGCTCCCACCCGAGGATAAACTCGTCAATAATAATGTGGCTCGAACACTTCTTTTCTCACTAGGCTTTTACGACACGCCACATGTATTTAAGCATCTACCTAACTTGTGTCTGCTGATATACAGCGCATTCTACGCCCAACCTACCAATTACTTCAACGTAGTGCGTGGCTAAAATTCAGGGGAGCTTCATCTCTGTCTTAATTTGAAGGTTCTTCCGGGGCGTTTGGGAATCTTCGTGCCTTTTGCGAGGTTAAGGTATCAAAGAAGTTTTCGAACCACATTATTACCGCCTTAAGCACCGGCGCATCCTGCTCGTGACAACTCTACCCTGCCCTGATAAAGGCACTGAACGTTCCAGAGAGTGCATCATTGACACGCGAGCAGGCCACAGTAGCCACAAGACGTATGGGTGATTATAGAATTGGTGGAGGTGTTGTTAACGATCAGGAGGACATTAGTGGGAGTTAGGAAAGACCCTATGTTCTCTCTATCGCGGACTTGTAACTTGACAAGCAAAAGGGTAAGAGAGCTGCACACCGAAGCAGGCCCTTCCTATACCTGTTTTTCCTACGCGTAGAGAGGAATCCAGAAAGGTGATAATTGGCATTCGATGAAAAAACAGTGTGCCACTGACTTAGTTCTATATGTGAAGAGCCTGTTAGCACGTGACGGCGGCCTTGGTATAGAGCCCTTAATGGTCTCCATCGCGTAGTAATGGGGCTCGAAAACCTCCTTACTTGGGATTGCGTGGCCTCCTTGTGAGTCATACACAAGGCTTAGGGCTATGGGGCGATACACTCCTTTTCGCGGCGCATGGGGCGGTGATGCCTACATAGTAGTAGTGACTGCCTTTCTGGGGGGCTATTTGTGGATGACCAACACCTGACCAGCGATGCAATCGCTAGGGGAGGTACACCTCTCATATGTTACAACAATCACCGAATTGTGTTTCGAATTCGAATCAAGTTTGCGGTGTCGACCAGATCTGGTCTTGCTGCCATACCGGGTTCGCCGCCTCCGGTGGATAGAACTGCATCTTAAGACATCTGGACCCAGCGGTAAGTAGCGGGAAGAGTTTAGAGTCATTCGTACAACTACAGGCTAAGGGCTTACTGGGGAGTTGTTGTAGGGCATAAAGATCGCCCCATGACTTTTCGTACTTTCCCCGATAGTTCACTCGCAGCGAGCTGCGGCTGGGCTTCGCCACACGAGTACGGGCAACATTTATCTCCTCTAATCACTGGGCACCGCGCGAGGAAATAGAAAACCCTAATCAGTGCTCATGGGCGCATCTATTGGTCTCCGCATGCACGATGCCGCGGAGTGCTTAGTTGTCCCTGCATAATCTTCGTAGATGTATAAGAGATTACCTATTTATTCGGTTTCGGTTCTAGACGTACCTTGCCGCATGAGTATAGGCTAATGAACTGAGTTGGCGCCAGAGGGAAAGGCATAATAATGCGGCTCGAATACTTCCTTAAGGAAGTATTCGAACCACATTACTAT";
//The given peptide
string givenPeptide = "KEVFEPHYY";
int resultCount = 0;
int candidateLength = givenPeptide.Length * 3;
string forward = "";
string backward = "";
for (int pos = 0; pos < dna.Length - candidateLength + 1; pos++) // Added the "+ 1"
{
forward = dna.Substring(pos, candidateLength);
backward = DNAComplement(forward);
// Unremark to get a glimpse into what is happening...
//Console.WriteLine("pos: {0}, forward: {1}, backward: {2}, forwardTranslation: {3}, backwardTranslation: {4}",
// pos, forward, backward, StringToAminoAcid(forward), StringToAminoAcid(backward));
if (
(StringToAminoAcid(forward) == givenPeptide)
||
(StringToAminoAcid(backward) == givenPeptide)
)
{
resultCount++;
Console.WriteLine(String.Format("Result {0,3} at position {1,6}... {2}", resultCount, pos, forward));
}
}
Console.WriteLine("Done");
Console.ReadLine();
}//end main
}//end class
}

Categories

Resources