perlquestion
Anonymous Monk
<p>I have a short script which splits a DNA-sequence (imported by BioPerl) by a user-provided pattern and subsequently populates a hash with modified versions of the resulting fragments along with a unique ID. Each fragment produced by split appears in the hash twice - in the original form and in a reverse complement form (F and R respectively).</p>
<code>
#!/usr/bin/perl
use strict;
use warnings;
use Bio::SeqIO;
my %sequences;
my $seqio = Bio::SeqIO->new(-file => $ARGV[0]);
my $enz = $ARGV[1];
while(my $seqobj = $seqio->next_seq) {
my $id = $seqobj->display_id;
my $seq = $seqobj->seq;
$sequences{$id} = $seq;
}
my @fragments;
for my $value (values %sequences) {
@fragments = split(/$enz/, $value);
}
my $Lfill = "TT";
my $Rfill = "AA";
my $ID = 0;
my %bins;
foreach my $RF (@fragments) {
$ID++;
$RF = $Lfill.$RF.$Rfill;
$bins{$ID."F"} = $RF;
(my $rev = $RF) =~ tr/ACGT/TGCA/;
$bins{$ID."R"} = reverse($rev);
}
</code>
<p>Example Input:</p>
<code>>example
AAGTAGCATCGATTTATAGCATCGACTAGTAAGCTTAGCTACGATCAGCTACGATCGAGCGACTACGTAGC</code>
<p>Fragments Generated:</p>
<code>1F => TTAAGTAGCATCGATTTATAGCATCGACTAGTAA
1R => TTACTAGTCGATGCTATAAATCGATGCTACTTAA
2F => TTAGCTACGATCAGCTACGATCGAGCGACTACGTAGCAA
2R => TTGCTACGTAGTCGCTCGATCGTAGCTGATCGTAGCTAA</code>
<p>I now want to obtain unique combinations (of two) whilst excluding a fragment from combining with its own reverse cognate. Using the example above, it would produce:</p>
<code>1F2F => TTAAGTAGCATCGATTTATAGCATCGACTAGTAATTAGCTACGATCAGCTACGATCGAGCGACTACGTAGCAA
1F2R => TTAAGTAGCATCGATTTATAGCATCGACTAGTAATTGCTACGTAGTCGCTCGATCGTAGCTGATCGTAGCTAA
1R2F => TTACTAGTCGATGCTATAAATCGATGCTACTTAATTAGCTACGATCAGCTACGATCGAGCGACTACGTAGCAA
1R2R => TTACTAGTCGATGCTATAAATCGATGCTACTTAATTGCTACGTAGTCGCTCGATCGTAGCTGATCGTAGCTAA</code>
<p>But would not produce 1F1R or 2F2R. As shown above, both the keys of the involved fragments are combined as well as the values - and stored in a new hash.</p>
<p>I've tried using the CPAN modules Algorithm::Combinatorics and Math::Combinatorics but can't seem to adapt these to fit this task.</p>
<p>Does anybody have any code snippets, examples or suggestions that could help achieve this? If it helps: i'm very new to Perl.</p>
7