Created
March 1, 2013 14:20
-
-
Save avrilcoghlan/5064950 to your computer and use it in GitHub Desktop.
Perl script that makes a list of all families in the TreeFam mysql database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
# | |
# Perl script list_treefam_families.pl | |
# Written by Avril Coghlan ([email protected]) | |
# 27-Feb-07. | |
# Updated 6-Dec-07. | |
# | |
# This perl script makes a list of families in the TreeFam mysql database. | |
# | |
# The command-line format is: | |
# % perl <list_treefam_families.pl> <release> | |
# where <release> is the release of the TreeFam database to use. | |
# | |
# | |
#------------------------------------------------------------------# | |
# CHECK IF THERE ARE THE CORRECT NUMBER OF COMMAND-LINE ARGUMENTS: | |
$num_args = $#ARGV + 1; | |
if ($num_args != 1) | |
{ | |
print "Usage of list_treefam_families.pl\n\n"; | |
print "perl list_treefam_families.pl <release>\n"; | |
print "where <release> is the release of the TreeFam database to use.\n"; | |
print "For example, >perl -w list_treefam_families.pl 4\n"; | |
exit; | |
} | |
#------------------------------------------------------------------# | |
# DECLARE MYSQL USERNAME AND HOST: | |
use lib "/home/bcri/acoghlan/x86_64-linux-thread-multi"; | |
use DBI; | |
# FIND WHICH RELEASE OF THE TREEFAM DATABASE TO USE: | |
$release = $ARGV[0]; | |
#------------------------------------------------------------------# | |
# GET A LIST OF ALL TREEFAM-A FAMILIES: | |
$database = "dbi:mysql:treefam_".$release.":db.treefam.org:3308"; | |
$dbh = DBI->connect("$database", 'anonymous', '') || return; | |
$table_w = 'familyA'; | |
$st = "SELECT AC from $table_w"; | |
$sth = $dbh->prepare($st) or die "Cannot prepare $st: $dbh->errstr\n"; | |
$rv = $sth->execute or die "Cannot execute the query: $sth->errstr"; | |
if ($rv >= 1) | |
{ | |
while ((@array) = $sth->fetchrow_array) | |
{ | |
$AC = $array[0]; | |
print "$AC\n"; | |
} | |
} | |
$rc = $dbh->disconnect(); | |
$rc = ""; | |
print STDERR "Read in list of TreeFam-A families...\n"; | |
# GET A LIST OF ALL TREEFAM-B FAMILIES: | |
$dbh = DBI->connect("$database", 'anonymous', '') || return; | |
$table_w = 'familyB'; | |
$st = "SELECT AC from $table_w"; | |
$sth = $dbh->prepare($st) or die "Cannot prepare $st: $dbh->errstr\n"; | |
$rv = $sth->execute or die "Cannot execute the query: $sth->errstr"; | |
if ($rv >= 1) | |
{ | |
while ((@array) = $sth->fetchrow_array) | |
{ | |
$AC = $array[0]; | |
print "$AC\n"; | |
} | |
} | |
$rc = $dbh->disconnect(); | |
$rc = ""; | |
print STDERR "Read in list of TreeFam-B families...\n"; | |
#------------------------------------------------------------------# | |
print STDERR "FINISHED.\n"; | |
#------------------------------------------------------------------# | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment