Last active
July 2, 2019 14:45
-
-
Save telatin/9d0e94e54a9a1a4fac3a9d57d3ad3e42 to your computer and use it in GitHub Desktop.
Perl snippets #perl
This file contains 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/bin/perl | |
use Getopt::Long; | |
my ($opt_help, $opt_version, $opt_input); | |
my $result = GetOptions( | |
'i|input=s' => \$opt_input, | |
'version' => \$opt_version, | |
'help' => \$opt_help | |
); | |
This file contains 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
sub stdev { | |
my $number_list_reference = shift @_; | |
my $sum = 0; | |
my $delta = 0; | |
my $count = 0; | |
my $mean = 0; | |
my $stddev = 0; | |
foreach $number (@{$number_list_reference}) { | |
$count++; | |
$delta = $number - $mean; | |
$mean = $mean + ($delta / $count); | |
$sum = $sum + $delta*($number - $mean); | |
} | |
return (0,0) if ($count == 1); | |
$stddev = sqrt($sum/($count - 1)); | |
#return(sprintf("%.2f", $stddev), sprintf("%.2f",$mean)); | |
return($stddev , $mean); | |
} |
This file contains 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
use Term::ANSIColor qw(:constants); | |
print BOLD, BLUE, "This text is in bold blue.\n", RESET; | |
{ | |
local $Term::ANSIColor::AUTORESET = 1; | |
print BOLD BLUE "This text is in bold blue.\n"; | |
print "This text is normal.\n"; | |
} |
This file contains 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
use File::Basename; | |
# if $path = '/lustre/projects/myfolder/file.ext'... | |
my $base = basename($path); | |
my $dir = dirname($path); | |
my ($base, $dir, $ext) = fileparse($path); |
This file contains 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
sub formatsec { | |
my $time = shift; | |
my $days = int($time / 86400); | |
$time -= ($days * 86400); | |
my $hours = int($time / 3600); | |
$time -= ($hours * 3600); | |
my $minutes = int($time / 60); | |
my $seconds = $time % 60; | |
$days = $days < 1 ? '' : $days .'d '; | |
$hours = $hours < 1 ? '' : $hours .'h '; | |
$minutes = $minutes < 1 ? '' : $minutes . 'm '; | |
$time = $days . $hours . $minutes . $seconds . 's'; | |
return $time; | |
} |
This file contains 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/bin/perl | |
use Pod::Usage; | |
my ($opt_help); | |
pod2usage({-exitval => 0, -verbose => 2}) if $opt_help; | |
__END__ | |
=head1 NAME | |
B<Bold program name> - this program does this | |
=head1 AUTHOR | |
Andrea Telatin <andrea@telatin.com> | |
=head1 SYNOPSIS | |
this.pl --kmer=KMERLEN --peak=PEAK --fastq=FASTQ [--fastq=FASTQ] | |
=head1 DESCRIPTION | |
After running jellyfish with a particular KMERLEN and one or more FASTQ files, | |
determine the PEAK using jellyplot.pl and find_valleys.pl. Next, use this | |
PEAK as well as the KMERLEN and the FASTQ files used in the jellyfish run | |
as input. The script will determine the coverage and genome size. | |
=head1 TYPICAL SESSION | |
=over 2 | |
# count k-mers (see jellyfish documentation for options) | |
gzip -dc reads1.fastq.gz reads2.fastq.gz | jellyfish count -m 31 -o fastq.counts -C -s 10000000000 -U 500 -t 30 /dev/fd/0 | |
# generate a histogram | |
jellyfish histo fastq.counts_0 > fastq.counts_0.histo | |
# generate a pdf graph of the histogram | |
jellyplot.pl fastq.counts_0.histo | |
# look at fastq.counts_0.histo.pdf and identify the approximate peak | |
# use find_valleys.pl to help pinpoint the actual peak | |
find_valleys.pl fastq.counts_0.histo | |
# estimate the size and coverage | |
estimate_genome_size.pl --kmer=31 --peak=42 --fastq=reads1.fastq.gz reads2.fastq.gz | |
=back | |
=head1 BUGS | |
Please report them to <andrea@telatin.com> | |
=head1 COPYRIGHT | |
Copyright (C) 2013 Andrea Telatin | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment