<?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: Calculate ATGC percentage in parallel with perl]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/30676/calculate-atgc-percentage-in-parallel-with-perl?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/30676/calculate-atgc-percentage-in-parallel-with-perl?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/30676/calculate-atgc-percentage-in-parallel-with-perl</guid>
	<pubDate>Thu, 26 Jan 2017 10:18:53 -0600</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/30676/calculate-atgc-percentage-in-parallel-with-perl</link>
	<title><![CDATA[Calculate ATGC percentage in parallel with perl]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl

use strict;
use Parallel::ForkManager;
use Bio::SeqIO;

#usage: perl testParallel.pl &lt;multi fasta infile&gt;

my %sequences;
my $seqio = Bio::SeqIO-&gt;new(-file =&gt; &quot;$ARGV[0]&quot;, -format =&gt; &quot;fasta&quot;);
while(my$seqobj = $seqio-&gt;next_seq) {
    my $id  = $seqobj-&gt;display_id;    # there&#039;s your key
    my $seq = $seqobj-&gt;seq;           # and there&#039;s your value
    $sequences{$id} = $seq;
}

  my $max_procs = 5;
  my @names = keys %sequences;

  # hash to resolve PID&#039;s back to child specific information
  my $pm =  new Parallel::ForkManager($max_procs);

 # Setup a callback for when a child finishes up so we can
  # get it&#039;s exit code
  $pm-&gt;run_on_finish (
    sub { my ($pid, $exit_code, $ident) = @_;
      #print &quot;** $ident just got out of the pool &quot;.
        &quot;with PID $pid and exit code: $exit_code\n&quot;;
    }
  );

  $pm-&gt;run_on_start(
    sub { my ($pid,$ident)=@_;
     #print &quot;** $ident started, pid: $pid\n&quot;;
    }
  );

  $pm-&gt;run_on_wait(
    sub {
      #print &quot;** Have to wait for one children ...\n&quot;
    },
    0.5
  );

  NAMES:
  foreach my $child ( 0 .. $#names ) {
    my $pid = $pm-&gt;start($names[$child]) and next NAMES;
    checkATCG($names[$child]);
    $pm-&gt;finish($child); # pass an exit code to finish
  }

  print &quot;Waiting for Children...\n&quot;;
  $pm-&gt;wait_all_children;
  print &quot;Everybody is out of the pool!\n&quot;;


sub checkATCG {
my $name=shift;
my $DNA=$sequences{$name};
my $length=length $DNA;
my $a=($DNA=~tr/A//);
my $b=($DNA=~tr/C//);
my $c=($DNA=~tr/G//);
my $d=($DNA=~tr/T//);
my $Total=$a+$b+$c+$d;
my $GC=($DNA=~s/GC/GC/g);
my $AT=($DNA=~s/AT/AT/g);
my $GCper=($GC/($Total)*100);
print&quot;$name\t$Total\t$AT\t$GC\t$GCper:\n&quot;;

}</code>]]></description>
	<dc:creator>Jit</dc:creator>
</item>

</channel>
</rss>