pickprimers.pl: first part

After the break I copied the program we wrote today in class…
Remember that it
1) Takes parameters from the user
2) Parse the multifasta file with contigs saving to $seq1 and $seq2 the sequence of desired contigs

#!/usr/bin/perl
 
# Constant: we write here the FILENAME of the multifasta 
# file containing the contigs
$multifasta = '/home/geno/tools/contigs.fna';
 
# We print a MESSAGE for the user
print STDERR "
   Pick Primer Tool v.01
 
   Parameters:
   contig1 direction1 contig2 direction2
 
   direction1,2 = U or C
 
";
 
# We populate variables with USER PARAMETERS
($contig1, $dir1, $contig2, $dir2) = @ARGV;
 
# And print them for the user
print STDERR "
contig1   $contig1
dir1      $dir1
contig2   $contig2
dir2      $dir2
";
open(I, "$multifasta") || die " ERROR: can't open $multifasta :(\n";
 
# Here we read the multifasta file
 
while (<I>) {
	chomp($_);
 
	if ($_=~/>(.*)/) {
 
	   if ($header eq $contig1) {
	   	 	$seq1 = $seq;
	   }
	   if ($header eq $contig2) {
	   		$seq2 = $seq;
	   }
 
	   $header=$1;
	   $seq = '';
	} else {
		$seq=$seq.$_;
	}
}
 
if ($header eq $contig1) {
 	$seq1 = $seq;
}
if ($header eq $contig2) {
	$seq2 = $seq;
}
 
if (length($seq1) == 0) {
	die "$contig1 was not found\n";
}
if (length($seq2) == 0) {
	die "$contig2 was not found\n";
}

Leave a Reply

Your email address will not be published.