Chemistry-SQL

 view release on metacpan or  search on metacpan

lib/Chemistry/SQL.pm  view on Meta::CPAN

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
        | MOL      |
        | mysql    |
        | test     |
        +----------+
 
I<* Example of the components table estructure:>
 
        +-------------+--------------+------+-----+---------+----------------+
        | Field       | Type         | Null | Key | Default | Extra          |
        +-------------+--------------+------+-----+---------+----------------+
        | formula     | varchar(250) |      | MUL |         |                |
        | id          | int(11)      |      | PRI | NULL    | auto_increment |
        | smilesform  | blob         |      |     |         |                |
        | description | blob         |      |     |         |                |
        +-------------+--------------+------+-----+---------+----------------+
 
=cut
 
sub create_tables_mysql
{       my $self=shift;
        $self->{sql}="CREATE TABLE `listafter` (

lib/Chemistry/SQL.pm  view on Meta::CPAN

231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
$self->{sql}="CREATE TABLE `listbefore` (
`id` int(11) NOT NULL auto_increment,
`smilesform` blob NOT NULL,
PRIMARY KEY(`id`)
)  ";
$self->{sth} = $self->{dbh}->prepare($self->{sql});
$self->{sth}->execute ;
 
# Creating components Table
$self->{sql}="CREATE TABLE `components` (
`formula` varchar(250) NOT NULL default '',
`id` int(11) NOT NULL auto_increment,
`smilesform` blob NOT NULL,
`description` blob NOT NULL,
PRIMARY KEY  (`id`),
KEY `formula` (`formula`)
)  ";
$self->{sth} = $self->{dbh}->prepare($self->{sql});
$self->{sth}->execute ;
 
# Creating Reactions Table     
$self->{sql}="CREATE TABLE `reactions` (
`formula` varchar(255) NOT NULL default '',
`smilesbefore` blob NOT NULL,
`smilesafter` blob NOT NULL,
`atommap_forward` blob NOT NULL,
`atommap_reverse` blob NOT NULL,
`id` int(11) NOT NULL auto_increment,
`direction` tinyint(1) NOT NULL default '0',
`description` blob NOT NULL,
PRIMARY KEY  (`id`),
KEY `formula` (`formula`)
) ";
$self->{sth} = $self->{dbh}->prepare($self->{sql}) ;
$self->{sth}->execute ;
 
# Creating Results Table       
$self->{sql}="CREATE TABLE `results` (
`id` int(11) NOT NULL auto_increment,
`q_name` varchar(255) NOT NULL default '',
`formula` varchar(255) NOT NULL default '',
`smilesbefore` blob NOT NULL,
`smilesafter` blob NOT NULL,
`atommap` blob NOT NULL,
`idreact` int(11) NOT NULL default '0',
`direction` tinyint(1) NOT NULL default '0',
`is_root` tinyint(1) NOT NULL default '0',
`level` int(11) NOT NULL default '0',
PRIMARY KEY  (`id`),
KEY `busquedakey` (`formula`,`idreact`),
KEY `qnamekey` (`q_name`),
KEY `levelkey` (`level`)
)  ";
$self->{sth} = $self->{dbh}->prepare($self->{sql}) ;
$self->{sth}->execute;   
 
# Creating Solution Graph      
$self->{sql}="CREATE TABLE `sgraph` (
`id` int(11) NOT NULL auto_increment,
`q_name` varchar(255) NOT NULL default '',
`formula` varchar(255) NOT NULL default '',
`smilesbefore` blob NOT NULL,
`smilesafter` blob NOT NULL,
`atommap` blob NOT NULL,
`idreact` int(11) NOT NULL default '0',
`direction` tinyint(1) NOT NULL default '0',
`is_root` tinyint(1) NOT NULL default '0',
`reaction_smiles` blob NOT NULL default '',
`painted` tinyint(1) NOT NULL default '0',
PRIMARY KEY  (`id`),
KEY `busqueda` (`formula`,`idreact`),
KEY `q_name` (`q_name`)
)  ";
$self->{sth} = $self->{dbh}->prepare($self->{sql}) ;
$self->{sth}->execute;   
 
