Skip to content

Instantly share code, notes, and snippets.

@avrilcoghlan
Created March 1, 2013 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avrilcoghlan/5064950 to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/perl
#
# Perl script list_treefam_families.pl
# Written by Avril Coghlan (alc@sanger.ac.uk)
# 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