Saturday, September 16, 2023

DNA Sequencer

 This is John Doe's DNA:

John Doe,T,A,C,G,C,T,A,T,T

These are other animals:

Arctic Fox,T,A,C,C,T,A,C,T,T,A,C,G,A,T,G,T,G,T,A,G,C,A,C,A,T,C,T,G,G,A,T,G,C,T,C,C,T,T,C,T,A,C,G,C,G,G,T,A,A,T,A,T,C,C,T,G,T,G,G,A,T,G,G,A,C,G,G,A,G,C,T,A,C,C,G,C,T,T,T,C,T,T,G,C,G,G,A,G,G,T,G,A,T,C,A,C,C,T,G,A,C,T


Glow Worm,T,A,C,C,T,A,C,T,T,A,C,G,A,A,C,A,C,T

Eastern Diamondback Rattlesnake,T,A,C,G,C,C,T,A,G,G,C,G,G,T,A,A,T,C

Domestic Cat,T,A,C,G,G,G,T,A,G,C,T,A,G,C,C,A,T,T


Great Dane,T,A,C,T,T,G,T,C,A,T,G,G,C,T,C,T,C,G,T,A,G,C,T,T,T,C,T,A,A,T,G,A,A,C,C,G,T,T,C,T,A,T,T,G,A,A,C,A,G,T,T,A,G,A,T,G,G,A,G,C,T,C,C,C,T,C,A,A,T,C,C,C,T,T,A,C,C,A,A,G,T,C,C,T,C,T,C,A,A,G,C,G,C,C,A,C,\

A,C,C,A,C,T

Alaskan Malmute,T,A,C,C,T,G,T,C,G,A,G,G,A,C,C,C,T,C,A,G,A,C,C,T,G,A,G,T,T,A,G,C,A,C,G,G,T,A,G,G,T,G,T,C,T,G,G,C,G,T,G,C,C,G,G,A,T,G,C,G,C,A,T,A,T,G,T,T,C,T,T,T,G,C,T,C,T,C,A,A,G,A,C,C,G,A,A,G,T,C,C,C,G,G\

,C,T,A,G,G,A,T,C

Golden Retriever,T,A,C,A,C,C,T,G,T,A,A,C,G,T,T,A,G,T,A,G,T,C,G,A,G,T,A,C,C,A,C,T,T,T,A,A,T,G,C,A,C,A,T,C,T,T,C,C,A,A,C,G,A,C,G,A,C,G,T,A,G,T,C,G,A,T,T,A,G,A,A,G,A,G,C,C,T,A,C,G,G,A,A,C,C,C,G,C,G,G,G,G,T,\

T,C,G,A,A,T,A,T,T


The fund-a is simpler organisms need not necessarily have more complex DNA.

Now cell division happens in two types. Meiosis and Mitosis. Mitosis is normal division and Meiosis results in haploid cells with half the number of Strands.

The thing is DNA transcription happens with the involvement of messenger RNAs.

I have a partly written code for this which did not completely work.

Here is some sample:

