From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing and Replacing strings within an array

Solved!
Go to solution

Hey guys,

 

I'm working on a project and I need to replace elements of an array based on the elements around it.

 

I was given a subVI that outputs a random gene sequence as a 2D array of strings. Each string is comprised of one letter, representing half of a base pair in an RNA strand. (For example, A is next to U and C is next to G, or vice versa) The subVI randomly adds the letter M to simulate a mutation taking place. So, I need a code that would locate this mutation and replace it with the proper other half of the base pair. (So if the sequence was M-U, I would need to replace the M with an A).

 

I know how to locate the M and replace it, but I'm not sure how to replace it with the corresponding letter. I'm not sure how to make the program differentiate what the correct letter is to insert. Can anyone point me in the right direction? I've attached the subVI.

 

Thank you!

0 Kudos
Message 1 of 7
(1,953 Views)
Solution
Accepted by topic author akempton01

Given the indices of the "M" element as (x,y), you can state that the indices of the element to use to determine the new value are (x, 1-y) for a 2D array (y=0 or y=1).

 

Once you have this, use Index Array to find the current value, and then you can use e.g. a Map to find the paired value.

Example_VI.png

 

As an aside, password protecting VIs that you upload to the forum is a bit annoying (although not critical in this case) and easily circumvented - passwords on VIs set in this manner basically are completely insecure - you shouldn't use this for "security" if that's something you're considering. Instead you need to entirely remove the block diagram as a compilation step if you're producing outputs. Password protection is only a deterrent.

 

Edit: I saw that I wired the search location in twice, once via the "?" and once as a normal tunnel. In case you didn't know, you don't need to do this - you can just wire the ? from the right side. I didn't notice before I uploaded 😕


GCentral
0 Kudos
Message 2 of 7
(1,892 Views)

This almost looks like homework. What should happen if both elements of a row are M? Can there be more than one M? Can we assume that all other pairs are correctly matched, e.g. a U-G cannot occur?

0 Kudos
Message 3 of 7
(1,886 Views)
Solution
Accepted by topic author akempton01

Here's how I would do all repairs except M-M (repaired A).

 

Once you have the result of all valid inputs, you can create a new map for even simpler code. (Repaired B). This version even replaces all invalid pairs with X-X.

 

 

altenbach_1-1619368722996.png

 

0 Kudos
Message 4 of 7
(1,874 Views)

Wow thank you so much - the only reason there is a password on that VI is because this is a small part of a homework assignment, and the professor didn't want us to be able to edit that VI. Nothing that really needs to be secure there! And no worries on the little extra wiring this is so helpful.

0 Kudos
Message 5 of 7
(1,864 Views)

I guess I should've been a little more specific - sorry this is my first time posting anything on this kind of forum. I don't think both elements of a row can be M. There can be multiple M's, and we can assume all other pairs are correctly matched.

0 Kudos
Message 6 of 7
(1,862 Views)

This is awesome! Thank you so much!

0 Kudos
Message 7 of 7
(1,861 Views)