PDA

View Full Version : DNA Visualization


Zlybrat
11-27-2011, 10:41 AM
Hello, people! I have to make a project which will mainly consist of DNA visualization. I am new to MEL, but not really new to Maya and script languages. I need some advices. My software has to get some input from user (e.g. AGAATC - nucleotides) and draw a helix. I assume that it will be easier to load the nucleotides and then connect them and twist the helix than to generate nucleotides every time? What is the most sufficient way to store and load them? Also, I have a string of letters e.g. AGATTC from scroollField. How to divide the string into separate letters to load appropriate molecule? Regards : )

Azrail
11-28-2011, 08:53 AM
Here is some simple script to build a chain, you just need to have the four nucleotides in the scene with the proper names: "base_A", "base_T", "base_G", "base_C". It doesn't matter if they are groups or objects. The script will make instance of every group and place it together with the corresponding nitro-base on the other side of the helix. Of course you should make sure the supplied string is valid (contains only capital letters etc..)

string $src = "CCAAAGTCCAG";
float $numBases = size($src);
float $scale = 5;
$grp = `group -em -n "DNA_Chain#"`;
for ($i=0;$i<$numBases;$i++)
{
$base = `substring $src ($i+1) ($i+1)`;
$pair = "A";
if ($base == "A") $pair = "T";
if ($base == "G") $pair = "C";
if ($base == "C") $pair = "G";
$x = sin($i)*$scale;
$z = cos($i)*$scale;
$y = $i*$scale;
$obj = `instance ("base_" + $base)`;
move -a -ws $x $y $z $obj;
parent $obj $grp;
// Set up the pair
$x2 = sin($i+3.14)*$scale;
$z2 = cos($i+3.14)*$scale;
$obj = `instance ("base_" + $pair)`;
move -a -ws $x2 $y $z2 $obj;
parent $obj $grp;
$link = `curve -d 1 -p $x $y $z -p $x2 $y $z2`;
parent $link $grp;
}

hope that helps

berniebernie
11-28-2011, 02:35 PM
string $src = "CCAAAGTCCAG";
float $numBases = size($src);
float $scale = 5;
$grp = `group -em -n "DNA_Chain#"`;
for ($i=0;$i<$numBases;$i++)
{
$base = `substring $src ($i+1) ($i+1)`;
$pair = "A";
if ($base == "A") $pair = "T";
if ($base == "G") $pair = "C";
if ($base == "C") $pair = "G";
$x = sin($i)*$scale;
$z = cos($i)*$scale;
$y = $i*$scale;
string $objs[] = `instance ("base_" + $base)`;
$obj = $objs[0];
move -a -ws $x $y $z $obj;
parent $obj $grp;
// Set up the pair
$x2 = sin($i+3.14)*$scale;
$z2 = cos($i+3.14)*$scale;
string $objs[] = `instance ("base_" + $pair)`;
$obj = $objs[0];
move -a -ws $x2 $y $z2 $obj;
parent $obj $grp;
$link = `curve -d 1 -p $x $y $z -p $x2 $y $z2`;
parent $link $grp;
}




Otherwise you'll lend on cannot cast string to string[] problems I think.

Azrail
11-28-2011, 04:09 PM
Nope you won't:

instance [-leaf] [-name string] [-smartTransform] [objects]
Return value
string - the name of the new transform node is returned.


PS: I actually did test that stuff you know ;)

Zlybrat
11-28-2011, 06:15 PM
Thank You, Azrail, this is extremely helpful : ) I think this short script will make a good toehold for me.

berniebernie
11-29-2011, 11:51 AM
yeah my bad I must have cast a variable before when I tested the inside of the loop.

CGTalk Moderation
11-29-2011, 11:51 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.