string Sequencer::Convert(const string trinucleotide){
  if((trinucleotide=="AUU")||(trinucleotide=="AUC")||(trinucleotide=="AUA"))
    return ("Isoleucine");
  else if((trinucleotide=="CUU")||(trinucleotide=="CUC")||(trinucleotide=="CUA")||
          (trinucleotide=="CUG")|| (trinucleotide=="UUA")||(trinucleotide=="UUG"))
    return ("Leucine");
  else if((trinucleotide=="GUU")||(trinucleotide=="GUC")||
          (trinucleotide=="GUA")||(trinucleotide=="GUG"))
    return ("Valine");
  else if((trinucleotide=="UUU")||(trinucleotide=="UUC"))
    return ("Phenylalanine");
  else if((trinucleotide=="AUG"))
    return ("Methionine (START)");
  else if((trinucleotide=="UGU")||(trinucleotide=="UGC"))
    return ("Cysteine");
  else if((trinucleotide=="GCU")||(trinucleotide=="GCC")||
          (trinucleotide=="GCA")||(trinucleotide=="GCG"))
    return ("Alanine");
  else if((trinucleotide=="GGU")||(trinucleotide=="GGC")||
          (trinucleotide=="GGA")||(trinucleotide=="GGG"))
    return ("Glycine");
  else if((trinucleotide=="CCU")||(trinucleotide=="CCC")||
          (trinucleotide=="CCA")||(trinucleotide=="CCG"))
    return ("Proline");
  else if((trinucleotide=="ACU")||(trinucleotide=="ACC")||
          (trinucleotide=="ACA")||(trinucleotide=="ACG"))
    return ("Threonine");
  else if((trinucleotide=="UCU")||(trinucleotide=="UCC")||
          (trinucleotide=="UCA")||(trinucleotide=="UCG")||
          (trinucleotide=="AGU")||(trinucleotide=="AGC"))
    return ("Serine");
  else if((trinucleotide=="UAU")||(trinucleotide=="UAC"))
    return ("Tyrosine");
  else if((trinucleotide=="UGG"))
    return ("Tryptophan");
  else if((trinucleotide=="CAA")||(trinucleotide=="CAG"))
    return ("Glutamine");
  else if((trinucleotide=="AAU")||(trinucleotide=="AAC"))
    return ("Asparagine");
  else if((trinucleotide=="CAU")||(trinucleotide=="CAC"))
    return ("Histidine");
  else if((trinucleotide=="GAA")||(trinucleotide=="GAG"))
    return ("Glutamic acid");
  else if((trinucleotide=="GAU")||(trinucleotide=="GAC"))
    return ("Aspartic acid");
  else if((trinucleotide=="AAA")||(trinucleotide=="AAG"))
    return ("Lysine");
  else if((trinucleotide=="CGU")||(trinucleotide=="CGC")||(trinucleotide=="CGA")||
          (trinucleotide=="CGG")||(trinucleotide=="AGA")||(trinucleotide=="AGG"))
    return ("Arginine");
  else if((trinucleotide=="UAA")||(trinucleotide=="UAG")||(trinucleotide=="UGA"))
    return ("Stop");
else
    cout << "returning unknown" << endl;
  return ("Unknown");
}

Also the sequencing either happens completely or not at all. There is nothing like half the DNA is copied and other half of the sequence isn't as I thought might happen earlier.

Potion Craft

 Another stupider game.

Here there are things like potions of various types in a file. We are supposed to read the file, populate our data structures, increment the ingredients if two of them combine to form a more complex ingredient. Final is the philosopher's stone or something.

//Constants (Do not edit)                                                                                                                                                                                  
const int PROJ2_SIZE = 29;
const int RANK_D = 30;
const int RANK_C = 50;
const int RANK_B = 70;
const int RANK_A = 90;
const int RANK_S = 100;

The score keeps incrementing as an when you get more and more complex ingredients made.

If you get all ingredients and stone your score reaches 100 and you win.

These are the ingredients and their secret recipes.

Firebell,natural,none,none

Waterbloom,natural,none,none

Terraria,natural,none,none

Windbloom,natural,none,none

Mad Mushroom,natural,none,none

Witch's Mushroom,natural,none,none

Featherbloom,natural,none,none

Healing,potion,Waterbloom,Terraria

Poison,potion,Terraria,Firebell

Frost,potion,Waterbloom,Waterbloom

Fire,potion,Firebell,Firebell

Explosion,potion,Mad Mushroom,Mad Mushroom

Swiftness,potion,Windbloom,Windbloom

Mana,potion,Witch's Mushroom,Witch's Mushroom

Lightning,potion,Thunder Thistle,Windbloom

Strength,potion,Terraria,Terraria

Stone Skin,potion,Firebell,Waterbloom

Sleep,potion,Lifeleaf,Waterbloom

Dexterity,potion,Waterbloom,Windbloom

Light,potion,Windbloom,Firebell

Rage,potion,Bloodthorn,Featherbloom

Charm,potion,Mad Mushroom,Windbloom

Levitation,potion,Mad Mushroom,Witch's Mushroom

Invisibility,potion,Witch's Mushroom,Windbloom

Nigredo,reagent,Poison,Stone Skin

Albedo,reagent,Nigredo,Frost

Citrinitas,reagent,Albedo,Fire

