<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: All]]></title>
	<link>https://bioinformaticsonline.com/snippets?offset=400</link>
	<atom:link href="https://bioinformaticsonline.com/snippets?offset=400" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/28042/rpkm-normalization-r-script</guid>
	<pubDate>Fri, 24 Jun 2016 17:45:55 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/28042/rpkm-normalization-r-script</link>
	<title><![CDATA[RPKM normalization- R script]]></title>
	<description><![CDATA[<code>P&lt;-read.table(&quot;input_table.txt&quot;,sep=&quot;\t&quot;,header=T)

len &lt;- ncol(p)

rownames(p) &lt;- p[,1]

for(i in 2:ncol(p)-1)

{

d &lt;-p[,i]

l &lt;- p[,len] #accessing the length column

cS &lt;- sum(as.numeric(p[,i])) #Total mapped reads per sample 

rpkm[[i]] &lt;- (10^9)*(as.numeric(p[,i]))/(as.numeric(l)*cS)

rpkm[[1]] &lt;- p[[1]]

}

write.table(rpkm,&quot;output_table_rpkm.txt&quot;,sep=&quot;\t&quot;,quote=F,row.names=F)​</code>]]></description>
	<dc:creator>EagleEye</dc:creator>
</item>
<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27956/perl-script-to-extract-fasta-sequence-by-matching-nameids</guid>
	<pubDate>Tue, 21 Jun 2016 09:28:19 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27956/perl-script-to-extract-fasta-sequence-by-matching-nameids</link>
	<title><![CDATA[Perl script to extract fasta sequence by matching name/ids !!]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl

use strict;
use warnings;
use Text::Trim qw(trim);

#Usage perl extractSeqbyID.pl ids.txt seq.fasta Result.fasta

$ARGV[2] or die &quot;use extractSeqbyID.pl LIST FASTA OUT\n&quot;;

my $list = shift @ARGV;
my $fasta = shift @ARGV;
my $out = shift @ARGV;
my %select;

open LINE, &quot;$list&quot; or die;
while (&lt;LINE&gt;) {
    chomp;
    next if /^\s*$/;
    s/&gt;//g; 
    my @ids=split (/\t/, $_);
    $select{$ids[0]} = 1;
}
my $size = keys %select;
print &quot;Total Ids $size\n&quot;;
close LINE;

$/ = &quot;\n&gt;&quot;;
open OUT, &quot;&gt;$out&quot; or die;
open FILE, &quot;$fasta&quot; or die;
while (&lt;FILE&gt;) {
    trim($_);
    s/&gt;//g;
    my ($id) = split (/\n/, $_);
    #my @i=split (/\s/, $id); # To avoid &gt;flattened_line_10751 circular cases
    print OUT &quot;&gt;$_&quot; if (defined $select{$id});
}
close FILE;
close OUT;</code>]]></description>
	<dc:creator>Surabhi Chaudhary</dc:creator>
</item>
<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27955/perl-script-to-extract-lines-with-matching-ids</guid>
	<pubDate>Tue, 21 Jun 2016 09:24:46 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27955/perl-script-to-extract-lines-with-matching-ids</link>
	<title><![CDATA[Perl script to extract lines with matching ids !!]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl
use strict;
use warnings;
my %patterns;

#USAGE: perl extactByIds.pl Idsfile1 file2 &gt; Result

# Open file and get patterns to search for
open(my $fh2,&quot;&lt;&quot;,&quot;$ARGV[0]&quot;)|| die &quot;ERROR: Could not open file2&quot;;
while (&lt;$fh2&gt;)
{
   chop;
   $patterns{$_}=1;
}

# Now read data file
open(my $fh1,&quot;&lt;&quot;,&quot;$ARGV[1]&quot;)|| die &quot;ERROR: Could not open file1&quot;;
while (&lt;$fh1&gt;)
{
   # You might need to adjust this place according to your file type
   #(undef,$srch,undef)=split;
   my @ids=split (/\t/, $_);
   print $_ if defined $patterns{$ids[0]};
}</code>]]></description>
	<dc:creator>Surabhi Chaudhary</dc:creator>
</item>
<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27919/perl-script-to-find-the-absolute-full-path-of-the-file</guid>
	<pubDate>Fri, 17 Jun 2016 08:58:08 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27919/perl-script-to-find-the-absolute-full-path-of-the-file</link>
	<title><![CDATA[Perl script to find the absolute "full" path of the file !]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl

use Cwd;
my $this_file_full_path = Cwd::abs_path(__FILE__);
print &quot;$this_file_full_path\n&quot;;


use Cwd qw/ realpath /;
## $0; this script 
my $path = realpath($0);
print $path;</code>]]></description>
	<dc:creator>Jit</dc:creator>
