Hey guys.
I’m rather new to scripting but as I’ve been learning for my hobby project I figured I’d make something useful for work too.
I thought I’d share in case any of you are in medicine.
This is my way of merging DNA alignments from Clustal Omega to get conserved regions where they exist and choose random bases where they do not. This enables me to take the output and feed into a BLAST. This was made to use in non coding regions (enhancer, promoter and other peptide binding sites).
For those that aren’t in medicine/biosciences: Clustal aligns sections of DNA. BLAST searches trough databases for sections resembling the input sequence. These methods can be combined in several ways.
I tried it out and it works rather well, however it is slow and I’m sure it could be optimized a lot.
I do realize I could just as well have made this in javascript instead of unityscript, but after some banging my head against a wall I realized it would be much easier in unityscript as I know that better.
I post this both to share and for criticism. If anyone wants to come with improvements (in particular increasing speed) I’d be very happy.
The finished project is pretty much only this script but I figured I’d save some space trough only posting the script instead of a build.
edit: I forgot to mention, DNA is 4 bases, a, c, t ang g, so I ignore any other letter or symbol in the input strings (spaces or - tend to signify no match in that area on that specific sequence).
Here comes wall of code:
var btnTexture : Texture;
var str1a : String = "";
var str2a : String = "";
var str3a : String = "";
var str4a : String = "";
var str5a : String = "";
var str6a : String = "";
var str7a : String = "";
var str8a : String = "";
var str9a : String = "";
var str10a : String = "";
var str11a : String = "";
var str12a : String = "";
var str13a : String = "";
var str14a : String = "";
var str15a : String = "";
var str16a : String = "";
var str17a : String = "";
var str18a : String = "";
var str19a : String = "";
var str20a : String = "";
var strFinalA = new Array();
var strFinalB = new Array();
var strFinalC = new Array();
var n = 10000;
var randomnumber : float;
var strG : String = "g";
var gC : int = strG[0];
var strA : String = "a";
var aC : int = strA[0];
var strT : String = "t";
var tC : int = strT[0];
var strC : String = "c";
var cC : int = strC[0];
var g : int;
var a : int;
var t : int;
var c : int;
var finalString : String;
var stringLength : int = 60;
var stringStr : String = "60";
var numbOfStr : int = 3;
var numbStr : String = "3";
function OnGUI () {
// Make a text field that modifies stringToEdit.
GUI.Label (Rect (500, 10, 300, 300), "In the first row type the number of bases in your input sequences (how many in each of them). \n It is very important that you do not insert the wrong number in the first row. \n Then press the first checkbox. \n In the second row type the number of sequences you are comparing. \n Press the second Checkbox. \n Input your sequences, one for each line. \n The last line is the merged output, leave that empty. \n When you have input your sequences press the last Checkbox. \n The run will take a few seconds (longer sequences take more time, there is no upper limit to length). \n If you need to start over by any reason, make sure to clear the last line before running again.");
stringStr = GUI.TextField (Rect (10, 10, 200, 20), stringStr, 5);
// here is the length of strings to input:
if (GUI.Button(Rect(300,10,50,50),btnTexture)){
stringLength = parseInt (stringStr);
strFinalA.Clear();
}
// here is the number of strings to input:
numbStr = GUI.TextField (Rect (10, 30, 200, 20), numbStr, 5);
if (GUI.Button(Rect(300,60,50,50),btnTexture)){
numbOfStr = parseInt (numbStr);
strFinalA.Clear();
}
str1a = GUI.TextField (Rect (10, 50, 200, 20), str1a);
str2a = GUI.TextField (Rect (10, 70, 200, 20), str2a);
str3a = GUI.TextField (Rect (10, 90, 200, 20), str3a);
str4a = GUI.TextField (Rect (10, 110, 200, 20), str4a);
str5a = GUI.TextField (Rect (10, 130, 200, 20), str5a);
str6a = GUI.TextField (Rect (10, 150, 200, 20), str6a);
str7a = GUI.TextField (Rect (10, 170, 200, 20), str7a);
str8a = GUI.TextField (Rect (10, 190, 200, 20), str8a);
str9a = GUI.TextField (Rect (10, 210, 200, 20), str9a);
str10a = GUI.TextField (Rect (10, 230, 200, 20), str10a);
str11a = GUI.TextField (Rect (10, 250, 200, 20), str11a);
str12a = GUI.TextField (Rect (10, 270, 200, 20), str12a);
str13a = GUI.TextField (Rect (10, 290, 200, 20), str13a);
str14a = GUI.TextField (Rect (10, 310, 200, 20), str14a);
str15a = GUI.TextField (Rect (10, 330, 200, 20), str15a);
str16a = GUI.TextField (Rect (10, 350, 200, 20), str16a);
str17a = GUI.TextField (Rect (10, 370, 200, 20), str17a);
str18a = GUI.TextField (Rect (10, 390, 200, 20), str18a);
str19a = GUI.TextField (Rect (10, 410, 200, 20), str19a);
str20a = GUI.TextField (Rect (10, 430, 200, 20), str20a);
if (!btnTexture) {
Debug.LogError("Please assign a texture on the inspector");
return;
}
if (GUI.Button(Rect(300,470,50,50),btnTexture)){
Debug.Log("Clicked the button with an image");
n=0;
}
finalString = GUI.TextField (Rect (10, 470, 200, 20), finalString);
}
function Update () {
if (n < stringLength){
if (str1a[n] == "g"){
g += 1;
}
if (str2a[n] == "g"){
g += 1;
}
if (str3a[n] == "g"){
g += 1;
}
if (str1a[n] == "a"){
a += 1;
}
if (str2a[n] == "a"){
a += 1;
}
if (str3a[n] == "a"){
a += 1;
}
if (str1a[n] == "t"){
t += 1;
}
if (str2a[n] == "t"){
t += 1;
}
if (str3a[n] == "t"){
t += 1;
}
if (str1a[n] == "c"){
c += 1;
}
if (str2a[n] == "c"){
c += 1;
}
if (str3a[n] == "c"){
c += 1;
}
if (numbOfStr >= 4){
if (str4a[n] == "g"){
g += 1;
}
if (str4a[n] == "a"){
a += 1;
}
if (str4a[n] == "t"){
t += 1;
}
if (str4a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 5){
if (str5a[n] == "g"){
g += 1;
}
if (str5a[n] == "a"){
a += 1;
}
if (str5a[n] == "t"){
t += 1;
}
if (str5a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 6){
if (str6a[n] == "g"){
g += 1;
}
if (str6a[n] == "a"){
a += 1;
}
if (str6a[n] == "t"){
t += 1;
}
if (str6a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 7){
if (str7a[n] == "g"){
g += 1;
}
if (str7a[n] == "a"){
a += 1;
}
if (str7a[n] == "t"){
t += 1;
}
if (str7a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 8){
if (str8a[n] == "g"){
g += 1;
}
if (str8a[n] == "a"){
a += 1;
}
if (str8a[n] == "t"){
t += 1;
}
if (str8a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 9){
if (str8a[n] == "g"){
g += 1;
}
if (str9a[n] == "a"){
a += 1;
}
if (str9a[n] == "t"){
t += 1;
}
if (str9a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 10){
if (str10a[n] == "g"){
g += 1;
}
if (str10a[n] == "a"){
a += 1;
}
if (str10a[n] == "t"){
t += 1;
}
if (str10a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 11){
if (str11a[n] == "g"){
g += 1;
}
if (str11a[n] == "a"){
a += 1;
}
if (str11a[n] == "t"){
t += 1;
}
if (str11a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 12){
if (str12a[n] == "g"){
g += 1;
}
if (str12a[n] == "a"){
a += 1;
}
if (str12a[n] == "t"){
t += 1;
}
if (str12a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 13){
if (str13a[n] == "g"){
g += 1;
}
if (str13a[n] == "a"){
a += 1;
}
if (str13a[n] == "t"){
t += 1;
}
if (str13a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 14){
if (str14a[n] == "g"){
g += 1;
}
if (str14a[n] == "a"){
a += 1;
}
if (str14a[n] == "t"){
t += 1;
}
if (str14a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 15){
if (str15a[n] == "g"){
g += 1;
}
if (str15a[n] == "a"){
a += 1;
}
if (str15a[n] == "t"){
t += 1;
}
if (str15a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 16){
if (str16a[n] == "g"){
g += 1;
}
if (str16a[n] == "a"){
a += 1;
}
if (str16a[n] == "t"){
t += 1;
}
if (str16a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 17){
if (str17a[n] == "g"){
g += 1;
}
if (str17a[n] == "a"){
a += 1;
}
if (str17a[n] == "t"){
t += 1;
}
if (str17a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 18){
if (str18a[n] == "g"){
g += 1;
}
if (str18a[n] == "a"){
a += 1;
}
if (str18a[n] == "t"){
t += 1;
}
if (str18a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 19){
if (str19a[n] == "g"){
g += 1;
}
if (str19a[n] == "a"){
a += 1;
}
if (str19a[n] == "t"){
t += 1;
}
if (str19a[n] == "c"){
c += 1;
}
}
if (numbOfStr >= 20){
if (str20a[n] == "g"){
g += 1;
}
if (str20a[n] == "a"){
a += 1;
}
if (str20a[n] == "t"){
t += 1;
}
if (str20a[n] == "c"){
c += 1;
}
}
print("The cycle is"+ n);
print("g is"+ g);
print("a is"+ a);
print("t is"+ t);
print("c is"+ c);
if ((g>a) (g>t) (g>c)){
strFinalA.push("g");
}
if ((a>g) (a>t) (a>c)){
strFinalA.push("a");
}
if ((t>a) (t>g) (t>c)){
strFinalA.push("t");
}
if ((c>a) (c>t) (c>g)){
strFinalA.push("c");
}
if ((g==a) (g>t) (g>c)){
randomnumber= Random.value;
if (randomnumber <= (0.5)){
strFinalA.push("g");
}
if (randomnumber > (0.5)) {
strFinalA.push("a");
}
}
if ((g==t) (g>a) (g>c)){
randomnumber= Random.value;
if (randomnumber <= (0.5)){
strFinalA.push("g");
}
if (randomnumber > (0.5)) {
strFinalA.push("t");
}
}
if ((g==c) (g>a) (g>t)){
randomnumber= Random.value;
if (randomnumber <= (0.5)){
strFinalA.push("c");
}
if (randomnumber > (0.5)) {
strFinalA.push("g");
}
}
if ((a==t) (a>g) (a>c)){
randomnumber= Random.value;
if (randomnumber <= (0.5)){
strFinalA.push("a");
}
if (randomnumber > (0.5)) {
strFinalA.push("t");
}
}
if ((a==c) (c>g) (c>t)){
randomnumber= Random.value;
if (randomnumber <= (0.5)){
strFinalA.push("c");
}
if (randomnumber > (0.5)) {
strFinalA.push("a");
}
}
if ((t==c) (c>a) (c>g)){
randomnumber= Random.value;
if (randomnumber <= (0.5)){
strFinalA.push("c");
}
if (randomnumber > (0.5)) {
strFinalA.push("t");
}
}
if ((g==a) (g==t) (g>c)){
randomnumber= Random.value;
if (randomnumber <= (0.33)){
strFinalA.push("g");
}
if ((randomnumber > (0.33)) (randomnumber <= (0.66))){
strFinalA.push("a");
}
if (randomnumber > (0.66)) {
strFinalA.push("t");
}
}
if ((c==t) (c==a) (c>g)){
randomnumber= Random.value;
if (randomnumber <= (0.33)){
strFinalA.push("a");
}
if ((randomnumber > (0.33)) (randomnumber <= (0.66))){
strFinalA.push("c");
}
if (randomnumber > (0.66)) {
strFinalA.push("t");
}
}
if ((t==c) (t==g) (t>a)){
randomnumber= Random.value;
if (randomnumber <= (0.33)){
strFinalA.push("g");
}
if ((randomnumber > (0.33)) (randomnumber <= (0.66))){
strFinalA.push("c");
}
if (randomnumber > (0.66)) {
strFinalA.push("t");
}
}
if ((a==c) (a==g) (a>t)){
randomnumber = Random.value;
if (randomnumber <= 0.33){
strFinalA.push("g");
}
if ((randomnumber > 0.33) (randomnumber <= 0.66)){
strFinalA.push("c");
}
if (randomnumber > 0.66) {
strFinalA.push("a");
}
}
if ((a==c) (a==g) (a==t)){
randomnumber= Random.value;
if (randomnumber <= 0.25){
strFinalA.push("g");
}
if ((randomnumber > 0.25) (randomnumber <= 0.5)){
strFinalA.push("c");
}
if ((randomnumber > 0.5) (randomnumber <= 0.75)) {
strFinalA.push("a");
}
if (randomnumber > 0.75){
strFinalA.push("t");
}
}
n += 1;
g = 0;
a = 0;
t = 0;
c = 0;
}
if (n==stringLength){
finalString = Array(strFinalA).Join("");
print(finalString);
n++;
}
}