Thursday, March 4, 2010

Updating mySql database from Perl

Perl script to read multifasta file calculate GC content,GC Skew and insert into mySql database.


use DBI;

$dbh = DBI->connect('DBI:mysql:meta', 'root', 'password'
) || die "Could not connect to database: $DBI::errstr";

my ($infile) = @ARGV;
open(IN, "$infile");

my $jcvi_read,$leng,$gccont=0,$gcskew=0,$seq="";

while(my $line = ){
if ($line =~ /^\>/) {#reading header line

if($jcvi_read !=0){

$dbh->do("INSERT into metadata (jcvi_read,full_length,gc_content,gc_skew_orient,sequence) VALUES('$jcvi_read','$leng','$gccont','$gcskew','$seq')");#inserting the data into mySql Database
my @a = split(/\//, $line);
my @b = split(/\_/, $a[0]);
$jcvi_read = $b[2];
my @c = split(/\=/, $a[1]);
$leng = $c[1];
# print $jcvi_read."\n";
else{#reading and analysing the sequence
$seq = $seq.$line;
my @char =split(//,$line);
if($_ eq "G"|| $_ eq "C"){$gccont++;}# Calculating GC content
if($_ eq "G"){$gcskew++;}#Calcualting GC skew
if($_ eq "C"){$gcskew--;}
#print $gcskew."\n";

1 comment:

Max said...

What did you say