# Creating  quimics    
$self->{sql}="CREATE TABLE `quimics` (
`q_name` varchar(250) NOT NULL default '',
`descripcio` blob NOT NULL,
PRIMARY KEY  (`q_name`)

lib/Chemistry/SQL.pm  view on Meta::CPAN

450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
This function is used in the insertion of components before to inserting them,
because it checks if them already exist.
 
=cut
 
sub component_exist    
{       my $self = shift;
        my ($component) = @_;
        my $result = 0;
        my $formula = $component->sprintf("%f");
        my $smilesform = $self->smiles_string($component);
        $self->{sql} = "SELECT smilesform,id FROM components where formula =
                        '$formula'";
        $self->{sth} = $self->{dbh}->prepare($self->{sql});
        $self->{sth}->execute;
        while ((my @row = $self->{sth}->fetchrow_array)&&($result==0))
        {       if ($row[0] eq $smilesform) {$result=$row[1];}
        }
        $self->{sth}->finish;
        return $result;
}
 
=item $db->insert_component(component, description)
 
Inserts component in the components table.
 
=cut
 
sub insert_component   
{       my $self=shift;
        my ($component,$description) = @_;
        my $formula = $component->sprintf("%f");
        my $smilesform = $self->smiles_string($component);
        if (($self->component_exist($component))==0)
        {      
                $self->{sql} = "INSERT INTO components
                (formula,smilesform,description)
                VALUES('$formula','$smilesform','$description')";
                $self->{sth}= $self->{dbh}->prepare($self->{sql});
                $self->{sth}->execute;
        }
        $self->{sth}->finish;
}
 
=item $db->inscomp_from_file(file)
 
Imports components from I<smilesformat> file.
 
This function imports a I<data.smi> file into the components table. It is often
used in the initialitzation of the database.
 
=cut
 
sub inscomp_from_file
{       my $self=shift;
        my($file)=@_;
        my @mols = Chemistry::Mol->read($file, format => 'smiles');
        my $smilesform="";
        my $formula = "";
        my $repeat=0;
        my $ending_value = scalar(@mols) ;
        for(my $counter=0 ; $counter < $ending_value ; $counter++)
        {       $self->insert_component($mols[$counter],"");
        }              
        return 1;
}
 
=item $db->recover_comp(formula, smilesform)
 
This function returns the components.
 
Options of recover_comp function:
 
        -------------------------------
        |formula      |   smilesform  | Result
        -------------------------------
        |  blank      |   ------      | All components returned
        -------------------------------
        |  value set  |   blank       | All components with formula parameter
        -------------------------------
        | value set   |   value set   | smilesform component is returned
        -------------------------------
 
* I<Examples:>
 
Returning all components in database:
 
        $db1->recover_comp("","")
 
=cut
 