</item>
<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27802/perl-script-to-generate-a-random-psuedo-dna-sequence</guid>
	<pubDate>Mon, 13 Jun 2016 08:49:13 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27802/perl-script-to-generate-a-random-psuedo-dna-sequence</link>
	<title><![CDATA[Perl script to generate a random psuedo DNA sequence !]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl

print &quot;Enter a number of nucleotides: \n&quot;;
chomp ($N = &lt;STDIN&gt;);
@b=qw/A T G C/;print &quot;&gt;Genome\n&quot;;while($l&lt;$N){print @b[int(rand(4))];$l++;};
print &quot;\n&quot;</code>]]></description>
	<dc:creator>Abhi</dc:creator>
</item>
<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27541/implementation-of-biological-random-mutation-with-perl</guid>
	<pubDate>Thu, 26 May 2016 02:38:01 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27541/implementation-of-biological-random-mutation-with-perl</link>
	<title><![CDATA[Implementation of biological random mutation with Perl]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl -w

use strict;  
use warnings;  

#sequence for a better recognition  
my $DNA=&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA \ n&quot;;  
my $I;  
my $mutant;  
srand (time | $$).  
$mutant=mutate ($DNA);  
print &quot;Mutate \ n&quot;. $DNA;  
print &quot;Here is the the original DNA: \ n&quot;;  
print &quot;$DNA \ n&quot;;  
print &quot;Here is the mutant DNA: \ n \ n&quot;;  
print &quot;$mutant \ n&quot;;  
print &quot;motorcycle 10 more successive mutations: \ n&quot;;  
for ($I=0; $i&lt;10; $I + +)  { 
    $mutant=mutate ($mutant);  
    Print &quot;$mutant \ n&quot;;  
}  

#subroutine: according to the length of the sequence is defined a random location of subroutine  
sub randomposition { 
    my ($string)=@ _;  
    return int (rand (length ($string)));  

} #subroutine: randomly selected from an element from an array  
sub randelement { 
  my (@array)=@ _;  
  return $array [rand @ array];  
}  

#subroutine: refer to the above subroutine, randomly selected from four bases ATGC a  
sub randomnucleotide { 
  my (@nucleotides)=&#039;ve/A, C/T G&#039;.  
  return randelement (@nucleotides);  
}  

#subroutine: generate mutations subroutine  
sub mutate { 
    my DNA ($)=@ _;  
    my (@nucleotides)=&#039;ve (A C T G)&#039;;  
    my ($position)=randomposition DNA ($);  
    my ($newbase)=randomnucleotide (@nucleotides);  
    DNA, substr ($$position, 1, $newbase); #substr ($string, $initial_position, $length, replacement substring)  
    return $DNA;  

}</code>]]></description>
	<dc:creator>Priya Singh</dc:creator>
</item>
<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27467/count-gc-content-in-nucleotide-sequence-with-perl</guid>
	<pubDate>Sat, 21 May 2016 22:56:18 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27467/count-gc-content-in-nucleotide-sequence-with-perl</link>
	<title><![CDATA[Count GC Content in nucleotide sequence with Perl]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl -w

### Usage: get_gc_content.pl &lt;fasta file&gt;                                                        ###

#---------------------------------------------------------------------------------------------------------------------------
#Deal with passed parameters
#---------------------------------------------------------------------------------------------------------------------------
if ($#ARGV == -1) {
    usage();
    exit;
}
$fasta_file = $ARGV[0];
$out_file = &quot;gc_out.txt&quot;;
unless ( open(IN, &quot;$fasta_file&quot;) ) {    
    print &quot;Got a bad fasta file: $fasta_file\n\n&quot;;
    exit;
}
unless ( open(OUT, &quot;&gt;$out_file&quot;) ) {
    print &quot;Couldn&#039;t create $out_file\n&quot;;
    exit;
}
print &quot;Parameters:\nfasta file = $fasta_file\noutput file = $out_file\n\n&quot;;
#---------------------------------------------------------------------------------------------------------------------------
#The main event
#---------------------------------------------------------------------------------------------------------------------------
print OUT &quot;ID\t% GCContent\tTotal Count\tG Count\tC Count\tA Count\tT Count\n&quot;;
$seq = &quot;&quot;;
while (&lt;IN&gt;) {
    chomp;
    if (/^&gt;/) {
	#finish up previous line.
	if (length($seq) &gt; 0) {
	    &amp;process_it;
	}
	#start new line.
	$id = $_;
	$id =~ s/^&gt;(.+?)\s.+$/$1/g;
	print OUT &quot;$id\t&quot;;
    }
    else {
	$seq = $seq . $_;
    }
}

#finish up last line.
&amp;process_it;

close(IN);
close(OUT);

sub usage {
   $0 get_gc_content.pl &lt;fasta file&gt;    
}

sub process_it {
    @letters = split(//, $seq);
    $gccount = 0;
    $totalcount = 0;
    $acount = 0;
    $tcount = 0;
    $gcount = 0;
    $ccount = 0;
    foreach $i (@letters) {
	if (lc($i) =~ /[a-z]/) {
	    $totalcount++;
	}
	if (lc($i) eq &quot;g&quot; || lc($i) eq &quot;c&quot;) {
	    $gccount++;
	}
	if (lc($i) eq &quot;a&quot;) {
	    $acount++;
	}
	if (lc($i) eq &quot;t&quot;) {
	    $tcount++;
	}
	if (lc($i) eq &quot;g&quot;) {
	    $gcount++;
	}
	if (lc($i) eq &quot;c&quot;) {
	    $ccount++;
	}
    }
    if ($totalcount &gt; 0) {
	$gccontent = (100 * $gccount) / $totalcount;
    }
    else {
	$gccontent = 0;
    }
    print OUT &quot;$gccontent\t$totalcount\t$gcount\t$ccount\t$acount\t$tcount\n&quot;;
    $seq = &quot;&quot;;
}</code>]]></description>
	<dc:creator>Radha Agarkar</dc:creator>