Rubedo,reagent,Citrinitas,Healing

Philosopher's Stone,legendary,Rubedo,Invisibility

Bloons Game

 A stupid game demonstrating several patterns in the code.

//**Constants related to starting game**                                                                                                                                                                    
const int START_ROUND = 1; //Starting round                                                                                                                                                                
const int START_LIFE = 100; //Starting life (num damage before losing game)                                                                                                                                
const int START_MONEY = 10; //Starting money for player                                                                                                                                                    

//Constants related to the length of the path                                                                                                                                                              
const int PATH_LENGTH = 3; //Length of the path (could be anything)                                                                                                                                        
const int START_BLOON = -1; //Starting location of all bloons                                                                                                                                              

//**Constants related to money/cost**                                                                                                                                                                      
const int COST_DART = 2; //Starting cost for dart monkey                                                                                                                                                    
const int COST_BOOMERANG = 4; //Starting cost for boomerang monkey                                                                                                                                          
const int COST_BOMB = 6; //Starting cost for a bomb monkey                                                                                                                                                  
const int COST_IMPROVE = 2; //Cost for each improvement (regardless of type)                                                                                                                                
const int EARN_POP = 1; //Earnings per pop of a bloon                                                                                                                                                      
const int IMPROVE_VALUE = 2; //When a bloon is improved, increases the value based on this                                                                                                                  

//**Constants related to damage**                                                                                                                                                                          
const int DAMAGE_DART = 1; //Starting damage for dart monkey                                                                                                                                                
const int DAMAGE_BOOM = 1; //Starting damage for boomerage monkey                                                                                                                                          
const int DAMAGE_BOMB = 1; //Starting damage for bomb monkey                                                                                                                                                
//******************************************************

The project has three types of Baloons. Dart, Boomerang and Bomb. Each are deriving from Monkey.

Basic is deriving from Bloon.

Monkey is a stand alone class.

This project demonstrates the concept of inheritance and polymorphism.

Sunday, March 22, 2020

Procedural Landscape(Terrain) Generation in OpenGL - C#.Net

My goal of doing this project was to finally create a landscape over which cars or other vehicles could be driven.

But first the snapshots




I am happy to showcase this project. It is using the Shadow Engine and Tao OpenGL binding for C#.Net.
You can generate these height maps from the techniques mentioned in my earlier posts like Diamond Square Algorithm etc.

You can refer to my repo in github for the code: https://github.com/bmkamath2000/OpenGL-in-CSharp.Net

Wednesday, January 15, 2020

React Client and PHP server- School Enrollment Form using Rest APIs


The following link here has a project that me and my ex-colleague Shridhar made over a few weekends.
Our goal was to learn ReactJS along with using Rest APIs to access server.
We were successful in making a simple user interface that accesses a database to display student information in a tabular form. There is provision for adding new students and deleting or modifying a student details.
Here is a snapshot of the projects working:
This is the dashboard:

This is the screen on pressing Add Students:

This is the screen on pressing modify for any of the student:

This is a link into my github for the above project.
https://github.com/bmkamath2000/School-Module

Sunday, October 6, 2019

[SOLVED] PHP, MySQL & React REST API Tutorial with Example Form

PHP is a very robust backend technology. Combined with MySQL it has withstood the test of time and are security wise good enough solutions. What makes these technologies even more popular is their ease of learning.

Recently it is a trend in the industry to have Web APIs serve website requests. On the front end use of Javascript frameworks like Angular JS and/or React JS or Vue.js makes the front end independent of the backend.
Why I say that is because for any data request that comes to the server, These front end client facing Apps can be changed without the back-end requiring any changes. Not only that, the back end can be upgraded to newer technologies without any changes to the front end app.
This decoupling is possible with the miracle technologies of Client Side Apps and Single Page Applications using frameworks such as AngularJS or ReactJS.

A React Application that I am going to focus on now will be responsible for the View or the rendering of data to the client. It does this task efficiently by the use of a concept called Virtual DOM. Updating the DOM is faster if we know which nodes in the DOM tree have changed. A Diffing algorithm used by React-JS does this efficiently.

