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
PS:
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
I'm not allowed to use enumerators, just arrays. I decided to use string array to make it easier such as
yeah you've lexed it
strings separated by spaces -> string array
the problem is how do i get my index to the start of the gene in the second array
if 222 vs atg vs empty have special meanings, you could lex into tokens
just to make your code later easier
atg is start but it doesnt matter since it always comes after TAG
what does that mean
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)
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?
because if one of the arrays is out of genes, all other genes are shared
ah ok
and otherwise it would skip every other one
yeah
ok
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