</item>
<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27454/needleman-wunsch-algorithm-in-perl</guid>
	<pubDate>Sat, 21 May 2016 22:07:06 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27454/needleman-wunsch-algorithm-in-perl</link>
	<title><![CDATA[Needleman-Wunsch  Algorithm in Perl]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl

# USAGE:   perl nw.pl HEAGAWGHEE PAWHEAE BLOSUM50.txt -8

# See:     &quot;Biological sequence anaysis&quot; Durbin et al. ed. CUP 1998, Pg. 19
# Needleman-Wunsch global alignment algo (GOTHO 1982 mod)

# usage statement
die &quot;usage: $0 &lt;sequence 1&gt; &lt;sequence 2&gt; &lt;substmatrix&gt; &lt;gapscore&gt; \n&quot; unless @ARGV == 4;

# get sequences, matrix and gapcost from command line
my ($seq1, $seq2, $smfile, $gapcost) = @ARGV;

# scoring scheme (instead of using fixed MATCH and MISMATCH scores we will use values read from BLOSUM50)
my $MATCH    =  1; # +1 for letters that match
my $MISMATCH = -1; # -1 for letters that mismatch
my $GAP      = $gapcost; # for any gap
my %BLOSUM50 = ();
my @aalist = ();

# read substitution matrix
open in, $smfile;
while(&lt;in&gt;){
    if($.&lt;2){next;}
    # read columns names (aa)
    if($.&lt;3){
        chop $_;
        @aalist=split(/\s+/,$_);
        next;
        }
    chop $_;
    @vals=split(/\s+/,$_);
    $curaaROW=$vals[0];
    for($i=1;$i&lt;=$#vals;$i++){
        $curaaCOLUMN=$aalist[$i];
        $BLOSUM50{$curaaROW}{$curaaCOLUMN}=$vals[$i];
    }   
}
close in;


# initialization
my @matrix;
$matrix[0][0]{score}   = 0;
$matrix[0][0]{pointer} = &quot;none&quot;;
for(my $j = 1; $j &lt;= length($seq1); $j++) {
    $matrix[0][$j]{score}   = $GAP * $j;
    $matrix[0][$j]{pointer} = &quot;left&quot;;
}
for (my $i = 1; $i &lt;= length($seq2); $i++) {
    $matrix[$i][0]{score}   = $GAP * $i;
    $matrix[$i][0]{pointer} = &quot;up&quot;;
}

# fill
for(my $i = 1; $i &lt;= length($seq2); $i++) {
    for(my $j = 1; $j &lt;= length($seq1); $j++) {
        my ($diagonal_score, $left_score, $up_score);

        # calculate match score
        my $letter1 = substr($seq1, $j-1, 1);
        my $letter2 = substr($seq2, $i-1, 1);                            
        if ($letter1 eq $letter2) {
            $diagonal_score = $matrix[$i-1][$j-1]{score} + $BLOSUM50{$letter1}{$letter2};
        }
        else {
            $diagonal_score = $matrix[$i-1][$j-1]{score} + $BLOSUM50{$letter1}{$letter2};
        }

        # calculate gap scores
        $up_score   = $matrix[$i-1][$j]{score} + $GAP;
        $left_score = $matrix[$i][$j-1]{score} + $GAP;

        # choose best score
        if ($diagonal_score &gt;= $up_score) {
            if ($diagonal_score &gt;= $left_score) {
                $matrix[$i][$j]{score}   = $diagonal_score;
                $matrix[$i][$j]{pointer} = &quot;diagonal&quot;;
            }
        else {
                $matrix[$i][$j]{score}   = $left_score;
                $matrix[$i][$j]{pointer} = &quot;left&quot;;
            }
        } else {
            if ($up_score &gt;= $left_score) {
                $matrix[$i][$j]{score}   = $up_score;
                $matrix[$i][$j]{pointer} = &quot;up&quot;;
            }
            else {
                $matrix[$i][$j]{score}   = $left_score;
                $matrix[$i][$j]{pointer} = &quot;left&quot;;
            }
        }
    }
}

# trace-back

my $align1 = &quot;&quot;;
my $align2 = &quot;&quot;;
my $descrstr = &quot;&quot;;

# start at last cell of matrix
my $j = length($seq1);
my $i = length($seq2);

while (1) {
    last if $matrix[$i][$j]{pointer} eq &quot;none&quot;; # ends at first cell of matrix

    if ($matrix[$i][$j]{pointer} eq &quot;diagonal&quot;) {
        $align1 .= substr($seq1, $j-1, 1);
        $align2 .= substr($seq2, $i-1, 1);
        if(substr($seq1, $j-1,1) eq substr($seq2, $i-1,1)){$descrstr .=&quot;|&quot;;}else{$descrstr .= &quot;.&quot;;}
        $i--;
        $j--;
    }
    elsif ($matrix[$i][$j]{pointer} eq &quot;left&quot;) {
        $align1 .= substr($seq1, $j-1, 1);
        $align2 .= &quot;-&quot;;
        $descrstr .= &quot; &quot;;
        $j--;
    }
    elsif ($matrix[$i][$j]{pointer} eq &quot;up&quot;) {
        $align1 .= &quot;-&quot;;
        $align2 .= substr($seq2, $i-1, 1);
        $descrstr .= &quot; &quot;;
        $i--;
    }    
}

$align1 = reverse $align1;
$align2 = reverse $align2;
$descrstr = reverse $descrstr;

# print matrices:
print &quot;\n\n&quot;;

for(my $i = 0; $i &lt;= length($seq2); $i++) {
    for(my $j = 0; $j &lt;= length($seq1); $j++) {
        printf(&quot;%2.1f&quot;, $matrix[$i][$j]{score});
        print(&quot;\t&quot;);
    }
    print&quot;\n&quot;;
}
print &quot;\n\n&quot;;

# print the alignment:
print &quot;$align1\n&quot;;
print &quot;$descrstr\n&quot;;
print &quot;$align2\n&quot;;

__END__
# Entries for the BLOSUM50 matrix at a scale of ln(2)/3.0.
Find matrix at http://bioinformaticsonline.com/file/view/27455/blosum50-matrix</code>]]></description>
	<dc:creator>Radha Agarkar</dc:creator>
</item>
<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27422/generating-a-random-string-with-perl</guid>
	<pubDate>Fri, 20 May 2016 05:13:20 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27422/generating-a-random-string-with-perl</link>
	<title><![CDATA[Generating a random string with Perl]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl

# This function generates random strings of a given length
sub generate_random_string
{
	my $length_of_randomstring=shift;# the length of 
			 # the random string to generate

	my @chars=(&#039;a&#039;..&#039;z&#039;,&#039;A&#039;..&#039;Z&#039;,&#039;0&#039;..&#039;9&#039;,&#039;_&#039;);
	my $random_string;
	foreach (1..$length_of_randomstring) 
	{
		# rand @chars will generate a random 
		# number between 0 and scalar @chars
		$random_string.=$chars[rand @chars];
	}
	return $random_string;
}

#Generate the random string
my $random_string=&amp;generate_random_string(11);

print &quot;Random string: &quot;.$random_string.&quot;\n&quot;;
print &quot;Length: &quot;.length($random_string).&quot;\n&quot;;</code>]]></description>
	<dc:creator>Abhi</dc:creator>
</item>
<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27403/find-the-number-of-each-2-consecutive-characters-aa-acagatccca-with-perl</guid>
	<pubDate>Wed, 18 May 2016 08:50:04 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27403/find-the-number-of-each-2-consecutive-characters-aa-acagatccca-with-perl</link>
	<title><![CDATA[Find the number of each 2 consecutive characters AA, AC,AG,AT,CC,CA... with Perl]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl -w

use strict;

my $subject = &quot;AACGTACTGACGTACTGGTTGGTACGA&quot;;
my %results = ();
while ($subject =~ m/[ACTG][ATGC]/g) {
    # matched text = $&amp;
        if(exists $results{$&amp;})
        {
            $results{$&amp;}++ 
        }
        else
        {
            $results{$&amp;} = 1;
        }
}

foreach (sort keys %results) {
    print &quot;$_ : $results{$_}\n&quot;;
  }</code>]]></description>
	<dc:creator>Jit</dc:creator>
</item>

</channel>
</rss>