Coming to the example part of my blog, I am going to improvise on an existing app that was written quite some time back and does not work well(Has errors while running). If you are interested in the non working application, that you could copy code from, then read this article in the site techiedairies.

PHP, MySQL & React REST API Tutorial with Example Form

Otherwise, you may continue to read on to know the differences that need to be made to make the program work.
Pre-Requisites:
1) PHP 2) MySQL 3) ReactJS 

If you have a set up with XAMPP/WAMP/LAMP that will have all these except ReactJS which you need to install and for that you need NodeJS.

Now,

WebAPIs that we write will serve rows of a table. All the rows are displayed in the react app and there is provision to add another row or post info to the PHP server.

First thing after having the prerequisites is you should expect to get errors in the browser. This is common for all website projects. Next is you should listen to those who have trodden this path. So the biggest errors you may get is in the PHP file and you may avoid some heartburn and save time by making following changes.

in contacts.php file there are some mistakes that need to be set right:

This is the correct code:
if ($method == 'GET') {
    echo '[';
    for ($i=0 ; $i<mysqli_num_rows($result) ; $i++) {
      echo ($i>0?',':'').json_encode(mysqli_fetch_object($result));
    }
    echo ']';
  } elseif ($method == 'POST') {
    echo json_encode($result);
  } else {
    echo mysqli_affected_rows($con);
  }

Where you don't set the array brackets based on existence of id field in the request.

Another thing is 
  componentDidMount() {
    const url = 'http://localhost/api/abc/contacts.php?id='
    axios.get(url).then(response => response.data)
    .then((data=> {
      this.setState({ contacts: data })
      console.log(this.state.contacts)
     })
  }

in your react app componentDidMount() function, the URL should be as shown above.
There should be an id field without any data which our php server checks. If no ID field is given the server sends an error header like this.


And that is because of the following thing:

So the extra error makes the contacts array not be parsed properly.

Now Another error you may encounter is the CORS issue. I solved this via a temporary solution of adding a CORS Access-Control-Allow-Origin extension in chrome.


If everything is fine, but only cors issue is blocking your access request, then you will get the following screen:

If you set the CORS button ON then you will get the following output:

Which is nothing but the output of the following MySQL database table:

mysql> select * from contacts;
+----+--------+------------------------+-----------+---------+---------+
| id | name   | email                  | city      | country | job     |
+----+--------+------------------------+-----------+---------+---------+
|  1 | mukesh | bmk@gmail.com          | bengaluru | India   | AC      |
|  2 | muk1   | bmkamath20000@gmail.co | bengal    | india   | driver  |
|  3 | kkjfev | suresh.kamath.104      | bng       | ind     | plumber |
+----+--------+------------------------+-----------+---------+---------+
3 rows in set (0.00 sec)

Another thing is in the contactsform.js component that you use to post data to the PHP server,

The axios function should get appropriate URL of your web service like this:

axios({
            method: 'post',
            url: 'http://localhost/api/abc/contacts.php',
            data: formData,
            config: { headers: {'Content-Type': 'multipart/form-data' }}
        })

Here my contacts.php file location is /api/abc within the server www folder.

I hope you have a smooth learning curve... Cheers!!!

Saturday, June 8, 2019

Sending SMS Via SMS Service Provider in PHP

Here in India there are several service providers to send(Push) Commercial/Transactional SMS to DND/non DND mobiles. I have worked on one such module where the SMSes were being sent from our server at City Engineering College(Http://www.cityengineeringcollege.ac.in).

Here is a brief about the API Integration:

SMS sending requires you to sign up with SMS service providers in India such as Core Factors.

Now in PHP there is a way of executing or triggering a URL by the CURL command.

CURL is a way of executing a URL from within your program. The SMS that needed to be sent is encoded within the URL string and executed by the PHP program using CURL command.

There was a document from Core Factors Pvt Ltd that helped us in integrating the SMS APIs exposed by them.

Firstly to send SMS to Students/Parents mobiles we needed to login to their website and using the UI provided send bulk messages.

In the Server code that we used to send the SMSes we needed to login to the website using credentials provided by them. Then we form URL strings containing the SMS text and execute in loops the URL which sent the SMSes.

So that was the Gist of how SMSes could be sent to mobiles from a PHP Server.