sub recover_comp
{       my $self=shift;
        my ($formula,$smilesform)=@_;
        my @list=();
        if ($formula eq "")
        {$self->{sql} = "SELECT smilesform FROM components";}
        else
        {$self->{sql} = "SELECT smilesform FROM components where formula=
                        '$formula'";}
        $self->{sth} = $self->{dbh}->prepare($self->{sql});
        $self->{sth}->execute;
        if ($smilesform eq "")
        {while (my $row = $self->{sth}->fetchrow)
         {      push @list, Chemistry::Mol->parse($row, format => 'smiles');
         }
        }
        else
        {while (my $row = $self->{sth}->fetchrow)
         {      if ($row eq $smilesform)

lib/Chemistry/SQL.pm  view on Meta::CPAN

568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
=back
 
=head2 Reactions functions
 
Functions to work with the reactions and the database, and they are:
 
=cut
 
=over 4
 
=item $db->reaction_exist(smilesbefore, smilesafter, formula)
 
It tests if the reaction described is in the database selecting the formula
reaction, and test if smilesbefore and smilesafter are the same that the
parameters describe.
 
=cut
 
 
sub reaction_exist     
{       my $self=shift;
        my ($smilesbefore,$smilesafter,$formula) = @_;
        my $result = 0;
        $self->{sql} = "SELECT smilesbefore,smilesafter,id FROM reactions
        where formula = '$formula' ";
        $self->{sth} = $self->{dbh}->prepare($self->{sql});
        $self->{sth}->execute;
        while (my @row = $self->{sth}->fetchrow_array)
        {       if (($row[0] eq $smilesbefore) && ($row[1] eq $smilesafter))
                {$result=$row[2];}
        }
        return $result;
}
 
=item $db->react_id(reaction)

lib/Chemistry/SQL.pm  view on Meta::CPAN

607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
=cut
 
 
sub react_id   
{       my $self=shift;
        my ($reaction) = @_;
        my $id;
        my $substrate = $reaction->substrate;
        my $product = $reaction->product;
        my $formula = $substrate->sprintf("%f");
        my $smilesbefore = $substrate->sprintf("%s");
        my $smilesafter = $product->sprintf("%s");
        $self->{sql} = "SELECT id,smilesbefore,smilesafter FROM reactions
                        where formula = '$formula'";
        $self->{sth} = $self->{dbh}->prepare($self->{sql});
        $self->{sth}->execute;
        while (my @row = $self->{sth}->fetchrow_array)
        {       if (($row[1] eq $smilesbefore) && ($row[2] eq $smilesafter))
                 {$id = $row[0];}
        }
        $self->{sth}->finish;
        return $id;
}

lib/Chemistry/SQL.pm  view on Meta::CPAN

668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
* Example of forward reaction insertion :
 
        $db1->rection_insert($r,"Description of my Reaction",0)
 
=cut
 
sub reaction_insert    
{       my $self=shift;
        my ($reaction,$description,$direction) = @_;
        my $substrate = $reaction->substrate;
        my $formula = $substrate->sprintf("%f");
        my $product = $reaction->product;
        my $smilesbefore = $substrate->sprintf("%s");
        my $smilesafter = $product->sprintf("%s");
        my $atommapf;
        my $atommapr;
        my @map = $substrate->atom_map;
        $atommapf=split(//,@map);
        my @map = $product->atom_map;
        $atommapr=split(//,@map);
        if (($self->reaction_exist($smilesbefore,$smilesafter,$formula))==0)
        {        $self->{sql} = "INSERT INTO reactions
                (formula,smilesbefore,smilesafter,atommap_forward,
                atommap_reverse,description,direction)
                VALUES('$formula','$smilesbefore','$smilesafter','$atommapf'
                ,'$atommapr','$description','$direction')";
                $self->{sth} = $self->{dbh}->prepare($self->{sql});
                $self->{sth}->execute;   
        }
}
 
=item $db->string_react(id)
 
Returns the string of the reaction with a SMILES format.

lib/Chemistry/SQL.pm  view on Meta::CPAN

1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
                        $sth->execute;
                        $sth->finish;
                }
        }
        $self->{sql}= "delete from listafter";
        $self->{sth} = $self->{dbh}->prepare($self->{sql});
        $self->{sth}->execute;
        $self->{sth}->finish;
}
 
=item $db->result_before_exists(formula, smilesform, qname)
 
Test for one component in I<cha> if the result already has been calculated.
 
=cut
 
sub result_before_exists
{       my $self=shift;
        my ($formula,$smilesform,$qname)=@_;
        my $result = 0;
        $self->{sql} = "SELECT smilesbefore FROM results where formula =
                        '$formula' AND q_name='$qname'";
        $self->{sth} = $self->{dbh}->prepare($self->{sql});
        $self->{sth}->execute;
        while (my $rows=$self->{sth}->fetchrow)
        {       if ($rows eq $smilesform)
                {$result=1;}   
        }
        return $result;
}
 
=back

lib/Chemistry/SQL.pm  view on Meta::CPAN

1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
=cut
 
sub gsg_fsc
{       my $self=shift;
        my ($startcomp)=@_;
        my $smilesform;
        my $component;
        my @child;my $rcomponent;
        foreach $component(@$startcomp)
        {       my $formula=$component->sprintf("%f");
                $smilesform=$self->smiles_string($component);
                my $sql = "SELECT smilesbefore,smilesafter,idreact,direction,
                        atommap FROM results where formula = '$formula'";
                my $sth = $self->{dbh}->prepare($sql);
                $sth->execute;
                # Create the root Graph Nodes
                my $counter=0;
                while (my @row = $sth->fetchrow_array)
                {       # creem el component
                         if ($row[0] eq $smilesform)
                         {     
                                push @child,$row[1];
                                $self->sgraph_insert($formula,$row[0],$row[1],
                                        $row[2],$row[3],$row[4],"","1");
                         }
                }
                # Get all the others
                # Firts Get the Child Components,
                # when detect a new child it is added in the list
                foreach $rcomponent(@child)
                {       my $component = Chemistry::Mol->parse($rcomponent,
                                        format => 'smiles');
                        my $formula=$component->sprintf("%f");
                        my $smilestring=$self->smiles_string($component);
                        my $sql  = "select smilesbefore,smilesafter,idreact,
                                   direction,atommap from results where
                                   formula = '$formula' ";
                        my $sth = $self->{dbh}->prepare($sql);
                        $sth->execute;
                        while (my @row = $sth->fetchrow_array)
                        {       if ($row[0] eq $smilestring)
                                {       if (!($self->sgraph_exist($formula,
                                                $row[0],$row[1],$row[2])))     
                                        {       push @child,$row[1];
                                                $self->sgraph_insert($formula,
                                                $row[0],$row[1],$row[2],
                                                $row[3],$row[4],"","0");
                                        }
                                }
                        }
                }
        }
}
 
=item $db->gsg_fec(endcomp)

lib/Chemistry/SQL.pm  view on Meta::CPAN

1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
=cut
 
sub gsg_fec
{       my $self=shift;
        my ($endcomp)=@_;
        my $smilesform;
        my $component;
        my @fathers;my $rcomponent;
        my $invdir;#inverted direction
        foreach $component(@$endcomp)
        {       my $formula=$component->sprintf("%f");
                $smilesform=$self->smiles_string($component);
                my $sql = "SELECT smilesbefore,smilesafter,idreact,direction,
                        atommap FROM results where formula = '$formula'";
                my $sth = $self->{dbh}->prepare($sql);
                $sth->execute;
                # Create the root Graph Nodes
                my $counter=0;
                while (my @row = $sth->fetchrow_array)
                {
                         if ($row[1] eq $smilesform)
                         {     
                                if ($row[3]==1)
                                {$invdir=0;}
                                else
                                { if ($row[3]==0)
                                  {$invdir=1;}
                                }
                                push @fathers,$row[0];
                                $self->sgraph_insert($formula,$row[1],$row[0],
                                $row[2],$invdir,$row[4],"","1");
                         }
                }
                 
                # Get all the others
                foreach $rcomponent(@fathers)
                {       my $component = Chemistry::Mol->parse($rcomponent,
                                        format => 'smiles');
                        my $formula=$component->sprintf("%f");
                        my $smilestring=$self->smiles_string($component);
                        my $sql  = "select smilesbefore,smilesafter,idreact,
                                        direction,atommap from results where
                                        formula = '$formula' ";
                        my $sth = $self->{dbh}->prepare($sql);
                        $sth->execute;
                        while (my @row = $sth->fetchrow_array)
                        {       if ($row[1] eq $smilestring)
                                {        if ($row[3]==1)
                                         {$invdir=0;}
                                         else
                                         { if ($row[3]==0)
                                           {$invdir=1;}
                                         }
                                        if (!($self->sgraph_exist($formula,
                                                $row[1],$row[0],$row[2])))
                                        {       push @fathers,$row[0];
                                                $self->sgraph_insert($formula,
                                                $row[1],$row[0],$row[2],
                                                $invdir,$row[4],"","0");
                                        }
                                }
                        }
                }
        }
}
 
=item $db->gsg_levels(qname, initlevel, endlevel)

lib/Chemistry/SQL.pm  view on Meta::CPAN

1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
I<initlevel>: First level
 
I<endlevel>: Last level to draw
 
=cut
 
 
sub gsg_levels
{       my $self=shift;
        my ($qname,$initlevel,$endlevel)=@_;
        my $sql = "SELECT level,formula,smilesbefore,smilesafter,idreact,
                direction,atommap FROM results where q_name='$qname'
                AND level >= '$initlevel' AND level<='$endlevel'";
        my $sth = $self->{dbh}->prepare($sql);
        $sth->execute;
        while (my @row = $sth->fetchrow_array)
        {       if($row[0]==$initlevel)
                {$self->sgraph_insert($row[1],$row[2],$row[3],$row[4],$row[5],
                                        $row[6],$qname,"1");   
                }
                else

lib/Chemistry/SQL.pm  view on Meta::CPAN

1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
Generates a complete I<cha> solution graph, inserting data into solution graph
table.
 
=cut
 
 
sub gsg_complete
{       my $self=shift;
        my ($qname)=@_;
        my $sql = "SELECT formula,smilesbefore,smilesafter,idreact,
        direction,atommap,is_root FROM results where q_name='$qname'";
        my $sth = $self->{dbh}->prepare($sql);
        $sth->execute;
        while (my @row = $sth->fetchrow_array)
        {       $self->sgraph_insert($row[0],$row[1],$row[2],$row[3],$row[4],
                                        $row[5],$qname,$row[6]);        }
        $self->{sth}->finish;
}
 
=item $db->sgraph_exist(formula, smilesbefore, smilesafter, idreact)
 
Checks if a result is in the solution graph table
 
=cut
 
 
sub sgraph_exist
{       my $self=shift;
        my ($formula,$smilesbefore,$smilesafter,$idreact) = @_;
        my $result=0;
        $self->{sql} = "SELECT smilesbefore, smilesafter FROM sgraph where
                        formula = '$formula'  AND idreact = '$idreact' ";
        $self->{sth} = $self->{dbh}->prepare($self->{sql});
        $self->{sth}->execute;
        #Finding for a equal smilesbefore and smilesafter strings
        while (my @row = $self->{sth}->fetchrow_array)
        {       if (($row[0] eq $smilesbefore) && ($row[1] eq $smilesafter))
                {$result=1;}
        }
        # 0 if not exist
        $self->{sth}->finish;
        return $result;
}
 
=item $db->sgraph_insert(formula,smilesbefore,smilesafter,idreact,direction,
atommap,q_name,is_root)
 
Solution graph insertion.
 
=cut
 
 
sub sgraph_insert
{       my $self=shift;
        my ($formula,$smilesbefore,$smilesafter,$idreact,$direction,$atommap,
        $qname,$is_root) = @_;
        if (!($self->sgraph_exist($formula,$smilesbefore,$smilesafter,$idreact)))
        {       # Get the Reaction Properties and Insert into the
                # Result Graph Table
                my $sql = "Select smilesbefore,smilesafter from reactions 
                                where id = $idreact";
                my $sth $self->{dbh}->prepare($sql);
                $sth->execute;
                my $smilesreaction;
                if (my @row=$sth->fetchrow_array)
                {       $smilesreaction = $row[0].">>".$row[1];
                }
                $sth->finish;
                $self->{sql} = "INSERT INTO sgraph
                (formula,smilesbefore,smilesafter,idreact,direction,atommap,
                q_name,is_root,reaction_smiles)
                VALUES('$formula','$smilesbefore','$smilesafter','$idreact',
                '$direction','$atommap','$qname','$is_root','$smilesreaction')";
                $self->{sth} = $self->{dbh}->prepare($self->{sql});
                $self->{sth}->execute;
                $self->{sth}->finish;
                return 1;
        }
        else
        {return 0;}
}
 
=back
 
=head2 Result functions
 
These functions are used to work with the results generated, and they are:
 
=cut
 
=over 4
 
=item $db->resultinsert(formula, smilesbefore, smilesafter, idreact, direction,
atommap, qname, is_root, level)
 
Inserts a result in the database.
 
=cut
 
sub result_insert
{       my $self=shift;
        my ($formula,$smilesbefore,$smilesafter,$idreact,$direction,$atommap,
        $qname,$is_root,$level) = @_;
        if ($smilesbefore eq $smilesafter) {return 0;}
         
        if (!($self->results_exist($formula,$smilesbefore,$smilesafter,
        $idreact,$qname)))
        {       $self->{sql} = "INSERT INTO results
                (formula,smilesbefore,smilesafter,idreact,direction,atommap,
                q_name,is_root,level)
                VALUES('$formula','$smilesbefore','$smilesafter','$idreact',
                '$direction','$atommap','$qname','$is_root','$level')";
                $self->{sth} = $self->{dbh}->prepare($self->{sql});
                $self->{sth}->execute;
                $self->{sth}->finish;
                return 1;
        }
        else
        {return 0;}
}
 
=item $db->resultexist(formula, smilesbefore, smilesafter, idreact, qname)
 
Checks if the result already exists in the database.
 
=cut
 
sub results_exist
{       my $self=shift;
        my ($formula,$smilesbefore,$smilesafter,$idreact,$qname) = @_;
        my $resultado=0;
        $self->{sql} = "SELECT smilesbefore, smilesafter FROM results where
                        formula = '$formula'  AND idreact = '$idreact'
                        AND q_name='$qname'";
        $self->{sth} = $self->{dbh}->prepare($self->{sql});
        $self->{sth}->execute;
        while (my @row = $self->{sth}->fetchrow_array)
        {       if ((@row[0] eq $smilesbefore) && (@row[1] eq $smilesafter))
                {$resultado=1;}
        }
        $self->{sth}->finish;
        return $resultado;
}

lib/Chemistry/SQL.pm  view on Meta::CPAN

1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
=cut
 
 
sub graphic_information
{       my $self = shift;
        # @_ is the quimics name
        my ($id,$component) = @_;
        my @info;
        my $smilesform = $self->smiles_string($component);
        my $formula = $component->sprintf("%f");
        $self->{sql} = "select smilesbefore,direction,atommap,reaction_smiles
                        from sgraph where id='$id'";
        $self->{sth} = $self->{dbh}->prepare($self->{sql});
        $self->{sth}->execute;
        if (my @row = $self->{sth}->fetchrow_array)
        {               push @info, $smilesform;
                        push @info, $formula;
                        push @info, $row[0];
                        push @info, $row[1];
                        push @info, $row[2];
                        push @info, $row[3];   
        }
        return \@info;
}
 
=item $db->rec_root()

lib/Chemistry/SQL.pm  view on Meta::CPAN

1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
=item $db->rec_child(component)
 
Returns all the child components from one component.
 
=cut
 
sub rec_child
{       my $self = shift;
        my ($component)=@_;
        my $formula = $component->sprintf("%f");
        my $smilesform = $self->smiles_string($component);
        $self->{sql} = "select id,smilesbefore,smilesafter from sgraph
                        where formula = '$formula' and painted=0";
        $self->{sth} = $self->{dbh}->prepare($self->{sql});
        $self->{sth}->execute;
        my @result;my @ids;
        while (my @row = $self->{sth}->fetchrow_array)
        {       # creem el component
                 if ($row[1] eq $smilesform)
                 {push @result, Chemistry::Mol->parse($row[2],
                                format => 'smiles');
                  push @ids,$row[0];
                  push @result,$row[0]; }



( run in 0.251 second using v1.01-cache-2.11-cpan-0f795438458 )