C
C#2y ago
Rype

Sharing elements of 2 arrays into another array

So i got a char array that consists of the chars ATG AAA GGG TAG ATG AAA TAG ATG TGT TTG TAT TAG and another char array that consists of chars *ATG* CCC *TAG* *ATG* AAA CTA *TAG* *ATG* GGG *TAG* *ATG* GGG GCG CCG *TAG* *ATG* CCG CCG CCG *TAG* (no char that is blank(' ') - the spaces and are to show significance of ATG and TAG) What i want to do: I have a 3rd char array and i want to share one gene from first array(if any) and one from second array(if any) - and skip the corresponding gene from other array if i already shared a gene from the other array. If other array has no corresponding gene, share all remaining genes without skipping. One gene starts with ATG and ends with TAG. The third array should look like ATG AAA GGG TAG *ATG* AAA CTA *TAG* ATG TGT TTG TAT TAG *ATG* GGG *TAG* *ATG* GGG GCG CCG *TAG* *ATG* CCG CCG CCG *TAG* There's no chance of two ATGs or TAGs stacking in the arrays, i have taken care of it. So maybe just taking care of TAG will be enough. I tried everything, the code was messy and didn't work under most conditions. Is there an easy way to do this?
15 Replies
Rype
Rype2y ago
PS:
Arr 1: { 'S', '1', '1', 'E', 'S', '1', '1', '1', '1', 'E', '\0', '\0', \0', '\0', '\0'};

Arr 2: { 'S', '2', 'E', 'S', '2', '2', '2', 'E', 'S', '2', '2', '2', '2', '2', 'E'};

Arr 3: { 'S', '1', '1', 'E', 'S', '2', '2', '2', 'E', 'S', '2', '2', '2', '2', '2', 'E'}
Arr 1: { 'S', '1', '1', 'E', 'S', '1', '1', '1', '1', 'E', '\0', '\0', \0', '\0', '\0'};

Arr 2: { 'S', '2', 'E', 'S', '2', '2', '2', 'E', 'S', '2', '2', '2', '2', '2', 'E'};

Arr 3: { 'S', '1', '1', 'E', 'S', '2', '2', '2', 'E', 'S', '2', '2', '2', '2', '2', 'E'}
Anton
Anton2y ago
Share the code and what you've tried First lex the strings into tokens so that you're working with individual items, if you get the strings like in the question I'd then use indices or enumerators (not enumerables) to do the checks there's no easy way to do stateful things with linq, you're gonna have an easier time managing the enumerators manually And to be honest your formulation of the question is kinda hard to parse, it'd simplify that first
Rype
Rype2y ago
I'm not allowed to use enumerators, just arrays. I decided to use string array to make it easier such as
string[] DNA1 = { "ATG", "111", "TAG", "ATG", "111", "TAG", "ATG", "111", "111", "111", "111", "111", "111", "111", "111", "TAG", "ATG", "111", "111", "TAG" };

string[] DNA2 = { "ATG", "222", "222", "TAG", "ATG", "222", "TAG", "ATG", "222", "222", "222", "222", "222", "TAG", "", "", "", "", "", "" };
string[] DNA1 = { "ATG", "111", "TAG", "ATG", "111", "TAG", "ATG", "111", "111", "111", "111", "111", "111", "111", "111", "TAG", "ATG", "111", "111", "TAG" };

string[] DNA2 = { "ATG", "222", "222", "TAG", "ATG", "222", "TAG", "ATG", "222", "222", "222", "222", "222", "TAG", "", "", "", "", "", "" };
Anton
Anton2y ago
yeah you've lexed it strings separated by spaces -> string array
Rype
Rype2y ago
the problem is how do i get my index to the start of the gene in the second array
Anton
Anton2y ago
if 222 vs atg vs empty have special meanings, you could lex into tokens just to make your code later easier
Rype
Rype2y ago
atg is start but it doesnt matter since it always comes after TAG
Anton
Anton2y ago
what does that mean
Rype
Rype2y ago
TAG ends a gene(.i.e ATG XXX XXX XXX TAG) and in the second array if the length is different when i skip it my index is not right (doesnt start at ATG)
Anton
Anton2y ago
do you just have to interleave such segments together? while skipping every other one? In your example, why is the last S 2 2 2 2 2 E included? because the first one ended?
Rype
Rype2y ago
because if one of the arrays is out of genes, all other genes are shared
Anton
Anton2y ago
ah ok and otherwise it would skip every other one
Rype
Rype2y ago
yeah
Anton
Anton2y ago
ok
Rype
Rype2y ago
first one comes from arr1[0] second one is arr2[1] third one is arr1[2] as long as they aren't null... to be exact
Want results from more Discord servers?
Add your server
More Posts