Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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).
#!/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); }
Example Input:
>example AAGTAGCATCGATTTATAGCATCGACTAGTAAGCTTAGCTACGATCAGCTACGATCGAGCGACTACGTAG +C
Fragments Generated:
1F => TTAAGTAGCATCGATTTATAGCATCGACTAGTAA 1R => TTACTAGTCGATGCTATAAATCGATGCTACTTAA 2F => TTAGCTACGATCAGCTACGATCGAGCGACTACGTAGCAA 2R => TTGCTACGTAGTCGCTCGATCGTAGCTGATCGTAGCTAA
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:
1F2F => TTAAGTAGCATCGATTTATAGCATCGACTAGTAATTAGCTACGATCAGCTACGATCGAGCGA +CTACGTAGCAA 1F2R => TTAAGTAGCATCGATTTATAGCATCGACTAGTAATTGCTACGTAGTCGCTCGATCGTAGCT +GATCGTAGCTAA 1R2F => TTACTAGTCGATGCTATAAATCGATGCTACTTAATTAGCTACGATCAGCTACGATCGAGCGA +CTACGTAGCAA 1R2R => TTACTAGTCGATGCTATAAATCGATGCTACTTAATTGCTACGTAGTCGCTCGATCGTAGCTG +ATCGTAGCTAA
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.
I've tried using the CPAN modules Algorithm::Combinatorics and Math::Combinatorics but can't seem to adapt these to fit this task.
Does anybody have any code snippets, examples or suggestions that could help achieve this? If it helps: i'm very new to Perl.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Obtaining combinations of hash keys and values
by choroba (Cardinal) on Apr 28, 2016 at 16:39 UTC | |
by Anonymous Monk on Apr 29, 2016 at 09:01 UTC | |
by Cristoforo (Curate) on Apr 29, 2016 at 18:40 UTC | |
by Anonymous Monk on Apr 29, 2016 at 09:13 UTC | |
by choroba (Cardinal) on Apr 29, 2016 at 09:26 UTC | |
|
Re: Obtaining combinations of hash keys and values
by Anonymous Monk on Apr 28, 2016 at 17:38 UTC | |
by Anonymous Monk on Apr 29, 2016 at 09:02 UTC |