-
Notifications
You must be signed in to change notification settings - Fork 0
/
FextractSeqFeaturesFromGbUsingBioPerl.pl
executable file
·1439 lines (1181 loc) · 65.5 KB
/
FextractSeqFeaturesFromGbUsingBioPerl.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
use strict;
# use lib '/Volumes/applications/Applications/bin/bioperl-1.5.2_102/';
use Env qw(SIGFFRID_DIR);
use Bio::SeqIO;
use Getopt::Long;
use Cwd;
# ************************************************************************************
# DECLARE STORING VARIABLES AND PARAMETERS
# ************************************************************************************
use warnings;
#use diagnostics;
# personal LIB ********************************************************************************
use lib $SIGFFRID_DIR.'libperl';
use SysUtilities; # qw(date tri_rapide)
use SeqUtilities; # qw(complement_seq print50 get_cosmid_seq);
# END LIB *************************************************************************************
# **********************************************************************
=head1 NAME
FextractSeqFeaturesFromGbUsingBioPerl.pl
=head1 DESCRIPTION
Extract sequences from gb or gbk files with various properties.
Mainly dedicated to dataset for SIGffRid analysis.
Caution, if output file already exists, overwrite it.
=head1 USAGE
=over
=item -gb_f <s>n
Genbank file for bacteria (must contain nucleotide sequence).
=item -id_bact <s>
ID of bacteria (this id is in the file provided by MBGD database
file of ortholog comparisons.
=item [-res_dir <s>]
Default:current directory.
=item [-test]
To run only test of seq extraction, do not take into account other arguments.
=back
examples:
Will run for example following command lines:
perl sigffrid_cmd_line.pl -gb_f \
../ref_genomes/NC_002516.2_Pseudomonas_aeruginosa_PAO1_chr_complete_genome.gb
-id_bact pae
-res_dir sigffrid_res/
=cut
# **********************************************************************
my $prog_tag = '[FextractSeqFeaturesFromGbUsingBioPerl]';
my $b_test = 0; # ok 2018 12 14
my @gb_f = ();
my $res_dir = undef;
# we get date with '/' characte to separate day, month and year
my $date = &date('/');
print "$prog_tag DATE: $date\n";
# booleens de choix ou non d'un type de traitement (dans l'ordre d'apparation dans le traitement)
my $debug_mode = 0;
my $ID_bact = undef;
# format GERE DANS LA FONCTION PRINT50
my $fasta = 0; # edition des sequences au format fasta 1 ou comme une seul sequence sur une ligne pour accelerer le traitement de certains programmes.
my $entete_fasta; # en tete de fichier pour preciser le format utilise pour generer le fichier
if($fasta){ $entete_fasta = 'fasta_' }
else { $entete_fasta = 'not_fasta_' }
my $edit_file_for_the_whole_one_block_seq0 = 1; # edition de la sequence complete d'une bacterie en sens 0: OK
my $edit_file_for_the_whole_one_block_seq1 = 0; # edition de la sequence complete d'une bacterie en sens 1: OK
my $edit_file_for_the_whole_one_block_seq_RMES = 1; # edition de la sequence complete d'une bacterie en sens 0, si plusieurs seq, separees par Z, une entete obligatoire
my $edit_file_for_each_CDS = 0; # edition de chaque CDS individuellement (meme en cas de chevauchement): OK
my $edit_file_for_all_CDS = 0; # edition de l'ensemble des CDS (fusions en cas de chevauchement): OK
my $edit_file_for_promoters = 1; # edition du promoteur de chaque gene (seq interg amont du CDS): OK
my $edit_file_for_all_interCDS = 0; # edition de l'ensemble des interCDS
my $edit_file_for_all_interCDS_between_conv = 0; # edition de l'ensemble des interCDS entre genes conv
my $edit_file_for_all_interCDS_between_div = 0; # edition de l'ensemble des interCDS entre genes div
my $edit_file_for_all_CDS_interCDS_between_conv = 0; # edition de l'ensemble des CDS+interCDS entre genes conv : prev OK + limit
my $edit_file_for_all_annotations = 0; # edition de toutes les annotations correspondant a chaque CDS OK
my $edit_file_for_upstream_seq = 1; # edition de la seq amont de chaque gene (seq amont du CDS), seq CDS et/ou interCDS : OK
my $edit_file_for_protein_seq = 0; # edition de toutes les sequences proteiques: OK
my $edit_file_for_300_0_seq = 1; # 1; # edition de toutes les sequences -300 0 en sens 0 puis en sens 1 (fusion pour celle se chevauchant dans le meme sens, sans chevauchement pour un sens considere: OK
my $edit_limits_of_overlapped_seq_sens01 = 1; # 1; # edition de toutes les limites des séquences amonts fusionnées: OK
my $edit_annotations_of_limits_overlapped = 1; # 1; # edition des annotations des genes dont les limites amonts sont fusionnées: OK
my $edit_limits_of_promoters = 0; # future work... edition des limites des sequences intergéniques amonts:OK
# limites utilisees pour l'extraction des sequences amont de CDS (qu'elles soient codantes ou non)
my $longueurmini = 30; # longueur minimale de la sequence extraite
my $dist_fin_up_seq_deb_trad = 0; # distance de la fin de la sequence amont au debut de la traduction
my $dist_deb_up_seq_deb_trad = 350; # distance a partir de laquelle on considere la sequence amont
my $length_upstream = $dist_deb_up_seq_deb_trad - $dist_fin_up_seq_deb_trad; # position du debut de la seq amont - position de fin
my $not_verbose = 1; # affichage des infos sur le deroulement du prog si = 0
my $bool_extended_alphabet = 1; # utilisation de l'alphabet etendu pour les seq qui ont d'autres lettres que acgt
my $bool_distinctfiles_sens0_1 = 0; # to delete files of upstream seq sens 0 and sens 1 after creatinf file sens01
# VAR for write in output files ***************************************
my @tmp_file_name = (); # store output files names
my $last_ind_1sens_file = -1;
my $end_file = '';
my $chemin_dest = undef;
# **********************************************************************
# CHECK OPTIONS
# **********************************************************************
my $nbargmini = 1;
if(scalar(@ARGV) < $nbargmini){
print "$prog_tag Bad number of arguments: ".scalar(@ARGV)." found, at least $nbargmini wanted\n";
foreach(0..$#ARGV){
print "$prog_tag $_: $ARGV[$_]\n";
}
die `perldoc $0`;
}
GetOptions(
"gb_f=s{1,}" => \@gb_f,
"id_bact=s" => \$ID_bact,
"res_dir=s" => \$chemin_dest,
"test" => sub { $b_test = 1 }
);
# **********************************************************************
if($b_test)
{
$ID_bact = 'H37Rv';
my $test_dir = $SIGFFRID_DIR.'test_SIGffRid/test_FextractSeqFeaturesFromGbUsingBioPerl/';
@gb_f = ($test_dir.'AL123456.3_Mycobacterium_tuberculosis_H37Rv_complete_genome_full.gb');
$res_dir = $test_dir.'res/';
my $cmd = join(' ', $SIGFFRID_DIR.'FextractSeqFeaturesFromGbUsingBioPerl.pl',
'-gb_f', @gb_f,
'-id_bact', $ID_bact,
'-res_dir', $res_dir
);
print "$prog_tag [TEST] cmd:$cmd, line ".__LINE__."\n";
`$cmd`;
print "$prog_tag [TEST] end\n";
exit;
}
# if($#ARGV < 1){ &sortir;}
if( defined $chemin_dest )
{
if($chemin_dest !~ /\/$/)
{ $chemin_dest .= '/'; }
-e $chemin_dest or die "$prog_tag [Error] $chemin_dest does not exist, line ".__LINE__."\n";
-d $chemin_dest or die "$prog_tag [Error] $chemin_dest is not a directory, line ".__LINE__."\n";
}
else
{
$chemin_dest = Cwd::cwd();
$chemin_dest .= '/';
}
foreach(@gb_f){
my $b_sortir = 0;
if(!-e $_){
die "$prog_tag [Error] $_ file does not exist, line ".__LINE__."\n";
}
if($_ !~ /\.gbk?$/){
die "$prog_tag [Error] $_ does not have GenBank file extension (.gb or .gbk), line ".__LINE__."\n";
}
}
# sub sortir{
# print "Usage:$0 <ID bacteria> <GenBank file(s) (file.gbk or file.gb)> [destination directory]\n";
# exit;
# }
print "$prog_tag chemin_dest : $chemin_dest\n";
# my $ID_bact = $ARGV[0] ;
my %H_ind_T = (
'gene'=> 0,
'prot'=>1,
'imp'=>2
);
my $bool_premier_passage = 1;
my $cpt_seq = 0;
my $separateur = '_';
my $verbose = 0; # to display or not debug informations
my @gene = (); # store genes names (coding prot OR rna)
my @comment = (); # store comments for genes (prot and rna), imp, cdregion...
my @seqdesc_title = ();
my @sens = (); # store strand (plus = 0, minus = 1, both = 2, unknown = 3) for genes or rna [0], prot [1], imp [2]
my @prot = (); # store prot seq
my @prot_name = (); # store prot name
my @Nr_acc_prot = (); # store prot IDs (NP_, ZP_...)
my @type = (); # store type (prot, tRNA...)
my @beg = (); # store beginning (limit) of CDS [0], prot [1], imp [2], ... (do not take into account sens of gene)
my @end = (); # store end (limit) of CDS (do not take into account sens of gene)
# foreach(keys %H_ind_T){
# @{ $beg[ $H_ind_T{$_} ] } = ();
# @{ $end[ $H_ind_T{$_} ] } = ();
# @{ $sens[ $H_ind_T{$_} ] } = ();
# }
# ************************************************************************************
# END DECLARE STORING VARIABLES AND PARAMETERS
# ************************************************************************************
# ************************************************************************************
# EXTRACTION
# ************************************************************************************
# &GetOptions("r"=>\$reverse);
for my $gbkfile(@gb_f) {
@gene = (); # store genes names (coding prot OR rna)
@comment = (); # store comments for genes (prot and rna), imp, cdregion...
@seqdesc_title = ();
@sens = (); # store strand (plus = 0, minus = 1, both = 2, unknown = 3) for genes or rna [0], prot [1], imp [2]
@prot = (); # store prot seq
@prot_name = (); # store prot name
@Nr_acc_prot = (); # store prot IDs (NP_, ZP_...)
@type = (); # store type (prot, tRNA...)
@beg = (); # store beginning (limit) of CDS [0], prot [1], imp [2], ... (do not take into account sens of gene)
@end = (); # store end (limit) of CDS (do not take into account sens of gene)
my $sequence = &get_cosmid_seq($gbkfile,$bool_extended_alphabet);
my $length_sequence = length($sequence);
print "$prog_tag length_sequence : $length_sequence\n";
my $k = 0;
my $length = 0;
print "$prog_tag Treatment of $gbkfile file\n";
my $seqIO_obj=Bio::SeqIO->new(-format=>'GenBank', -file=>"$gbkfile");
my $pb_in_genes=0;
while(my $seq_obj=$seqIO_obj->next_seq()){
$length=$seq_obj->length();
my @features=$seq_obj->all_SeqFeatures();
foreach my $feature (@features){
my $pri_tag=$feature->primary_tag();
unless (($pri_tag eq 'CDS')||($pri_tag =~ /RNA/)) {next;}
my @genes_list = ();
my @locus_list = ();
my @product = ();
my @note = ();
my @protein_id = ();
my $bool_found = 0;
my $genes = '';
if($feature->has_tag('gene')){
@genes_list=$feature->each_tag_value('gene');
$bool_found = 1;
}
if($feature->has_tag('locus_tag')){
@locus_list=$feature->each_tag_value('locus_tag');
$bool_found = 1;
}
if($bool_found){
$genes=join('_',@genes_list,@locus_list);
$genes=~s/\ //g;
}
else{ $genes=$pri_tag; }
if($feature->has_tag('product')){
@product=$feature->get_tag_values('product');
}
if($feature->has_tag('note')){
@note=$feature->get_tag_values('note');
}
if($feature->has_tag('protein_id')){
@protein_id=$feature->get_tag_values('protein_id');
}
my $start=$feature->start();
my $end=$feature->end();
my $strand=$feature->strand();
$k++;
$pb_in_genes+=$end-$start+1;
print("$genes\t$start\t$end\t$strand\t@product\t@protein_id\n"); # \t@note\n");
# RECORD IN DATA STRUCT
push @gene, $genes;
push @{ $beg[ $H_ind_T{'gene'} ] }, $start;
push @{ $end[ $H_ind_T{'gene'} ] }, $end;
push @{ $sens[ $H_ind_T{'gene'} ] }, $strand;
push @prot_name, join(' ',@product);
push @Nr_acc_prot, join(' ',@protein_id);
push @{ $comment[ $H_ind_T{'gene'} ] }, join(' ',@note);
push @type, $pri_tag;
}
}
print("parsed $k genes in $length pb sequence with $pb_in_genes pb in genes and ",$length-$pb_in_genes," pb in intergenic spaces (");
printf("%.2f",100*($length-$pb_in_genes)/$length);
print "\%)\n";
# ************************************************************************************
# END EXTRACTION
# ************************************************************************************
# ************************************************************************************
# WRITING IN FILES
# ************************************************************************************
$date = &date();
# record of the whole seq in sens 1 (plus)
if( $edit_file_for_the_whole_one_block_seq0 ){
if($bool_premier_passage and (-e "$chemin_dest".$entete_fasta.'whole_seq0_'.$ID_bact."$end_file".".txt") )
{
system("rm -f $chemin_dest".$entete_fasta.'whole_seq0_'.$ID_bact."$end_file".".txt");
}
open(FSORWHOLESEQ0,">> $chemin_dest".$entete_fasta.'whole_seq0_'.$ID_bact."$end_file".".txt")or die "$prog_tag [Error] Impossible to create $chemin_dest".$entete_fasta."whole_seq0_".$ID_bact."$end_file".".txt\n";
print FSORWHOLESEQ0 &print50($fasta,$sequence);
close FSORWHOLESEQ0;
print "$prog_tag length_sequence : ".length($sequence)."\n";
print "$prog_tag $chemin_dest".$entete_fasta.'whole_seq0_'.$ID_bact."$end_file"."_$date".".txt file created\n";
}
# record of the whole seq in sens -1 (minus)
if( $edit_file_for_the_whole_one_block_seq1 ){
my $rev_seq = reverse "$sequence";
$rev_seq =~ tr/acgtACGT/tgcaTGCA/;
if($bool_premier_passage and (-e "$chemin_dest".$entete_fasta.'whole_seq1_'.$ID_bact."$end_file".".txt") )
{
system("rm -f $chemin_dest".$entete_fasta.'whole_seq1_'.$ID_bact."$end_file".".txt");
}
open(FSORWHOLESEQ1,">> $chemin_dest".$entete_fasta.'whole_seq1_'.$ID_bact."$end_file".".txt")or die "$prog_tag [Error] Impossible to create $chemin_dest".$entete_fasta."whole_seq1_".$ID_bact."$end_file".".txt\n";
# &complement_seq(\$sequence);
print FSORWHOLESEQ1 &print50($fasta,$rev_seq);
close FSORWHOLESEQ1;
print "$prog_tag $chemin_dest".$entete_fasta.'whole_seq1_'.$ID_bact."$end_file"."_$date".".txt file created\n";
}
# edit whole seq(s) for rmes prog
if($edit_file_for_the_whole_one_block_seq_RMES){
# if(($bool_premier_passage) and (-e $chemin_dest.'RMES_'.$ID_bact.$end_file.".txt") )
# {
# die "File $chemin_dest".'RMES_'.$ID_bact.$end_file.".txt already exists, change the destination folder \n";
# }
#
if($bool_premier_passage and (-e "$chemin_dest".'RMES_'.$ID_bact.$end_file.".txt"))
{
system("rm -f $chemin_dest".'RMES_'.$ID_bact.$end_file.".txt");
}
open(FRMES,">> $chemin_dest".'RMES_'.$ID_bact.$end_file.".txt")or die "$prog_tag [Error] Impossible to create $chemin_dest".'RMES_'.$ID_bact.$end_file.".txt\n";
if($bool_premier_passage){ print FRMES ">$ID_bact\n"; }
else { print FRMES "ZZZZZZZZZZ"; }
print FRMES $sequence;
close FRMES;
print "$prog_tag length_sequence : ".length($sequence)."\n";
print $prog_tag.' '.$chemin_dest.'RMES_'.$ID_bact.$end_file.".txt file created\n";
}
# record of every CDS sequences
if($edit_file_for_each_CDS){
# if(($bool_premier_passage) and (-e "$chemin_dest".$entete_fasta.'chaque_CDS_'.$ID_bact."$end_file"."_$date".".txt") )
# {
# die "File $chemin_dest".$entete_fasta.'chaque_CDS_'.$ID_bact."$end_file"."_$date".".txt already exists, change the destination folder \n";
# }
if($bool_premier_passage and (-e "$chemin_dest".$entete_fasta.'chaque_CDS_'.$ID_bact."$end_file"."_$date".".txt"))
{
system("rm -f $chemin_dest".$entete_fasta.'chaque_CDS_'.$ID_bact."$end_file"."_$date".".txt");
}
# pour toutes les sequences CDS (chevauchements possibles)
open(FSOREACHCDS,">> $chemin_dest".$entete_fasta.'chaque_CDS_'.$ID_bact."$end_file"."_$date".".txt")or die "$prog_tag [Error] Impossible to create $chemin_dest".$entete_fasta."chaque_CDS_".$ID_bact."$end_file"."_$date".".txt\n";
for my $cpt_deb_CDS(0..$#{$beg[ $H_ind_T{'gene'} ]})
{
# if($beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS]+1 < $end[ $H_ind_T{'gene'} ][$cpt_deb_CDS])
# {
# enregistrement du codant correspondant
my $long = $end[ $H_ind_T{'gene'} ][$cpt_deb_CDS] - $beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] +1;
print FSOREACHCDS ">CDS_sequence_of_$gene[$cpt_deb_CDS], sens $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] limits : $beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS],$end[ $H_ind_T{'gene'} ][$cpt_deb_CDS]\n";
($not_verbose)or print "\n>CDS sequence of $gene[$cpt_deb_CDS] sens $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS]\n";
if($sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] == -1)
{
print FSOREACHCDS &print50($fasta,&complement_seq(substr($sequence,$beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] -1, $long)));
($not_verbose)or print &print50($fasta,&complement_seq(substr($sequence,$beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] -1, $long)));
}
elsif($sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] == 1)
{
print FSOREACHCDS &print50($fasta,substr($sequence,$beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] -1, $long));
($not_verbose)or print &print50($fasta,substr($sequence,$beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] -1, $long));
}
else
{
print "$prog_tag Unknown sens for $gene[$cpt_deb_CDS]\n";
}
# }
# else
# {
# die "Problem : end of CDS ($end[ $H_ind_T{'gene'} ][$cpt_deb_CDS]) lower than beginning ($beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS]) for gene $gene[$cpt_deb_CDS]\n";
# }
}
close FSOREACHCDS;
print "$prog_tag $chemin_dest".$entete_fasta.'chaque_CDS_'.$ID_bact."$end_file"."_$date".".txt file created\n";
}
if($edit_file_for_all_CDS)
{
# if(($bool_premier_passage) and (-e "$chemin_dest".$entete_fasta.'ens_seq_CDS_'.$ID_bact."$end_file"."_$date".".txt") )
# {
# die "File $chemin_dest".$entete_fasta.'ens_seq_CDS_'.$ID_bact."$end_file"."_$date".".txt already exists, change the destination folder \n";
# }
#
if($bool_premier_passage and (-e "$chemin_dest".$entete_fasta.'ens_seq_CDS_'.$ID_bact."$end_file"."_$date".".txt")){
system("rm -f $chemin_dest".$entete_fasta.'ens_seq_CDS_'.$ID_bact."$end_file"."_$date".".txt");
}
# pour l'ensemble des sequences CDS (pas de chevauchement)
open(FSORENSCDS,">> $chemin_dest".$entete_fasta.'ens_seq_CDS_'.$ID_bact."$end_file"."_$date".".txt")or die "$prog_tag [Error] Impossible to create $chemin_dest".$entete_fasta."ens_seq_CDS_".$ID_bact."$end_file"."_$date".".txt\n";
($not_verbose) or print "$prog_tag Appel get_limits line ".__LINE__."\n";
my ($debut, $fin) = &get_limits(0);
my ($gene_beg, $gene_end);
my $temp_deb = undef;
for my $cpt_deb_CDS(1..$#{$beg[ $H_ind_T{'gene'} ]})
{
($not_verbose) or print "$prog_tag Appel get_limits line ".__LINE__."\n";
($gene_beg, $gene_end) = &get_limits($cpt_deb_CDS);
if($gene_beg > $fin+1)
{
# enregistrement du codant precedent
$cpt_seq++;
my $long = $fin - $debut +1;
print FSORENSCDS ">CDS_sequence_set_$cpt_seq limits : $debut, $fin\n";
print FSORENSCDS &print50($fasta,substr($sequence,$debut -1, $long));
($not_verbose)or print "\n>CDS Sequence set $cpt_seq\n";
($not_verbose)or print &print50($fasta,substr($sequence,$debut -1, $long));
($not_verbose) or print "$prog_tag Appel get_limits line ".__LINE__."\n";
($debut, $fin) = &get_limits($cpt_deb_CDS);
if($cpt_deb_CDS == $#{$beg[ $H_ind_T{'gene'} ]})
{
print FSORENSCDS ">CDS_sequence_set_$cpt_seq limits : $debut, $fin\n";
print FSORENSCDS &print50($fasta,substr($sequence,$debut -1, $long));
}
}
else
{
($not_verbose) or print "$prog_tag Appel get_limits line ".__LINE__."\n";
($temp_deb, $fin) = &get_limits($cpt_deb_CDS);
}
}
close FSORENSCDS;
print "$prog_tag $chemin_dest".$entete_fasta.'ens_seq_CDS_'.$ID_bact."$end_file"."_$date".".txt file created\n";
$cpt_seq = 0;
}
# ******** ??? A REPRENDRE
if($edit_file_for_promoters)
{
# if(($bool_premier_passage) and (-e "$chemin_dest".$entete_fasta.'promot_'.$ID_bact."$end_file".".txt") )
# {
# die "File $chemin_dest".$entete_fasta.'promot_'.$ID_bact."$end_file".".txt already exists, change the destination folder \n";
# }
if($bool_premier_passage and (-e "$chemin_dest".$entete_fasta.'promot_'.$ID_bact."$end_file".".txt")){
system("rm -f $chemin_dest".$entete_fasta.'promot_'.$ID_bact."$end_file".".txt");
}
# output file pour toutes les sequences promotrices (chevauchements possibles)
open(FSORPROMOT,">> $chemin_dest".$entete_fasta.'promot_'.$ID_bact."$end_file".".txt")or die "$prog_tag [Error] Impossible to create $chemin_dest".$entete_fasta."promot_".$ID_bact."$end_file".".txt\n";
if($edit_limits_of_promoters)
{
# if(($bool_premier_passage) and (-e "$chemin_dest".'limits_of_promot_'.$ID_bact."$end_file".".txt") )
# {
# die "File $chemin_dest".'limits_of_promot_'.$ID_bact."$end_file".".txt already exists, change the destination folder \n";
# }
if($bool_premier_passage and (-e "$chemin_dest".'limits_of_promot_'.$ID_bact."$end_file".".txt")){
system("rm -f $chemin_dest".'limits_of_promot_'.$ID_bact."$end_file".".txt");
}
open(FSORLIMITS_PROMOT,">> $chemin_dest".'limits_of_promot_'.$ID_bact."$end_file".".txt")or die "$prog_tag [Error] Impossible to create $chemin_dest".'limits_of_promot_'.$ID_bact."$end_file".".txt\n";
}
# open(FSORPROMOT2,">> $chemin_dest".$entete_fasta.'promot_ss_seq'.$ID_bact."$end_file"."_$date".".txt")or die "Impossible to create $chemin_dest".$entete_fasta."promot_ss_seq".$ID_bact."$end_file"."_$date".".txt\n";
my $long = 0;
my $RBS_upstr = '';
my $temp_gene_end_prec_for_sens0_limit = 0;
my $string_limits_sens1 = '';
my $string_limits_sens0 = '';
my $prem_sens = undef; # $sens[ $H_ind_T{'gene'} ][0];
# pour chaque limite inferieure de gene...
for my $cpt_deb_CDS(0..$#{$beg[ $H_ind_T{'gene'} ]})
{
$prem_sens = $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS];
# ...nous recuperons tous les RBS associes
# if(defined $imp_linked_to[$cpt_deb_CDS]){
# # Pour cela, nous listons tous les 'imp' associes a ce gene
# for my $nri(0..$#{ $imp_linked_to[$cpt_deb_CDS] }){
# # sens du (des) RBS A VERIFIER !!!
# for my $nb_sens(0..$#{ $sens[ $H_ind_T{'imp'} ][$nri] }){
# # nous ne devons garder QUE ceux etant des RBS ET DANS LE MEME SENS
# if($sens[$H_ind_T{'gene'}][$cpt_deb_CDS] == $sens[$H_ind_T{'imp'}][$nri][$nb_sens] )
# {
# ($imp_type[ $imp_linked_to[$cpt_deb_CDS][$nri][1] ] eq 'RBS') and $RBS_upstr .= " beg $beg[ $H_ind_T{'imp'} ][$nri][ $imp_linked_to[$cpt_deb_CDS][0] ], end $end[ $H_ind_T{'imp'} ][$nri][ $imp_linked_to[$cpt_deb_CDS][0] ]";
# }
# }
# }
# }
($not_verbose) or print "$prog_tag Appel get_limits line ".__LINE__."\n";
my ($gene_beg, $gene_end) = &get_limits($cpt_deb_CDS);
my ($gene_beg_prec, $gene_end_prec);
# ?????
my ($gene_beg_suiv, $gene_end_suiv);
if($prem_sens == -1)
{
($not_verbose)or print "\n>Promot_for:"."$gene[$cpt_deb_CDS] sens $prem_sens deb_trad ".(-$dist_fin_up_seq_deb_trad)."\n"; # , upstr RBS:$RBS_upstr
# si l'on n'a pas affaire au dernier CDS # ??
if($cpt_deb_CDS != $#{$beg[ $H_ind_T{'gene'} ]})
{
($not_verbose) or print "$prog_tag Appel get_limits line ".__LINE__."\n";
($gene_beg_suiv, $gene_end_suiv) = &get_limits($cpt_deb_CDS+1);
# longueur = difference entre fin du CDS courant et debut du CDS precedent + la marge (quelques nucleotides apres)
$long = $gene_beg_suiv - $gene_end-1 -$dist_fin_up_seq_deb_trad;
print "$prog_tag longueur vaut ".$gene_beg_suiv."-".$gene_end."-1 - $dist_fin_up_seq_deb_trad\n";
}
else
{
# longueur = longueur de la sequence globale - limite de fin du gene - la marge souhaitee
$long = $length_sequence -$end[ $H_ind_T{'gene'} ][0]-1 -$dist_fin_up_seq_deb_trad;
}
# sequence inexistante... on ne met que l'en-tete (si l'utilsateur le souhaite)
if($long < 1 -$dist_fin_up_seq_deb_trad)
{
print FSORPROMOT ">Promot_for:"."$gene[$cpt_deb_CDS] sens $prem_sens deb_trad ".(-$dist_fin_up_seq_deb_trad)."\n\n"; # , upstr RBS:$RBS_upstr
# print FSORPROMOT2 "No intergenic region corresponding to\n";
($not_verbose)or print "$prog_tag No intergenic region corresponding to $gene[$cpt_deb_CDS]\n";
($edit_limits_of_promoters)and $string_limits_sens1 .= "-1,-1;";
}
# sequence trop courte par rapport a la limite basse definie (longueurmini)
elsif($long < $longueurmini)
{
print FSORPROMOT ">Promot_for:"."$gene[$cpt_deb_CDS] sens $prem_sens deb_trad ".(-$dist_fin_up_seq_deb_trad)."\n\n"; # upstr RBS:$RBS_upstr
# print FSORPROMOT2 "Intergenic region to short (mini length:$longueurmini, distance from translation start:$dist_fin_up_seq_deb_trad)\n";
($not_verbose)or print "Intergenic region to short (mini length:$longueurmini, distance from translation start:$dist_fin_up_seq_deb_trad)\n";
print "$prog_tag longueur $long inferieure a longueur_mini $longueurmini\n";
($edit_limits_of_promoters) and $string_limits_sens1 .= "-1,-1;";
}
else
{
if(!defined $gene[$cpt_deb_CDS]){ print "$prog_tag gene not defined for $cpt_deb_CDS\n";}
($not_verbose)or print "$prog_tag on imprime la partie de la seq commencant a la position $gene_end+$dist_fin_up_seq_deb_trad =".($gene_end+$dist_fin_up_seq_deb_trad)." et de longueur $long\n";
($not_verbose)or print &print50($fasta,&complement_seq(substr($sequence,$gene_end+$dist_fin_up_seq_deb_trad, $long)));
print FSORPROMOT ">Promot_for:"."$gene[$cpt_deb_CDS] sens $prem_sens deb_trad ".(-$dist_fin_up_seq_deb_trad)."\n"; # , upstr RBS:$RBS_upstr
print FSORPROMOT &print50($fasta,&complement_seq(substr($sequence,$gene_end+$dist_fin_up_seq_deb_trad, $long)));
($edit_limits_of_promoters) and $string_limits_sens1 .= $gene_end.",".($gene_end + $long-1).";"
}
}
# traitement des sequences en sens 1
elsif($prem_sens == 1)
{
($not_verbose)or print "\n>Promot_for:"."$gene[$cpt_deb_CDS] sens $prem_sens deb_trad ".(-$dist_fin_up_seq_deb_trad)."\n"; # , upstr RBS:$RBS_upstr
my $debut = undef;
# cas general, nous ne traitons pas le premier gene
if($cpt_deb_CDS)
{
# ??
($not_verbose) or print "$prog_tag Appel get_limits line ".__LINE__."\n";
($gene_beg_prec, $gene_end_prec) = &get_limits($cpt_deb_CDS-1);
if($gene_end_prec > $temp_gene_end_prec_for_sens0_limit)
{
$temp_gene_end_prec_for_sens0_limit = $gene_end_prec;
}
else
{
print "$prog_tag LIMITE: pour le gene $gene[$cpt_deb_CDS] la fin du gene précedent $gene_end_prec , est inférieur à la fin du gene d'avant, $temp_gene_end_prec_for_sens0_limit\n";
}
$debut = $temp_gene_end_prec_for_sens0_limit;
$long = $gene_beg - $temp_gene_end_prec_for_sens0_limit - 1 -$dist_fin_up_seq_deb_trad;
print "$prog_tag on memorise pour debut $debut et pour longueur $long ($gene_beg - $temp_gene_end_prec_for_sens0_limit - 1 -$dist_fin_up_seq_deb_trad) pour $gene[$cpt_deb_CDS]\n";
}
# traitement du premier gene du genome
else
{
$debut = 0;
$long = $beg[ $H_ind_T{'gene'} ][0] - 1-$dist_fin_up_seq_deb_trad;
print "$prog_tag on memorise pour debut $debut et pour longueur $long ($beg[ $H_ind_T{'gene'} ][0] - 1 - $dist_fin_up_seq_deb_trad)\n";
# print "long $long vaut $beg[ $H_ind_T{'gene'} ][0] - 1 - $dist_fin_up_seq_deb_trad\n";
}
# sequence inexistante
if($long < 1-$dist_fin_up_seq_deb_trad )
{
print FSORPROMOT ">Promot_for:"."$gene[$cpt_deb_CDS] sens $prem_sens deb_trad ".(-$dist_fin_up_seq_deb_trad)."\n\n"; # , upstr RBS:$RBS_upstr
# print FSORPROMOT2 "No intergenic region corresponding to\n";
($not_verbose)or print "$prog_tag No intergenic region corresponding to\n";
($edit_limits_of_promoters) and $string_limits_sens0 .= "-1,-1;";
}
# sequence trop courte
elsif($long < $longueurmini)
{
print FSORPROMOT ">Promot_for:"."$gene[$cpt_deb_CDS] sens $prem_sens deb_trad ".(-$dist_fin_up_seq_deb_trad)."\n\n"; # , upstr RBS:$RBS_upstr
# print FSORPROMOT2 "Intergenic region to short (mini length:$longueurmini, distance from translation start:$dist_fin_up_seq_deb_trad)\n";
($not_verbose)or print "$prog_tag Intergenic region to short ($long)(mini length:$longueurmini, distance from translation start:$dist_fin_up_seq_deb_trad)\n";
($edit_limits_of_promoters) and $string_limits_sens0 .= "-1,-1;";
}
# cas general
else
{
print FSORPROMOT ">Promot_for:"."$gene[$cpt_deb_CDS] sens $prem_sens deb_trad ".(-$dist_fin_up_seq_deb_trad)."\n"; # upstr RBS:$RBS_upstr
print "$prog_tag Debut $debut long $long ".length($sequence)."\n";
if($debut + $long >= length($sequence)){
print "$prog_tag pb gene $gene[$cpt_deb_CDS] \n";
exit;
}
print FSORPROMOT &print50($fasta,substr($sequence,$debut, $long));
($not_verbose)or print &print50($fasta,substr($sequence,$debut, $long));
print "$prog_tag on memorise pour debut $debut et pour longueur $long\n";
# die "on extrait de $debut a ".($beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] -1)." pour $gene[$cpt_deb_CDS] sens $prem_sens\n";
($edit_limits_of_promoters) and $string_limits_sens0 .= $debut.",".($debut + $long-1).";";
}
}
# sens non connu
else{
print FSORPROMOT ">Promot_for:"."$gene[$cpt_deb_CDS] sens $prem_sens (unknown) deb_trad ".(-$dist_fin_up_seq_deb_trad)."\n\n"; # upstr RBS:$RBS_upstr
print "$prog_tag undefined sens for $prem_sens line ".__LINE__."\n";
}
}
close FSORPROMOT;
# close FSORPROMOT2;
print "$prog_tag $chemin_dest".$entete_fasta.'promot_'.$ID_bact."$end_file".".txt file created\n";
# print "$chemin_dest".$entete_fasta.'promot_ss_seq'.$ID_bact."$end_file"."_$date".".txt file created\n";
if($edit_limits_of_promoters)
{
print FSORLIMITS_PROMOT $string_limits_sens0."\n".$string_limits_sens1."\n";
close FSORLIMITS_PROMOT;
}
}
if($edit_file_for_all_interCDS)
{
# if(($bool_premier_passage) and (-e "$chemin_dest".$entete_fasta.'seq_interCDS_'.$ID_bact."$end_file"."_$date".".txt") )
# {
# die "File $chemin_dest".$entete_fasta.'seq_interCDS_'.$ID_bact."$end_file"."_$date".".txt already exists, change the destination folder \n";
# }
if($bool_premier_passage and (-e "$chemin_dest".$entete_fasta.'seq_interCDS_'.$ID_bact."$end_file"."_$date".".txt")){
system("rm -f $chemin_dest".$entete_fasta.'seq_interCDS_'.$ID_bact."$end_file"."_$date".".txt");
}
# pour toutes les sequences interCDS
open(FSORENSINTERCDS,">> $chemin_dest".$entete_fasta.'seq_interCDS_'.$ID_bact."$end_file"."_$date".".txt")or die "$prog_tag [Error] Impossible to create $chemin_dest".$entete_fasta."seq_interCDS_".$ID_bact."$end_file"."_$date".".txt\n";
if($beg[ $H_ind_T{'gene'} ][0] != 1)
{
$cpt_seq++;
print FSORENSINTERCDS ">InterCDS_sequence_$cpt_seq\n";
print FSORENSINTERCDS &print50($fasta,substr($sequence,0,$beg[ $H_ind_T{'gene'} ][0]-1));
($not_verbose)or print "\n>InterCDS sequence $cpt_seq 1\n";
($not_verbose)or print &print50($fasta,substr($sequence,0,$beg[ $H_ind_T{'gene'} ][0]-1));
}
for my $chaqueCDS(0..($#{$beg[ $H_ind_T{'gene'} ]}-1))
{
($not_verbose)or print "\ndeb_CDS fin_CDS\n$beg[ $H_ind_T{'gene'} ][$chaqueCDS+1] $end[ $H_ind_T{'gene'} ][$chaqueCDS]";
if( (my $long = $beg[ $H_ind_T{'gene'} ][$chaqueCDS+1]-$end[ $H_ind_T{'gene'} ][$chaqueCDS]-1)>0 )
{
$cpt_seq++;
print FSORENSINTERCDS ">InterCDS_sequence_$cpt_seq\n";
print FSORENSINTERCDS &print50($fasta,substr($sequence,$end[ $H_ind_T{'gene'} ][$chaqueCDS], $long));
($not_verbose)or print "\n>InterCDS sequence $cpt_seq\n";
($not_verbose)or print &print50($fasta,substr($sequence,$end[ $H_ind_T{'gene'} ][$chaqueCDS], $long));
}
else
{
($not_verbose)or print "\n$prog_tag Problem, upstream limit of interCDS higher than downstream limit!\nCSD must overlap!\n";
# print FPB "Problem, upstream limit of interCDS higher than downstream limit!\nCSD must overlap!\n";
}
}
if($length_sequence-$end[ $H_ind_T{'gene'} ][$#{$end[ $H_ind_T{'gene'} ]}] != 0)
{
$cpt_seq++;
print FSORENSINTERCDS ">InterCDS_sequence_$cpt_seq\n";
print FSORENSINTERCDS &print50($fasta,substr($sequence,$end[ $H_ind_T{'gene'} ][$#{$end[ $H_ind_T{'gene'} ]}],$length_sequence - $end[ $H_ind_T{'gene'} ][$#{$end[ $H_ind_T{'gene'} ]}]));
($not_verbose)or print "\n>InterCDS sequence $cpt_seq\n";
($not_verbose)or print &print50($fasta,substr($sequence,$end[ $H_ind_T{'gene'} ][$#{$end[ $H_ind_T{'gene'} ]}],$length_sequence - $end[ $H_ind_T{'gene'} ][$#{$end[ $H_ind_T{'gene'} ]}]));
}
close FSORENSINTERCDS;
print "$prog_tag $chemin_dest".$entete_fasta.'seq_interCDS_'.$ID_bact."$end_file"."_$date".".txt file created\n";
$cpt_seq = 0;
}
# if($edit_file_for_all_interCDS_between_conv)
# {
# pour les sequences interCDS entre genes convergents
# open(FSORCONV,"> $chemin_dest".$entete_fasta.'seq_interCDS_entre_conv_'.$ID_bact."$end_file"."_$date".".txt")or die "Impossible to create $chemin_dest".$entete_fasta."seq_interCDS_entre_conv_".$ID_bact."$end_file"."_$date".".txt\n";
# for my $chaqueCDS(0..$#deb_interCDS_entre_conv)
# {
# my $long = $fin_interCDS_entre_conv[$chaqueCDS]-$deb_interCDS_entre_conv[$chaqueCDS];
# $cpt_seq++;
# print FSORCONV ">InterCDS_between_convergent_genes_$cpt_seq\n";
# print FSORCONV &print50($fasta,substr($sequence,$deb_interCDS_entre_conv[$chaqueCDS], $long));
# ($not_verbose)or print "\n>InterCDS between convergent genes $cpt_seq\n";
# ($not_verbose)or print &print50($fasta,substr($sequence,$deb_interCDS_entre_conv[$chaqueCDS], $long));
# }
# close FSORCONV;
# print "$chemin_dest".'seq_interCDS_entre_conv_'.$ID_bact."$end_file"."_$date".".txt file created\n";
# $cpt_seq = 0;
# }
# if($edit_file_for_all_interCDS_between_div)
# {
# pour les sequences interCDS entre genes divergents
# open(FSORDIV,"> $chemin_dest".$entete_fasta.'seq_interCDS_entre_div_'.$ID_bact."$end_file"."_$date".".txt")or die "Impossible to create $chemin_dest".$entete_fasta."seq_interCDS_entre_div_".$ID_bact."$end_file"."_$date".".txt\n";
# for my $chaqueCDS(0..$#deb_interCDS_entre_div)
# {
# my $long = $fin_interCDS_entre_div[$chaqueCDS]-$deb_interCDS_entre_div[$chaqueCDS];
# $cpt_seq++;
# print FSORDIV ">InterCDS_between_divergent_genes_$cpt_seq\n";
# print FSORDIV &print50($fasta,substr($sequence,$deb_interCDS_entre_div[$chaqueCDS], $long));
# ($not_verbose)or print "\n>InterCDS between divergent genes $cpt_seq\n";
# ($not_verbose)or print &print50($fasta,substr($sequence,$deb_interCDS_entre_div[$chaqueCDS], $long));
# }
# close FSORDIV;
# print "$chemin_dest".'seq_interCDS_entre_div_'.$ID_bact."$end_file"."_$date".".txt file created\n";
# $cpt_seq = 0;
# }
#if($edit_file_for_all_CDS_interCDS_between_conv)
#{
#pour les sequence CDS+interCDS entre genes conv
# open(FSORCDS_INTERCDSCONV,"> $chemin_dest".$entete_fasta.'seq_CDS_et_interCDS_entre_conv_'.$ID_bact."$end_file"."_$date".".txt")or die "Impossible to create $chemin_dest".$entete_fasta."seq_CDS_et_interCDS_entre_conv_".$ID_bact."$end_file"."_$date".".txt\n";
# for my $chaqueCDS(0..$#deb_CDS_interCDS_entre_conv)
# {
# my $long = $fin_CDS_interCDS_entre_conv[$chaqueCDS]-$deb_CDS_interCDS_entre_conv[$chaqueCDS]+1;
# $cpt_seq++;
# print FSORCDS_INTERCDSCONV ">CDS&interCDS_between_convergent_genes_$cpt_seq\n";
# print FSORCDS_INTERCDSCONV &print50($fasta,substr($sequence,$deb_CDS_interCDS_entre_conv[$chaqueCDS]-1, $long));
# ($not_verbose)or print "\n>CDS&interCDS between convergent genes $cpt_seq\n";
# ($not_verbose)or print &print50($fasta,substr($sequence,$deb_CDS_interCDS_entre_conv[$chaqueCDS]-1, $long));
# }
# close FSORCDS_INTERCDSCONV;
# print "$chemin_dest".$entete_fasta.'seq_CDS_et_interCDS_entre_conv_'.$ID_bact."$end_file"."_$date".".txt file created\n";
# $cpt_seq = 0;
#}
# OK
if($edit_file_for_all_annotations)
{
my $bool_with_limits = 1;
# pour toutes les annotations
# if(($bool_premier_passage) and (-e "$chemin_dest".'annot_'.$ID_bact.$end_file.".txt") )
# {
# die "File $chemin_dest".'annot_'.$ID_bact.$end_file.".txt already exists, change the destination folder \n";
# }
#
if($bool_premier_passage and (-e "$chemin_dest".'annot_'.$ID_bact.$end_file.".txt")){
system("rm -f $chemin_dest".'annot_'.$ID_bact.$end_file.".txt");
}
# pour toutes les sequences CDS (donc leurs annotations)
open(FSOREACHANNOT,">> $chemin_dest".'annot_'.$ID_bact.$end_file.".txt")or die "$prog_tag [Error] Impossible to create $chemin_dest"."annot_".$ID_bact.$end_file.".txt\n";
for my $numg(0..$#gene)
{
# my $long = $end[ $H_ind_T{'gene'} ][$numg] - $beg[ $H_ind_T{'gene'} ][$numg] +1;
print FSOREACHANNOT ">annot_for_$gene[$numg]";
# (defined $prot_name[$numg]) and print FSOREACHANNOT ", prot_name $prot_name[$numg], Nr_acc_prot $Nr_acc_prot[$numg], ";
print FSOREACHANNOT ", prot_name $prot_name[$numg]\n";
# print FSOREACHANNOT "\n";
# ($not_verbose)or print "\n>annot for $gene[$numg]";
# if(defined $imp_linked_to[$numg]){
# # print "DEFINI\n";1
# print FSOREACHANNOT "RELATED ANNOTATIONS:\n";
# for my $nri(0..$#{ $imp_linked_to[$numg] }){
# # print "nri $nri\n";
# # print FSOREACHANNOT "imp: $imp_type_kind[ $imp_type[ $imp_linked_to[$nri][1] ]] , sens $sens[ $H_ind_T{'imp'} ][ $imp_linked_to[$nri][1] ][ $imp_linked_to[$nri][0] ], beg $beg[ $H_ind_T{'imp'} ][ $imp_linked_to[$nri][1] ][ $imp_linked_to[$nri][0] ], end $end[ $H_ind_T{'imp'} ][ $imp_linked_to[$nri][1] ][ $imp_linked_to[$nri][0] ], ";
# # print "imp_linked_to nri $nri 1 $imp_linked_to[$numg][$nri][1]\n";
# # print "imp_linked_to nri $nri 0 $imp_linked_to[$numg][$nri][0]\n";
# # print "imp: imp_type $imp_type[ $imp_linked_to[$numg][$nri][1] ]\n";
# # print "sens sens $sens[ $H_ind_T{'imp'} ][ $imp_linked_to[$numg][$nri][1] ][ $imp_linked_to[$numg][$nri][0] ]\n";
# print FSOREACHANNOT "$imp_type_kind[ $imp_type[ $imp_linked_to[$numg][$nri][1] ]] , imp_sens $sens[ $H_ind_T{'imp'} ][ $imp_linked_to[$numg][$nri][1] ][ $imp_linked_to[$numg][$nri][0] ], $beg[ $H_ind_T{'imp'} ][ $imp_linked_to[$numg][$nri][1] ][ $imp_linked_to[$numg][$nri][0] ]..$end[ $H_ind_T{'imp'} ][ $imp_linked_to[$numg][$nri][1] ][ $imp_linked_to[$numg][$nri][0] ]";
# defined($comment[ $H_ind_T{'imp'} ][$nri] ) and do
# {
# # defined($comment[ $H_ind_T{'imp'} ][ $imp_linked_to[$numg][$nri] ]) and do {
# foreach(@{ $comment[ $H_ind_T{'imp'} ][$nri] }){
# print FSOREACHANNOT ", comment_imp: $_";
# }
# };
# print FSOREACHANNOT "\n";
# # }
# }
# # exit;
# }
# else{ print "imp_linked_to of $gene[$numg] NOT DEF\n"; }
# ?????
(defined $sens[ $H_ind_T{'gene'} ][$numg])and do { ($sens[ $H_ind_T{'gene'} ][$numg] == 3)and print "$prog_tag PB: UNKNOWN SENS for $gene[$numg]\n";
print FSOREACHANNOT "gene_sens $sens[ $H_ind_T{'gene'} ][$numg], ";
};
($bool_with_limits)and print FSOREACHANNOT "$beg[ $H_ind_T{'gene'} ][$numg]..$end[ $H_ind_T{'gene'} ][$numg], ";
(defined $Nr_acc_prot[$numg]) and print FSOREACHANNOT "Nr_acc_prot $Nr_acc_prot[$numg], ";
# (defined $seqdesc_title[ $H_ind_T{'prot'} ][$numg])and print FSOREACHANNOT "seqdesc_title $seqdesc_title[ $H_ind_T{'prot'} ][$numg], ";
print FSOREACHANNOT "$beg[ $H_ind_T{'prot'} ][$numg]..$end[ $H_ind_T{'prot'} ][$numg], ";
(defined $sens[ $H_ind_T{'prot'} ][$numg])and print FSOREACHANNOT "prot_sens $sens[ $H_ind_T{'prot'} ][$numg], ";
# print 'prot '.substr($prot[$numg],0,7)."\n";
if (defined($comment[ $H_ind_T{'gene'} ][$numg])){
print FSOREACHANNOT "\ngene comment :$comment[ $H_ind_T{'gene'} ][$numg]; ";
}
if (defined($comment[ $H_ind_T{'prot'} ][$numg])){
print FSOREACHANNOT "\nprot comment :$comment[ $H_ind_T{'prot'} ][$numg]; ";
}
# if((defined $comment_cdregion[$numg]) and ($comment_cdregion[$numg] ne ''))
# {
# print FSOREACHANNOT "\ncomment_cdregion : $comment_cdregion[$numg]";
# print " comment cdregion $comment_cdregion[$numg] pour $numg $gene[$numg]\n";
# }
# if(defined $region_linked_to[$numg])
# {
# print FSOREACHANNOT "\nRegion(s) :";
# for my $nri(0..$#{ $region_linked_to[$numg] })
# {
# print FSOREACHANNOT "$region[$region_linked_to[$numg][$nri]],";
# }
# }
print FSOREACHANNOT "\n";
# ($not_verbose)or print ;
}
close FSOREACHANNOT;
print $prog_tag.' '.$chemin_dest.'annot_'.$ID_bact.$end_file.".txt file created\n";
# $cpt_seq = 0;
}
if($edit_file_for_upstream_seq)
{
# !!!!!!!ATTENTION: cas deb trop courts par rapport a longueur demandee non encore teste!!!!!!!!!!!!!!!!!! (decallage possible d'une lettre?)
# if(($bool_premier_passage) and (-e "$chemin_dest".$entete_fasta."upstr_seq_".(-$dist_deb_up_seq_deb_trad)."_".(-$dist_fin_up_seq_deb_trad).'_'.$ID_bact."$end_file"."_$date".".txt") )
# {
# die "File $chemin_dest".$entete_fasta."upstr_seq_".(-$dist_deb_up_seq_deb_trad)."_".(-$dist_fin_up_seq_deb_trad).'_'.$ID_bact."$end_file"."_$date".".txt already exists, change the destination folder \n";
# }
#
if($bool_premier_passage and (-e "$chemin_dest".$entete_fasta."upstr_seq_".(-$dist_deb_up_seq_deb_trad)."_".(-$dist_fin_up_seq_deb_trad).'_'.$ID_bact."$end_file".".txt")){
system("rm -f $chemin_dest".$entete_fasta."upstr_seq_".(-$dist_deb_up_seq_deb_trad)."_".(-$dist_fin_up_seq_deb_trad).'_'.$ID_bact."$end_file".".txt");
}
# pour toutes les sequences amont (chevauchements possibles)
open(FSORUPSEQ,">> $chemin_dest".$entete_fasta."upstr_seq_".(-$dist_deb_up_seq_deb_trad)."_".(-$dist_fin_up_seq_deb_trad).'_'.$ID_bact."$end_file".".txt")or die "$prog_tag [Error] Impossible to create $chemin_dest".$entete_fasta."upstr_seq_".(-$dist_deb_up_seq_deb_trad)."_".(-$dist_fin_up_seq_deb_trad).'_'.$ID_bact."$end_file".".txt\n";
for my $cpt_deb_CDS(0..$#{$beg[ $H_ind_T{'gene'} ]})
{
my $RBS_upstr = 0;
# if(defined $imp_linked_to[$cpt_deb_CDS]){
# for my $nri(0..$#{ $imp_linked_to[$cpt_deb_CDS] }){
# # for my $nb_sens(0..$#{ $sens[ $H_ind_T{'imp'} ][$nri] }){
# ($imp_type_kind[$imp_type[ $imp_linked_to[$cpt_deb_CDS][$nri][1] ]] eq 'RBS') and $RBS_upstr .= " beg $beg[ $H_ind_T{'imp'} ][ $imp_linked_to[$cpt_deb_CDS][$nri][1] ][ $imp_linked_to[$cpt_deb_CDS][$nri][0] ], end $end[ $H_ind_T{'imp'} ][ $imp_linked_to[$cpt_deb_CDS][$nri][1] ][ $imp_linked_to[$cpt_deb_CDS][$nri][0] ]";
# # }
# }
# }
#if(exists $H_RBS{$cpt_deb_CDS}){ $RBS_upstr = $H_RBS{$cpt_deb_CDS};}
# traitement des sequences en sens -1
if($sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] == -1 or $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] == 2)
{
($not_verbose)or print "\n>Promot_for:"."$gene[$cpt_deb_CDS] sens $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] deb_trad ".(-$dist_fin_up_seq_deb_trad).", upstr RBS:$RBS_upstr\n";
#si ce n'est pas le dernier gene
if($length_sequence - $end[ $H_ind_T{'gene'} ][$cpt_deb_CDS] >= $dist_deb_up_seq_deb_trad)
{
print FSORUPSEQ ">Promot_for:"."$gene[$cpt_deb_CDS] sens $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] deb_trad ".(-$dist_fin_up_seq_deb_trad).", upstr RBS:$RBS_upstr\n";
print FSORUPSEQ &print50($fasta,&complement_seq(substr($sequence,$end[ $H_ind_T{'gene'} ][$cpt_deb_CDS]+$dist_fin_up_seq_deb_trad, $length_upstream)));
($not_verbose)or print &print50($fasta,&complement_seq(substr($sequence,$end[ $H_ind_T{'gene'} ][$cpt_deb_CDS]+$dist_fin_up_seq_deb_trad, $length_upstream)));
}
elsif((my $length_end = $length_sequence - $dist_fin_up_seq_deb_trad - $end[ $H_ind_T{'gene'} ][$cpt_deb_CDS]) >= $longueurmini)
{
print FSORUPSEQ ">Promot_for:"."$gene[$cpt_deb_CDS] sens $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS]deb_trad ".(-$dist_fin_up_seq_deb_trad).", upstr RBS:$RBS_upstr\n";
print FSORUPSEQ &print50($fasta,&complement_seq(substr($sequence,$end[ $H_ind_T{'gene'} ][$cpt_deb_CDS]+$dist_fin_up_seq_deb_trad, $length_end)));
($not_verbose)or print &print50($fasta,&complement_seq(substr($sequence,$end[ $H_ind_T{'gene'} ][$cpt_deb_CDS]+$dist_fin_up_seq_deb_trad, $length_end)));
}
else
{
print "$prog_tag Upstream sequence of $gene[$cpt_deb_CDS] gene to short to be used\n";
}
}
elsif($sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] == 1 or $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] == 2)
{
# traitement des sequences en sens 1
($not_verbose)or print "\n>Promot_for:"."$gene[$cpt_deb_CDS] sens $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] upstr RBS:$RBS_upstr\n";
if( $beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] > $dist_deb_up_seq_deb_trad)
{
print FSORUPSEQ ">Promot_for:"."$gene[$cpt_deb_CDS] sens $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] deb_trad ".(-$dist_fin_up_seq_deb_trad).", upstr RBS:$RBS_upstr\n";
print FSORUPSEQ &print50($fasta,substr($sequence,$beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] - $dist_deb_up_seq_deb_trad -1, $length_upstream));
($not_verbose)or print &print50($fasta,substr($sequence,$beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] - $dist_deb_up_seq_deb_trad -1, $length_upstream));
}
elsif($beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] > $dist_fin_up_seq_deb_trad + $longueurmini)
{
print FSORUPSEQ ">Promot_for:"."$gene[$cpt_deb_CDS] sens $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] deb_trad ".(-$dist_fin_up_seq_deb_trad).", upstr RBS:$RBS_upstr\n";
print FSORUPSEQ &print50($fasta,substr($sequence, 0, $beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] - $dist_fin_up_seq_deb_trad));
($not_verbose)or print &print50($fasta,substr($sequence, 0, $beg[ $H_ind_T{'gene'} ][$cpt_deb_CDS] - $dist_fin_up_seq_deb_trad));
print "$prog_tag Verifier la longueur de la sequence amont du premier gene\n";
}
else
{
print "$prog_tag Upstream sequence of $gene[$cpt_deb_CDS] gene to short to be used\n";
}
}
else{
die "$prog_tag [Error] case of unknown sens $sens[ $H_ind_T{'gene'} ][$cpt_deb_CDS] we have to treat line ".__LINE__."\n";
}
}