23andMe SNP visualization as ‘Ticker’ using Processing

The following Processing script is used for the visualization of 23andMe SNP data in the above movie.

//
// Ticker showing 23andMe SNP 
// Processing 2.0b
// Written by Madscientist
//
//

ArrayList column;
int index;
float x;
float y;
int fontsize;
float t;
float delta;
String genotype;
PFont f; 

void setup(){
  
  size(800,200);
  background(125);
  fill(0);
  text("Loading...",200,200);
  String fileName = dataPath("23andme.txt"); 
  File file = new File(fileName);
  BufferedReader br = null;
  column = new ArrayList();
  try {
        br = new BufferedReader(new FileReader(file));
        String listtext = null;
        while ((listtext=br.readLine())!=null){
          column.add(listtext);
      }
    }
    catch(FileNotFoundException e){
      e.printStackTrace();
    }
    catch(IOException e){
      e.printStackTrace();
    }
    finally{
      try {
        if (br != null){
          br.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    
  index = 0;
  f = createFont("Arial",16,true);
  fontsize =50;
  x=0;
  y=random(50,150);
}

void draw () {
  
    background(255);
    fill(0);
    
    String line = column.get(index).toString();
    String comment = line.substring(0,1);
    if (!comment.equals("#")) {
        String [] numbers = split(line,'\t');
        textFont(f,fontsize);
        
        genotype = numbers[3];
        if (genotype.equals("AA")) {
        fill(255,0,0,t);
        } else 
        if (genotype.equals("AG")){
        fill(255,125,0,t);
        } else
        if (genotype.equals("AC")){
        fill(255,0,125,t);
        } else
        if (genotype.equals("AT")){
        fill(255,0,255,t);
        }else
        if (genotype.equals("GG")){
        fill(0,255,0,t);
        } else
        if (genotype.equals("CG")){
        fill(0,125,125,t);
        } else
        if (genotype.equals("TG")){
        fill(0,125,255,t);
        } else
        if (genotype.equals("CC")){
        fill(0,0,255,t);
        } else
        if (genotype.equals("CT")){
        fill(0,125,50,t);  
        }      
        else
        if (genotype.equals("TT")){
        fill(50,0,50,t);
         } else
        if (genotype.equals("--")){
        fill(0,0,0,t);
        }
        text(genotype,  x,y);
        textFont(f,fontsize/2);
        text(numbers[0],x,y+30);
        fill(0,0,0);
        text("Chromosome "+numbers[1],0,180);
        text(numbers[2]+ " bp",200,180);
      } else {
       index++; 
      }
   
   if (x<800) {
    x=x+30;
    t=255-x/3.1372549019;
   } else {
    x = 0;
    index++;
    y=random(50,150); 
   }
     
   if (index>=column.size()){
      index = 0; 
   }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s