Skip to content

Instantly share code, notes, and snippets.

@ElNando888
Last active December 17, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElNando888/71d09fac5003236d6432 to your computer and use it in GitHub Desktop.
Save ElNando888/71d09fac5003236d6432 to your computer and use it in GitHub Desktop.
Source for pseudoswitch lab-design generator
//
// Globals
//
var vrna = new LibVrna211;
var seq;
var constraint;
var t1 = 'GGAAA';
var t2 = 'GCUGAGCUUCGGCUCAGCA'
var t3 = 'AAAGAAACAACAACAACAAC';
var s1 = 'GAGCCCUGGGAGGCUC';
var s2 = 'GCUGUUCCCAGACAGC';
var h1ofs, h2ofs;
//
// Utilities
//
String.prototype.repeat = function (num)
{
var a = [];
a.length = (num << 0) + 1;
return a.join(this);
};
function complement(base)
{
if(base=='A') return 'U';
if(base=='U') return 'A';
if(base=='G') return 'C';
if(base=='C') return 'G';
return null;
}
//
// Start of code
//
do {
var c1, c2, c3;
clear();
if( typeof sequence != 'undefined' ) {
if( seq == sequence ) break;
seq = sequence;
// ...
// determine c1,c2,c3,h1ofs,h2ofs from the sequence
// ...
h1ofs = seq.indexOf(s1);
if( h1ofs == -1) break;
c1 = h1ofs - 5;
h2ofs = seq.indexOf(s2);
if( h2ofs == -1) break;
c2 = h2ofs - c1 - 21;
c3 = 31 - c1 - c2;
} else {
c1 = Lib.random(11,13);
c2 = Lib.random(5,6);
c3 = 31 - c1 - c2;
var x1 = Lib.randomSequence( c1 );
h1ofs = t1.length + c1;
var x2 = Lib.randomSequence( c2 );
h2ofs = t1.length + c1 + s1.length + c2;
var x3 = Lib.randomSequence( c3 );
// randomize barcode
var b = [];
b[0] = Lib.randomSequenceWithBases(1,'GC');
b[14] = complement(b[0]);
for( j = 1; j <= 5; j++ ) {
b[j] = Lib.randomSequence(1);
b[14-j] = complement(b[j])
}
b[6] = Lib.randomSequenceWithBases(1,'CCG');
b[8] = complement(b[0]);
b[7] = "UUCG";
b[15] = "A";
t2 = b.join('');
seq = t1+x1+s1+x2+s2+x3+t2+t3;
}
var ret = vrna.fold( seq );
if( ret.mfe_structure.substr(0,5) != '.....' ) continue;
if( ret.mfe_structure.substr(68,39) != '(((((((....))))))).....................' ) continue;
if( ret.mfe_structure.substr(h1ofs,16) == '(((((......)))))' ) continue;
if( ret.mfe_structure.substr(h2ofs,16) == '((((((....))))))' ) continue;
var mfe_secstr = ret.mfe_structure;
outln( seq );
outln(ret.mfe_structure);
outln(ret.free_energy);
constraint = ".".repeat(h1ofs+5) + "xxxxxx" + ".".repeat(c2+10) + "xxxxxx" + ".".repeat(107-h2ofs-11);
ret = vrna.foldWithConstraint( seq, constraint );
if( ret.mfe_structure.substr(0,5) != '.....' ) continue;
if( ret.mfe_structure.substr(68,39) != '(((((((....))))))).....................' ) continue;
if( ret.mfe_structure.substr(h1ofs,16) != '(((((......)))))' ) continue;
if( ret.mfe_structure.substr(h2ofs,16) != '(((((......)))))' ) continue;
outln( constraint );
outln(ret.mfe_structure);
outln(ret.free_energy);
constraint = ".".repeat(h1ofs+5) + "xxxxxx" + ".".repeat(107+c2+16-h2ofs-11);
ret = vrna.foldWithConstraint( seq, constraint );
if( ret.mfe_structure.substr(0,5) != '.....' ) continue;
if( ret.mfe_structure.substr(68,39) != '(((((((....))))))).....................' ) continue;
if( ret.mfe_structure.substr(h1ofs,16) != '(((((......)))))' ) continue;
outln( constraint );
outln(ret.mfe_structure);
outln(ret.free_energy);
constraint = ".".repeat(h1ofs+c2+21) + "xxxxxx" + ".".repeat(107-h2ofs-11);
ret = vrna.foldWithConstraint( seq, constraint );
if( ret.mfe_structure.substr(0,5) != '.....' ) continue;
if( ret.mfe_structure.substr(68,39) != '(((((((....))))))).....................' ) continue;
if( ret.mfe_structure.substr(h2ofs,16) != '(((((......)))))' ) continue;
outln( constraint );
outln(ret.mfe_structure);
outln(ret.free_energy);
constraint = ".".repeat(h1ofs+5) + "((((((" + ".".repeat(c2+10) + "))))))" + ".".repeat(107-h2ofs-11);
ret = vrna.foldWithConstraint( seq, constraint );
if( ret.mfe_structure == mfe_secstr ) continue;
if( ret.mfe_structure.substr(0,5) != '.....' ) continue;
if( ret.mfe_structure.substr(68,39) != '(((((((....))))))).....................' ) continue;
outln( constraint );
outln(ret.mfe_structure);
outln(ret.free_energy);
break;
} while(1);
delete vrna;
return null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment