Commit 06d5594f authored by Sebastien Carrere's avatar Sebastien Carrere

Normes de code et simplification (boucles repetees)

parent 0bbb8d79
=head2 function CreatePanProteome
Title : CreatePanProteome
......@@ -18,16 +19,18 @@ sub CreatePanProteome
my $rh_specific = {};
my $refexist;
my @references;
my @SeqS1,@AllSeqS1;
my @a_references = ();
my @a_seqs1 = ();
my @a_allseqs1 = ();
my %ListGroupSelectSeqidCode;
my %h_list_group_select_seqid_code = ();
foreach my $code (keys %{$rh_analysis_params->{'proteomes'}})
{
if ($rh_analysis_params->{'proteomes'}->{$code}->{'reference'} eq 'true')
{
push @references, $code;
&Log("INFO - $code is a reference proteome");
push(@a_references, $code);
}
}
......@@ -39,53 +42,48 @@ sub CreatePanProteome
foreach my $groupid (keys %{$rh_orthomcl})
{
&__DeleteSequencesFromGroupId($rh_orthomcl, $rh_specific, $groupid);
}
foreach my $group (keys %{$rh_orthomcl})
{
$refexist = 0;
@AllSeqS1 = ();
foreach my $code (@references)
$refexist = 0;
@a_allseqs1 = ();
foreach my $code (@a_references)
{
if(exists($rh_orthomcl->{$group}->{$code}))
if (exists($rh_orthomcl->{$groupid}->{$code}))
{
$refexist = 1;
foreach my $seqid (@{$rh_orthomcl->{$group}->{$code}})
foreach my $seqid (@{$rh_orthomcl->{$groupid}->{$code}})
{
@SeqS1 = ();
push @SeqS1, $code, $seqid;
push @AllSeqS1,[ @SeqS1 ];
@a_seqs1 = ();
push(@a_seqs1, $code, $seqid);
push(@a_allseqs1, [@a_seqs1]);
}
}
}
if ($refexist == 0)
{
foreach my $code (keys %{$rh_orthomcl->{$group}})
foreach my $code (keys %{$rh_orthomcl->{$groupid}})
{
foreach my $seqid (@{$rh_orthomcl->{$group}->{$code}})
foreach my $seqid (@{$rh_orthomcl->{$groupid}->{$code}})
{
@SeqS1 = ();
push @SeqS1, $code, $seqid;
push @AllSeqS1, [ @SeqS1 ];
}
@a_seqs1 = ();
push(@a_seqs1, $code, $seqid);
push(@a_allseqs1, [@a_seqs1]);
}
}
}
$ListGroupSelectSeqidCode{$group} = &SelectSequenceRepGroupe($rh_species,\@AllSeqS1);
$h_list_group_select_seqid_code{$groupid} = &SelectSequenceRepGroupe($rh_species, \@a_allseqs1);
}
&PrintPanProteome($outdir,$rh_specific,\%ListGroupSelectSeqidCode,$rh_species);
&PrintPanProteome($outdir, $rh_specific, \%h_list_group_select_seqid_code, $rh_species);
return;
}
=head3 function SelectSequenceRepGroupe
Title : SelectSequenceRepGroupe
Usage : @selec = &SelectSequenceRepGroupe($rh_species,\@AllSeqS1);
Usage : @selec = &SelectSequenceRepGroupe($rh_species,\@a_allseqs1);
Prerequisite : none
Function : Select representative sequence
Returns : array of [code,seqid]
......@@ -98,33 +96,39 @@ sub SelectSequenceRepGroupe
{
my ($rh_species, $SeqForSelect) = @_;
my $selecSeqid = "";
my$selecCode = "";
my $selecCode = "";
foreach my $toselect (@{$SeqForSelect})
{
if ($selecSeqid eq "")
{
$selecSeqid = $toselect->[1];
$selecCode = $toselect->[0];
$selecCode = $toselect->[0];
}
else
{
my $nb_X_selec = ($rh_species->{$selecCode}->{'sequences'}->{$selecSeqid}->{'sequence'} =~ tr/X/X/);
my $nb_X_toselec = ($rh_species->{$toselect->[0]}->{'sequences'}->{$toselect->[1]}->{'sequence'} =~ tr/X/X/);
if ((length($rh_species->{$toselect->[0]}->{'sequences'}->{$toselect->[1]}->{'sequence'}) - $nb_X_toselec * 3) > (length($rh_species->{$selecCode}->{'sequences'}->{$selecSeqid}->{'sequence'}) - $nb_X_selec * 3))
my $nb_X_toselec =
($rh_species->{$toselect->[0]}->{'sequences'}->{$toselect->[1]}->{'sequence'} =~ tr/X/X/);
if (
(
length($rh_species->{$toselect->[0]}->{'sequences'}->{$toselect->[1]}->{'sequence'}) -
$nb_X_toselec * 3
) > (length($rh_species->{$selecCode}->{'sequences'}->{$selecSeqid}->{'sequence'}) - $nb_X_selec * 3)
)
{
$selecSeqid = $toselect->[1];
$selecCode = $toselect->[0];
$selecCode = $toselect->[0];
}
}
}
return [$selecSeqid,$selecCode];
return [$selecSeqid, $selecCode];
}
=head3 function PrintPanProteome
Title : PrintPanProteome
Usage : &PrintPanProteome($outdir,$rh_specific,\%ListGroupSelectSeqidCode,$rh_species)
Usage : &PrintPanProteome($outdir,$rh_specific,\%h_list_group_select_seqid_code,$rh_species)
Prerequisite : none
Function : Print pan-proteome
Returns : none
......@@ -135,29 +139,34 @@ sub SelectSequenceRepGroupe
sub PrintPanProteome
{
my ($outdir,$rh_specific,$rh_ListGroupSelectSeqidCode,$rh_species) = @_;
my $subdirectory = "pan_proteome";
my $subdirectory_description = "directory with fasta multi-sequence of pan-proteome";
my ($outdir, $rh_specific, $rh_h_list_group_select_seqid_code, $rh_species) = @_;
my $subdirectory = "pan_proteome";
my $subdirectory_description = "Directory with fasta multi-sequence of pan-proteome";
mkdir "$outdir/$subdirectory";
push (@A_OUTPUT_DATA, {'directory' => $subdirectory, 'description' => $subdirectory_description});
my $fh_PanProteome = &GetStreamOut("$outdir/$subdirectory/PanProteome.fasta");
push(@A_OUTPUT_DATA, {'directory' => $subdirectory, 'description' => $subdirectory_description});
my $fh_panproteome = &GetStreamOut("$outdir/$subdirectory/PanProteome.fasta");
foreach my $group (sort keys %{$rh_ListGroupSelectSeqidCode})
foreach my $group (sort keys %{$rh_h_list_group_select_seqid_code})
{
print $fh_PanProteome ">".$rh_ListGroupSelectSeqidCode->{$group}[0]."|".$rh_ListGroupSelectSeqidCode->{$group}[1]."|".$group."\n";
print $fh_PanProteome $rh_species->{$rh_ListGroupSelectSeqidCode->{$group}[1]}->{'sequences'}->{$rh_ListGroupSelectSeqidCode->{$group}[0]}->{'sequence'}."\n";
print $fh_panproteome ">"
. $rh_h_list_group_select_seqid_code->{$group}[0] . "|"
. $rh_h_list_group_select_seqid_code->{$group}[1] . "|"
. $group . "\n";
print $fh_panproteome $rh_species->{$rh_h_list_group_select_seqid_code->{$group}[1]}->{'sequences'}
->{$rh_h_list_group_select_seqid_code->{$group}[0]}->{'sequence'} . "\n";
}
foreach my $code (keys %{$rh_specific})
{
foreach my $seqid (keys %{$rh_specific->{$code}})
{
print $fh_PanProteome ">".$seqid."|".$code."|uniq\n";
print $fh_PanProteome $rh_species->{$code}->{'sequences'}->{$seqid}->{'sequence'}."\n";
print $fh_panproteome ">" . $seqid . "|" . $code . "|uniq\n";
print $fh_panproteome $rh_species->{$code}->{'sequences'}->{$seqid}->{'sequence'} . "\n";
}
}
$fh_panproteome->close;
return;
}
......
......@@ -14,7 +14,7 @@
sub ListGroupAndUniqueForAllProteomes
{
my ($rh_orthomcl, $rh_species, $outdir) = @_;
my %ListGroupByCode;
my %h_list_group_by_code;
my $rh_specific = {};
&Log("INFO - ListGroupAndUniqueForAllProteomes");
......@@ -22,37 +22,29 @@ sub ListGroupAndUniqueForAllProteomes
foreach my $code (keys %{$rh_species})
{
$rh_specific->{$code} = Storable::dclone($rh_species->{$code}->{'sequences'});
}
foreach my $code (keys %{$rh_species})
{
$ListGroupByCode{$code} = [];
}
foreach my $group (keys %{$rh_orthomcl})
{
foreach my $code (keys %{$rh_orthomcl->{$group}})
{
push @{$ListGroupByCode{$code}}, $group;
}
$h_list_group_by_code{$code} = [];
}
foreach my $groupid (keys %{$rh_orthomcl})
{
&__DeleteSequencesFromGroupId($rh_orthomcl, $rh_specific, $groupid);
foreach my $code (keys %{$rh_orthomcl->{$groupid}})
{
push (@{$h_list_group_by_code{$code}}, $groupid);
}
}
foreach my $code (keys %{$rh_specific})
{
my $nb = scalar(keys %{$rh_specific->{$code}});
&Log("INFO - $code contain $nb unique specific protein");
&Log("INFO - $code contains $nb unique specific protein");
foreach my $seqid (keys %{$rh_specific->{$code}})
{
push @{$ListGroupByCode{$code}}, $seqid;
push (@{$h_list_group_by_code{$code}}, $seqid);
}
}
&PrintListGroupProteome($outdir, \%ListGroupByCode);
&PrintListGroupProteome($outdir, \%h_list_group_by_code);
return;
}
......@@ -60,7 +52,7 @@ sub ListGroupAndUniqueForAllProteomes
=head3 function PrintListGroupProteome
Title : PrintListGroupProteome
Usage : &PrintListGroupProteome($outdir,\%ListGroupByCode)
Usage : &PrintListGroupProteome($outdir,\%h_list_group_by_code)
Prerequisite : none
Function : Print for each proteome, a list of all group with a protein of this proteome + unique protein
Returns : none
......@@ -74,7 +66,7 @@ sub PrintListGroupProteome
my ($outdir, $rh_listgroupbycode) = @_;
my $subdirectory = "list_group_unique_proteomes";
my $subdirectory_description =
'directory with for each proteome (one file / proteome), a list of all group with a protein of this proteome + unique protein';
'Directory with for each proteome (one file / proteome), a list of all group with a protein of this proteome + unique protein';
mkdir "$outdir/$subdirectory";
push (@A_OUTPUT_DATA, {'directory' => $subdirectory, 'description' => $subdirectory_description});
......@@ -85,7 +77,9 @@ sub PrintListGroupProteome
{
print $fh_liste "$group\n";
}
$fh_liste->close;
}
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment