Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Perl script that gets the TreeFam clean tree for a family.
#!/usr/local/bin/perl
#
# Perl script get_trees2.pl
# Written by Avril Coghlan (alc@sanger.ac.uk)
# 6-Mar-07.
# Updated 6-Dec-07.
#
# For the TreeFam project.
#
# This perl script gets the TreeFam clean tree for a family.
#
# The command-line format is:
# % perl <get_trees2.pl> family
# where family is the TreeFam family of interest.
#
#------------------------------------------------------------------#
# CHECK IF THERE ARE THE CORRECT NUMBER OF COMMAND-LINE ARGUMENTS:
$num_args = $#ARGV + 1;
if ($num_args != 1)
{
print "Usage of get_trees2.pl\n\n";
print "perl get_trees2.pl <family>\n";
print "where <family> is the TreeFam family of interest.\n";
print "For example, >perl get_trees2.pl TF101001\n";
exit;
}
use DBI;
# FIND THE NAME OF THE FAMILY:
$family = $ARGV[0];
#------------------------------------------------------------------#
# CONNECT TO THE MYSQL DATABASE:
$dbh = DBI->connect("dbi:mysql:treefam_7:db.treefam.org:3308", 'anonymous', '') || return;
$table_w = "trees";
# READ IN THE INPUT LIST:
print STDERR "Getting clean tree for $family...\n";
$found_tree = 0;
$st = "SELECT TREE, TYPE from $table_w WHERE AC=?";
$sth = $dbh->prepare($st) or die "Cannot prepare $st: $dbh->errstr\n";
$rv = $sth->execute($family) or die "Cannot execute the query: $sth->errstr";
if ($rv >= 1)
{
while ((@array) = $sth->fetchrow_array)
{
$the_tree = $array[0];
$type = $array[1];
if ($type eq 'CLEAN')
{
print "$the_tree\n";
$found_tree = 1;
}
}
}
if ($found_tree == 0) { print STDERR "WARNING: did not find clean tree for $family\n";}
#------------------------------------------------------------------#
print STDERR "FINISHED.\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment