Friday, September 30, 2011

Scripts Perl -Bioinfo-


----------------------------------------------------------------------------------------------------------------------------
Perl, bom para manipulacão de arquivo texto.
Por conta da sintaxe resolvi salvar aqui esse scripts!Putz sintaxe ;-p
"Perl, good for manipulating text files.
Because of the syntax here I decided to save these scripts!
Putz syntax"
----------------------------------------------------------------------------------------------------------------------------
script to translate a nucleotide sequence.


#!/usr/bin/perl

use strict;
use warnings;

my %HoA;
open(IN,'iupac')or die $!;
while(<IN>){
    chomp;
    my($aminoacido,$codon)=split (/\t/,$_);
    ${$HoA{$codon}}=$aminoacido;
}
close(IN);

my $dna;
open(IN,'DNA')or die $!;
while(<IN>){
    chomp;
    $dna .= $_;
}
close(IN);

my @DNA = split(//,$dna);
my $frame = 0;
my $codon;

while ($frame < 2){
    print "\nNormal frame - $frame\n";
    for(my $i = $frame; $i < $#DNA; $i+=3){
            $codon .= join("",@DNA[$i..$i+2]);
            if (exists $HoA{$codon}){
                print "${$HoA{$codon}} - ";
            }
            $codon = "";
    }
    $frame++;
}
$dna = reverse $dna;
$dna =~ tr/ATGC/TACG/;
@DNA = split(//,$dna);

$frame = 0;
while ($frame < 2){
    print "\nComplementar frame - $frame\n";
    for(my $i = $frame;$i < $#DNA;$i+=3){
        $codon .= join("",@DNA[$i..$i+2]);
        if (exists $HoA{$codon}){
            print "${$HoA{$codon}} - ";
        }
        $codon = "";
    }
    $frame++;
}

'DNA'
ATGGAGATGGGCAGACGGATTCATTCAGAGCTGCGGAACAGGGCGCCCTCTGATGTGAAAGAACTTGCCCTGGACAACAGTCGGTCGAATGAAGGCAAATCGAAGCCCTCACAGATGAATT
TGAAGAACTGGAATTCTTAAGTAAAATCAACGGAGGCCTCACCTCAATCTCAGACTTACCAA
AGTTAAAGTTGAGAAGCTTGAACTAAGAGTCTCAGGGGGCCTGGAAGTATTGGCGAAAAGT
GTCCAAACCTCACGCATCTATATTTAAGTGGCAACAAAATTAAAGACCTCAGCACAATAGAGCCACTGAAACAGTTAGAAAACCTCAAGAGCTTAGACCTTTTCAATTGCGAGGTAACCAACCTGA
ACGACTCGGAGAAAACGTGTTCAAGCTTCTCCTGCACTCACATATCTCGACAGCTGTTACTGG
GACCACAAGGAGCCCCTTACTCAGATATTGAGGACCACGTGAGGGCCTGGATGACGAGGAGG
AGGGTGAGCATGAGGAGAGTATGATGAAGATGCTCAGGTAGTGGAAATGAGGAGGGCGAGG
AGGAGGAGGAGGAAGGTGAAGAGGGGACGTGAGTGGAGGGGACGAGGAGGATGAGAAGGT
TATAACGATGGAGAGGTAGATGGCGAGGAAGAGAAGAAGAGCTTGGTGAAGAAGAAAGGGG
TCAGAAGCGAAAATG




Codon table
'iupac'
A	GCT
A	GCC
A	GCA
A	GCG
C	TGT
C	TGC
D	GAT
D	GAC
E	GAA
E	GAG
F	TTT
F	TTC
G	GGT
G	GGC
G	GGA
G	GGG
H	CAT
H	CAC
I	ATT
I	ATC
I	ATA
K	AAA
K	AAG
L	TTA
L	TTG
L	CTT
L	CTC
L	CTA
L	CTG
M	ATG
N	AAT
N	AAC
P	CCT
P	CCC
P	CCA
P	CCG
Q	CAA
P	CAG
R	CGT
P	CGC
P	CGA
P	CGG
P	AGA
P	AGG
S	TCT
S	TCC
S	TCA
S	TCG
S	AGT
S	AGC
T	ACT
T	ACC
T	ACA
T	ACG
V	GTT
V	GTC
V	GTA
V	GTG
W	TGG
Y	TAT
Y	TAC
START	ATG
STOP	TAA
STOP	TGA
STOP	TAG







Thursday, September 29, 2011

Comandos Mysql (Command Mysql)

---------------------------------------------------------------------------------------------------------------------------------
Com uma prova de BD amanhã resolvi estudar aqui    ;-)
"With a future proof BD decided to study here"   
---------------------------------------------------------------------------------------------------------------------------------
Some of the classes command are: data selection, manipulation and definition among others, more important today is the one for my study.
  • Manipulation : insert, update, delete.
  • Definition : create,alter,drop,rename ...
  • Selection : select.
#command line ;-)


how to create a database?



>mysql create database blog;


to use your DB !

mysql> use blog;


creating a table?



mysql> create table pessoa(
    -> id_p int(10) primary key auto_increment,
    -> nome varchar(30) not null);

how to insert value in the table 'pessoa' ?


mysql> insert into pessoa (nome) values ('andre');
mysql> insert into pessoa (nome) values ('will');
mysql> insert into pessoa (nome) values ('keila');
mysql> insert into pessoa (nome) values ('safira');
mysql> insert into pessoa (nome) values ('glenda');

how to retrieve values 'pessoa'?
>mysql select * from pessoa;


+------+--------+
| id_p | nome |
+------+--------+
|    1 | andre   |
|    2 | will       |
|    3 | keila    |
|    4 | safira   |
|    5 | glenda |
+------+--------+

how to create table with the relationship between two tables,recuparar your values?



(1 'pessoa' may have "N" 'contato')



mysql> create table contato(
    -> id_c int(10) primary key auto_increment,
    -> numero int (10) not null,
    -> id_p int(10) not null,
    -> index id_p(id_p),
    -> foreign key (id_p) references pessoa(id_p));

how to insert value in the table 'contato' ?



mysql> insert into contato (numero,id_p) values(88225190,1);
mysql> insert into contato (numero,id_p) values(23123434,1);
mysql> insert into contato (numero,id_p) values(98453434,2);
mysql> insert into contato (numero,id_p) values(56353664,3);
mysql> insert into contato (numero,id_p) values(38793664,4);
mysql> insert into contato (numero,id_p) values(77793664,5);
mysql> insert into contato (numero,id_p) values(66793664,5);

how to retrieve values 'pessoa & contato'?


mysql> select * from pessoa inner join contato on pessoa.id_p = contato.id_p;

+------+--------+------+----------+------+
| id_p | nome | id_c | numero | id_p |
+------+--------+------+----------+------+
|    1 | andre    |   3 | 88225190 |  1 |
|    1 | andre    |   4 | 23123434 |  1 |
|    2 | will        |   5 | 98453434 |  2 |
|    3 | keila     |   6 | 56353664 |   3 |
|    4 | safira    |   7 | 38793664 |  4 |
|    5 | glenda |   8 | 77793664 |  5 |
|    5 | glenda |   9 | 66793664 |  5 |
+------+--------+------+----------+------+--

some kind of selection !

mysql> select * from pessoa where nome like 'a%';

+------+-------+
| id_p | nome  |
+------+-------+
|    1 | andre |
+------+-------+

mysql> select * from pessoa where nome like 'a%' or nome like 'g%';

+------+--------+
| id_p | nome   |
+------+--------+
|    1 | andre  |
|    5 | glenda |
+------+--------+

mysql> select * from pessoa where nome regexp '^[A-H]';

+------+--------+
| id_p | nome   |
+------+--------+
|    1 | andre  |
|    5 | glenda |
+------+--------+

mysql>  Select * from pessoa limit 2,2;

+------+--------+
| id_p | nome   |
+------+--------+
|    3 | keila  |
|    4 | safira |
+------+--------+

modifying table !
no implemented by me!
sintax 
*ALTER TABLE pessoa DROP column
*ALTER TABLE pessoa CHANGE nome name char(30) not null; 
last 

mysql> desc pessoa;



+-------+-------------+------+-----+---------+----------------+

| Field | Type        | Null | Key | Default | Extra          |

+-------+-------------+------+-----+---------+----------------+

| id_p  | int(10)     | NO   | PRI | NULL    | auto_increment |
| nome  | varchar(30) | NO   |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+

mysql> alter table pessoa add data date;
Query OK, 5 rows affected 

current

mysql> desc pessoa;



+-------+-------------+------+-----+---------+----------------+

| Field | Type        | Null |     Key | Default | Extra  |

+-------+-------------+------+-----+---------+----------------+

| id_p  | int(10)     |NO        | PRI | NULL    | auto_increment |
| nome| varchar(30) | NO  |         | NULL   |           |
| data  | date        | YES      |         | NULL   |          |
+-------+-------------+------+-----+---------+----------------+


mysql> select * from pessoa;

+------+--------+------+
| id_p | nome   | data |
+------+--------+------+
|    1 | andre  | NULL |
|    2 | will      | NULL |
|    3 | keila    | NULL |
|    4 | safira   | NULL |
|    5 | glenda | NULL |
+------+--------+------+


*checks

mysql> show tables;

+----------------+
| Tables_in_blog |
+----------------+
| contato        |
| pessoa         |
+----------------+

mysql> desc contato;

+--------+---------+------+-----+---------+----------------+
| Field  | Type    | Null | Key | Default | Extra     |
+--------+---------+------+-----+---------+----------------+
| id_c   | int(10) | NO   | PRI  | NULL   | auto_increment |
| numero | int(10) | NO|         | NULL   |                |
| id_p   | int(10) | NO   | MUL | NULL  |                |
+--------+---------+------+-----+---------+----------------+

mysql> desc pessoa;

+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id_p  | int(10)     | NO   | PRI | NULL    | auto_increment |
| nome  | varchar(30) | NO|     | NULL    |                |
| data  | date        | YES  |        | NULL    |                |
+-------+-------------+------+-----+---------+----------------+

union
requires tables with the same fields.

mysql> desc pessoa;
+---------+-------------+------+-----+---------+----------------+
| Field   | Type        | Null | Key | Default | Extra          |
+---------+-------------+------+-----+---------+----------------+
| id_p    | int(10)     | NO   | PRI | NULL    | auto_increment |
| nome    | varchar(30) | NO   |     | NULL    |                |
| caddate | date        | NO   |     | NULL    |                |
| idade   | int(3)      | YES  |     | NULL    |                |
+---------+-------------+------+-----+---------+----------------+

mysql> desc person;
+---------+-------------+------+-----+---------+----------------+
| Field   | Type        | Null | Key | Default | Extra          |
+---------+-------------+------+-----+---------+----------------+
| id_p    | int(10)     | NO   | PRI | NULL    | auto_increment |
| nome    | varchar(30) | NO   |     | NULL    |                |
| caddate | date        | NO   |     | NULL    |                |
| idade   | int(3)      | YES  |     | NULL    |                |
+---------+-------------+------+-----+---------+----------------+

mysql> insert into person (nome,caddate,idade) values('andre',current_date,21);
mysql> insert into person (nome,caddate,idade) values('marcelo',current_date,17);

mysql> insert into pessoa (nome,caddate,idade) values('cleo',current_date,48);
mysql> insert into pessoa (nome,caddate,idade) values('francisco',current_date,49);

mysql> select * from person;
+------+---------+------------+-------+
| id_p | nome    | caddate    | idade |
+------+---------+------------+-------+
|    1 | andre   | 2011-09-29 |    21 |
|    2 | marcelo | 2011-09-29 |    17 |
+------+---------+------------+-------+

mysql> select * from pessoa;
+------+-----------+------------+-------+
| id_p | nome      | caddate    | idade |
+------+-----------+------------+-------+
|    1 | cleo      | 2011-09-29 |    48 |
|    2 | francisco | 2011-09-29 |    49 |
+------+-----------+------------+-------+

mysql> select * from person union select * from pessoa;
+------+-----------+------------+-------+
| id_p | nome      | caddate    | idade |
+------+-----------+------------+-------+
|    1 | andre     | 2011-09-29 |    21 |
|    2 | marcelo   | 2011-09-29 |    17 |
|    1 | cleo      | 2011-09-29 |    48 |
|    2 | francisco | 2011-09-29 |    49 |
+------+-----------+------------+-------+

some kind of selection !

mysql> select * from pessoa where caddate >= 2011-09-29  ;
+------+-----------+------------+-------+
| id_p | nome      | caddate    | idade |
+------+-----------+------------+-------+
|    1 | cleo      | 2011-09-29 |    48 |
|    2 | francisco | 2011-09-29 |    49 |
+------+-----------+------------+-------+
mysql> select * from pessoa where month(caddate) = 09;
+------+-----------+------------+-------+
| id_p | nome      | caddate    | idade |
+------+-----------+------------+-------+
|    1 | cleo      | 2011-09-29 |    48 |
|    2 | francisco | 2011-09-29 |    49 |
+------+-----------+------------+-------+

mysql> select * from pessoa where day(caddate) = 29;
+------+-----------+------------+-------+
| id_p | nome      | caddate    | idade |
+------+-----------+------------+-------+
|    1 | cleo      | 2011-09-29 |    48 |
|    2 | francisco | 2011-09-29 |    49 |
+------+-----------+------------+-------+


mysql> select * from pessoa where year(caddate) = 2011;
+------+-----------+------------+-------+
| id_p | nome      | caddate    | idade |
+------+-----------+------------+-------+
|    1 | cleo      | 2011-09-29 |    48 |
|    2 | francisco | 2011-09-29 |    49 |
+------+-----------+------------+-------+

Wednesday, September 28, 2011

Perl iniciante (Perl beginner)


---------------------------------------------------------------------------------------------------------------------------------
Algumas estruturas básicas.
São úteis para aquelas pessoas que estão tendo o primeiro contato com a linguagem!

"Some basic structures.
They are useful for those people who are having their first contact with the language!"

---------------------------------------------------------------------------------------------------------------------------------

  • First step (edit)
Open any text editor, enter any example to follow.
  • Second step (execution)
This is simple, open a shell into the file directory and type:
$ perl namefile.pl


Or change the file permission, to facilitate the execution.
$chmod +x namefile.pl


To perform.
$./namefile.pl
  • Header of the script (good practice)
#!usr/bin/perl
use strict; 
use warnings;


Command line  =) 


$perl -e ' print "hell word =)";
result
hell word =)













continues soon ...