forked from keylabivdc/VIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinseq-lite.pl
4850 lines (4508 loc) · 187 KB
/
prinseq-lite.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
#===============================================================================
# Author: Robert SCHMIEDER, Computational Science Research Center @ SDSU, CA
#
# File: prinseq-lite
# Date: 2013-03-13
# Version: 0.20.3 lite
#
# Usage:
# prinseq-lite [options]
#
# Try 'prinseq-lite -h' for more information.
#
# Purpose: PRINSEQ will help you to preprocess your genomic or metagenomic
# sequence data in FASTA or FASTQ format. The lite version does not
# require any non-core perl modules for processing.
#
# Bugs: Please use http://sourceforge.net/tracker/?group_id=315449
#
#===============================================================================
use strict;
use warnings;
#use Data::Dumper; ###
use Getopt::Long;
use Pod::Usage;
use File::Temp qw(tempfile); #for output files
use Fcntl qw(:flock SEEK_END); #for log file
use Digest::MD5 qw(md5_hex); #for dereplication
use Cwd;
use List::Util qw(sum min max);
$| = 1; # Do not buffer output
my $WINDOWSIZE = 64;
my $WINDOWSTEP = 32;
my $WORDSIZE = 3;
my @WINDOWSIZEARRAY = (0..61);
my $LOG62 = log(62);
my $ONEOVERLOG62 = 1/log(62);
my $POINTFIVE = 1/2;
my $LINE_WIDTH = 60;
my $TRIM_QUAL_WINDOW = 1;
my $TRIM_QUAL_STEP = 1;
my $TRIM_QUAL_TYPE = 'min';
my $TRIM_QUAL_RULE = 'lt';
my $TAG_LENGTH = 20;
my %MIDS = (ACGAGTGCGT => 0,
ACGCTCGACA => 0,
AGACGCACTC => 0,
AGCACTGTAG => 0,
ATCAGACACG => 0,
ATATCGCGAG => 0,
CGTGTCTCTA => 0,
CTCGCGTGTC => 0,
TAGTATCAGC => 0,
TCTCTATGCG => 0,
TGATACGTCT => 0,
TACTGAGCTA => 0,
CATAGTAGTG => 0,
CGAGAGATAC => 0,
ACACGACGACT => 0,
ACACGTAGTAT => 0,
ACACTACTCGT => 0,
ACGACACGTAT => 0,
ACGAGTAGACT => 0,
ACGCGTCTAGT => 0,
ACGTACACACT => 0,
ACGTACTGTGT => 0,
ACGTAGATCGT => 0,
ACTACGTCTCT => 0,
ACTATACGAGT => 0,
ACTCGCGTCGT => 0);
my $MIDCHECKLENGTH = 15; #maximum MID length plus possible key length (by default 4 bp for 454)
my %DN_DI = ('AA' => 0, 'AC' => 0, 'AG' => 0, 'AT' => 0, 'CA' => 0, 'CC' => 0, 'CG' => 0, 'CT' => 0, 'GA' => 0, 'GC' => 0, 'GG' => 0, 'GT' => 0, 'TA' => 0, 'TC' => 0, 'TG' => 0, 'TT' => 0);
my %GRAPH_OPTIONS = map {$_ => 1} qw(ld gc qd ns pt ts aq de da sc dn);
my $VERSION = '0.20.3';
my $WHAT = 'lite';
my $man = 0;
my $help = 0;
my %params = ('help' => \$help, 'h' => \$help, 'man' => \$man);
GetOptions( \%params,
'help|h',
'man',
'verbose',
'version' => sub { print "PRINSEQ-$WHAT $VERSION\n"; exit; },
'fastq=s',
'fasta=s',
'fastq2=s',
'fasta2=s',
'qual=s',
'min_len=i',
'max_len=i',
'range_len=s',
'min_gc=i',
'max_gc=i',
'range_gc=s',
'min_qual_score=i',
'max_qual_score=i',
'min_qual_mean=i',
'max_qual_mean=i',
'ns_max_p=i',
'ns_max_n=i',
'noniupac',
'seq_num=i',
'derep=i',
'derep_min=i',
'lc_method=s',
'lc_threshold=i',
'trim_to_len=i',
'trim_left=i',
'trim_right=i',
'trim_left_p=i',
'trim_right_p=i',
'trim_tail_left=i',
'trim_tail_right=i',
'trim_ns_left=i',
'trim_ns_right=i',
'trim_qual_left=i',
'trim_qual_right=i',
'trim_qual_type=s',
'trim_qual_rule=s',
'trim_qual_window=i',
'trim_qual_step=i',
'seq_case=s',
'dna_rna=s',
'line_width=i',
'rm_header',
'seq_id=s',
'seq_id_mappings:s',
'out_format=i',
'out_good=s',
'out_bad=s',
'stats_len',
'stats_dinuc',
'stats_info',
'stats_tag',
'stats_dupl',
'stats_ns',
'stats_assembly',
'stats_all',
'aa',
'log:s',
'graph_data:s',
'graph_stats=s',
'phred64',
'qual_noscale',
'no_qual_header',
'exact_only',
'web:s',
'filename1=s',
'filename2=s',
'custom_params=s',
'params=s'
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
=head1 NAME
PRINSEQ - PReprocessing and INformation of SEQuence data
=head1 VERSION
PRINSEQ-lite 0.20.3
=head1 SYNOPSIS
perl prinseq-lite.pl [-h] [-help] [-version] [-man] [-verbose] [-fastq input_fastq_file] [-fasta input_fasta_file] [-fastq2 input_fastq_file_2] [-fasta2 input_fasta_file_2] [-qual input_quality_file] [-min_len int_value] [-max_len int_value] [-range_len ranges] [-min_gc int_value] [-max_gc int_value] [-range_gc ranges] [-min_qual_score int_value] [-max_qual_score int_value] [-min_qual_mean int_value] [-max_qual_mean int_value] [-ns_max_p int_value] [-ns_max_n int_value] [-noniupac] [-seq_num int_value] [-derep int_value] [-derep_min int_value] [-lc_method method_name] [-lc_threshold int_value] [-trim_to_len int_value] [-trim_left int_value] [-trim_right int_value] [-trim_left_p int_value] [-trim_right_p int_value] [-trim_ns_left int_value] [-trim_ns_right int_value] [-trim_tail_left int_value] [-trim_tail_right int_value] [-trim_qual_left int_value] [-trim_qual_right int_value] [-trim_qual_type type] [-trim_qual_rule rule] [-trim_qual_window int_value] [-trim_qual_step int_value] [-seq_case case] [-dna_rna type] [-line_width int_value] [-rm_header] [-seq_id id_string] [-out_format int_value] [-out_good filename_prefix] [-out_bad filename_prefix] [-phred64] [-stats_info] [-stats_len] [-stats_dinuc] [-stats_tag] [-stats_dupl] [-stats_ns] [-stats_assembly] [-stats_all] [-aa] [-graph_data file] [-graph_stats string] [-qual_noscale] [-no_qual_header] [-exact_only] [-log file] [-custom_params string] [-params file] [-seq_id_mappings file]
=head1 DESCRIPTION
PRINSEQ will help you to preprocess your genomic or metagenomic sequence data in FASTA (and QUAL) or FASTQ format. The lite version does not require any non-core perl modules for processing.
=head1 OPTIONS
=over 8
=item B<-help> | B<-h>
Print the help message; ignore other arguments.
=item B<-man>
Print the full documentation; ignore other arguments.
=item B<-version>
Print program version; ignore other arguments.
=item B<-verbose>
Prints status and info messages during processing.
=item B<***** INPUT OPTIONS *****>
=item B<-fastq> <file>
Input file in FASTQ format that contains the sequence and quality data. Use stdin instead of a file name to read from STDIN (-fasta stdin). This can be useful to process compressed files using Unix pipes.
=item B<-fasta> <file>
Input file in FASTA format that contains the sequence data. Use stdin instead of a file name to read from STDIN (-fastq stdin). This can be useful to process compressed files using Unix pipes.
=item B<-qual> <file>
Input file in QUAL format that contains the quality data.
=item B<-fastq2> <file>
For paired-end data only. Input file in FASTQ format that contains the sequence and quality data. The sequence identifiers for two matching paired-end sequences in separate files can be marked by /1 and /2, or _L and _R, or _left and _right, or must have the exact same identifier in both input files. The input sequences must be sorted by their sequence identifiers. Singletons are allowed in the input files.
=item B<-fasta2> <file>
For paired-end data only. Input file in FASTA format that contains the sequence data. The sequence identifiers for two matching paired-end sequences in separate files can be marked by /1 and /2, or _L and _R, or _left and _right, or must have the exact same identifier in both input files. The input sequences must be sorted by their sequence identifiers. Singletons are allowed in the input files.
=item B<-params> <file>
Input file in text format that contains PRINSEQ parameters. Each parameter should be specified on a new line and arguments should be separated by spaces or tabs. Comments can be specified on lines starting with the # sign. Can be combined with command line parameters. Parameters specified on the command line will overwrite the arguments in the file (if any).
=item B<-si13>
This option was replaced by option -phred64.
=item B<-phred64>
Quality data in FASTQ file is in Phred+64 format (http://en.wikipedia.org/wiki/FASTQ_format#Encoding). Not required for Illumina 1.8+, Sanger, Roche/454, Ion Torrent, PacBio data.
=item B<-aa>
Input is amino acid (protein) sequences instead of nucleic acid (DNA or RNA) sequences. Allowed amino acid characters: ABCDEFGHIKLMNOPQRSTUVWYZXabcdefghiklmmopqrstuvwyzx*- and allowed nucleic acid characters: ACGTURYKMSWBDHVNXacgturykmswbdhvnx-
The following options are ignored for -aa: stats_dinuc,stats_tag,stats_ns,dna_rna
=item B<***** OUTPUT OPTIONS *****>
=item B<-out_format> <integer>
To change the output format, use one of the following options. If not defined, the output format will be the same as the input format.
1 (FASTA only), 2 (FASTA and QUAL), 3 (FASTQ), 4 (FASTQ and FASTA), or 5 (FASTQ, FASTA and QUAL)
=item B<-out_good> <string>
By default, the output files are created in the same directory as the input file containing the sequence data with an additional "_prinseq_good_XXXX" in their name (where XXXX is replaced by random characters to prevent overwriting previous files). To change the output filename and location, specify the filename using this option. The file extension will be added automatically (either .fasta, .qual, or .fastq). For paired-end data, filenames contain additionally "_1", "_1_singletons", "_2", and "_2_singletons" before the file extension. Use "-out_good null" to prevent the program from generating the output file(s) for data passing all filters. Use "-out_good stdout" to write data passing all filters to STDOUT (only for FASTA or FASTQ output files).
Example: use "file_passed" to generate the output file file_passed.fasta in the current directory
=item B<-out_bad> <string>
By default, the output files are created in the same directory as the input file containing the sequence data with an additional "_prinseq_bad_XXXX" in their name (where XXXX is replaced by random characters to prevent overwriting previous files). To change the output filename and location, specify the filename using this option. The file extension will be added automatically (either .fasta, .qual, or .fastq). For paired-end data, filenames contain additionally "_1" and "_2" before the file extension. Use "-out_bad null" to prevent the program from generating the output file(s) for data not passing any filter. Use "-out_bad stdout" to write data not passing any filter to STDOUT (only for FASTA or FASTQ output files).
Example: use "file_filtered" to generate the output file file_filtered.fasta in the current directory
Example: "-out_good stdout -out_bad null" will write data passing filters to STDOUT and data not passing any filter will be ignored
=item B<-log> <file>
Log file to keep track of parameters, errors, etc. The log file name is optional. If no file name is given, the log file name will be "inputname.log". If the log file already exists, new content will be added to the file.
=item B<-graph_data> <file>
File that contains the necessary information to generate the graphs similar to the ones in the web version. The file name is optional. If no file name is given, the file name will be "inputname.gd". If the file already exists, new content will overwrite the file. Use "-out_good null -out_bad null" to prevent generating any additional outputs. (See below for more options related to the graph data.)
The graph data can be used as input for the prinseq-graphs.pl file to generate the PNG graph files or an HTML report file. If you have trouble installing the required prinseq-graphs.pl modules or want to see an output
example report, upload the graph data file at: http://edwards.sdsu.edu/prinseq/ -> Choose "Get Report"
=item B<-graph_stats> <string>
Use this option to select what statistics should be calculated and included in the graph_data file. This is useful if you e.g. do not need sequence complexity information, which requires a lot of computation. Requires to have graph_data specified. Default is all selected.
Allowed option are (separate multiple by comma with no spaces): ld (Length distribution), gc (GC content distribution), qd (Base quality distribution), ns (Occurence of N), pt (Poly-A/T tails), ts (Tag sequence check), aq (Assembly quality measure), de (Sequence duplication - exact only), da (Sequence duplication - exact + 5'/3'), sc (Sequence complexity), dn (Dinucleotide odds ratios, includes the PCA plots)
Example use: -graph_stats ld,gc,qd,de
=item B<-qual_noscale>
Use this option if all your sequences are shorter than 100bp as they do not require to scale quality data to 100 data points in the graph. By default, quality scores of sequences shorter than 100bp or longer than 100bp are fit to 100 data points. (To retrieve this information and calculate the graph data would otherwise require to parse the data two times or store all the quality data in memory.)
=item B<-no_qual_header>
In order to reduce the file size, this option will generate an empty header line for the quality data in FASTQ files. Instead of +header, only the + sign will be output. The header of the sequence data will be left unchanged. This option applies to FASTQ output files only.
=item B<-exact_only>
Use this option to check for exact (forward and reverse) duplicates only when generating the graph data. This allows to keep the memory requirements low for large input files and is faster. This option will automatically be applied when using -derep options 1 and/or 4 only. Specify option -derep 1 or -derep 4 if you do not want to apply both at the same time.
=item B<-seq_id_mappings> <file>
Text file containing the old and new (specified with -seq_id) identifiers for later reference. This option is useful if e.g. a renamed sequence has to be identified based on the new sequence identifier. The file name is optional. If no file name is given, the file name will be "inputname_prinseq_good.ids" (only good sequences are renamed). If a file with the same name already exists, new content will overwrite the old file. The text file contains one sequence identifier pair per line, separated by tabs (old-tab-new). Requires option -seq_id.
=item B<***** FILTER OPTIONS *****>
=item B<-min_len> <integer>
Filter sequence shorter than min_len.
=item B<-max_len> <integer>
Filter sequence longer than max_len.
=item B<-range_len> <string>
Filter sequence by length range. Multiple range values should be separated by comma without spaces.
Example: -range_len 50-100,250-300
=item B<-min_gc> <integer>
Filter sequence with GC content below min_gc.
=item B<-max_gc> <integer>
Filter sequence with GC content above max_gc.
=item B<-range_gc> <string>
Filter sequence by GC content range. Multiple range values should be separated by comma without spaces.
Example: -range_gc 50-60,75-90
=item B<-min_qual_score> <integer>
Filter sequence with at least one quality score below min_qual_score.
=item B<-max_qual_score> <integer>
Filter sequence with at least one quality score above max_qual_score.
=item B<-min_qual_mean> <integer>
Filter sequence with quality score mean below min_qual_mean.
=item B<-max_qual_mean> <integer>
Filter sequence with quality score mean above max_qual_mean.
=item B<-ns_max_p> <integer>
Filter sequence with more than ns_max_p percentage of Ns.
=item B<-ns_max_n> <integer>
Filter sequence with more than ns_max_n Ns.
=item B<-noniupac>
Filter sequence with characters other than A, C, G, T or N.
=item B<-seq_num> <integer>
Only keep the first seq_num number of sequences (that pass all other filters).
=item B<-derep> <integer>
Type of duplicates to filter. Allowed values are 1, 2, 3, 4 and 5. Use integers for multiple selections (e.g. 124 to use type 1, 2 and 4). The order does not matter. Option 2 and 3 will set 1 and option 5 will set 4 as these are subsets of the other option.
1 (exact duplicate), 2 (5' duplicate), 3 (3' duplicate), 4 (reverse complement exact duplicate), 5 (reverse complement 5'/3' duplicate)
=item B<-derep_min> <integer>
This option specifies the number of allowed duplicates. If you want to remove sequence duplicates that occur more than x times, then you would specify x+1 as the -derep_min values. For examples, to remove sequences that occur more than 5 times, you would specify -derep_min 6. This option can only be used in combination with -derep 1 and/or 4 (forward and/or reverse exact duplicates). [default : 2]
=item B<-lc_method> <string>
Method to filter low complexity sequences. The current options are "dust" and "entropy". Use "-lc_method dust" to calculate the complexity using the dust method.
=item B<-lc_threshold> <integer>
The threshold value (between 0 and 100) used to filter sequences by sequence complexity. The dust method uses this as maximum allowed score and the entropy method as minimum allowed value.
=item B<-custom_params> <string>
Can be used to specify additional filters. The current set of possible rules is limited and has to follow the specifications below. The custom parameters have to be specified within quotes (either ' or ").
Please separate parameter values with a space and separate new parameter sets with semicolon (;). Parameters are defined by two values:
(1) the pattern (any combination of the letters "ACGTN"),
(2) the number of repeats or percentage of occurence
Percentage values are defined by a number followed by the %-sign (without space).
If no %-sign is given, it is assumed that the given number specifies the number of repeats of the pattern.
Examples: "AAT 10" (filters out sequences containing AATAATAATAATAATAATAATAATAATAAT anywhere in the sequence), "T 70%" (filters out sequences with more than 70% Ts in the sequence), "A 15" (filters out sequences containing AAAAAAAAAAAAAAA anywhere in the sequence), "AAT 10;T 70%;A 15" (apply all three filters)
=item B<***** TRIM OPTIONS *****>
=item B<-trim_to_len> <integer>
Trim all sequence from the 3'-end to result in sequence with this length.
=item B<-trim_left> <integer>
Trim sequence at the 5'-end by trim_left positions.
=item B<-trim_right> <integer>
Trim sequence at the 3'-end by trim_right positions.
=item B<-trim_left_p> <integer>
Trim sequence at the 5'-end by trim_left_p percentage of read length. The trim length is rounded towards the lower integer (e.g. 143.6 is rounded to 143 positions). Use an integer between 1 and 100 for the percentage value.
=item B<-trim_right_p> <integer>
Trim sequence at the 3'-end by trim_right_p percentage of read length. The trim length is rounded towards the lower integer (e.g. 143.6 is rounded to 143 positions). Use an integer between 1 and 100 for the percentage value.
=item B<-trim_tail_left> <integer>
Trim poly-A/T tail with a minimum length of trim_tail_left at the 5'-end.
=item B<-trim_tail_right> <integer>
Trim poly-A/T tail with a minimum length of trim_tail_right at the 3'-end.
=item B<-trim_ns_left> <integer>
Trim poly-N tail with a minimum length of trim_ns_left at the 5'-end.
=item B<-trim_ns_right> <integer>
Trim poly-N tail with a minimum length of trim_ns_right at the 3'-end.
=item B<-trim_qual_left> <integer>
Trim sequence by quality score from the 5'-end with this threshold score.
=item B<-trim_qual_right> <integer>
Trim sequence by quality score from the 3'-end with this threshold score.
=item B<-trim_qual_type> <string>
Type of quality score calculation to use. Allowed options are min, mean, max and sum. [default: min]
=item B<-trim_qual_rule> <string>
Rule to use to compare quality score to calculated value. Allowed options are lt (less than), gt (greater than) and et (equal to). [default: lt]
=item B<-trim_qual_window> <integer>
The sliding window size used to calculate quality score by type. To stop at the first base that fails the rule defined, use a window size of 1. [default: 1]
=item B<-trim_qual_step> <integer>
Step size used to move the sliding window. To move the window over all quality scores without missing any, the step size should be less or equal to the window size. [default: 1]
=item B<***** REFORMAT OPTIONS *****>
=item B<-seq_case> <string>
Changes sequence character case to upper or lower case. Allowed options are "upper" and "lower". Use this option to remove soft-masking from your sequences.
=item B<-dna_rna> <string>
Convert sequence between DNA and RNA. Allowed options are "dna" (convert from RNA to DNA) and "rna" (convert from DNA to RNA).
=item B<-line_width> <integer>
Sequence characters per line. Use 0 if you want each sequence in a single line. Use 80 for line breaks every 80 characters. Note that this option only applies to FASTA output files, since FASTQ files store sequences without additional line breaks. [default: 60]
=item B<-rm_header>
Remove the sequence header. This includes everything after the sequence identifier (which is kept unchanged).
=item B<-seq_id> <string>
Rename the sequence identifier. A counter is added to each identifier to assure its uniqueness. Use option -seq_id_mappings to generate a file containing the old and new identifiers for later reference.
Example: "mySeq_10" will generate the IDs (in FASTA format) >mySeq_101, >mySeq_102, >mySeq_103, ...
=item B<***** SUMMARY STATISTIC OPTIONS *****>
The summary statistic values are written to STDOUT in the form: "parameter_name statistic_name value" (without the quotes). For example, "stats_info reads 10000" or "stats_len max 500". Only one statistic is written per line and values are separated by tabs.
If you specify any statistic option, no other ouput will be generated. To preprocess data, do not specify a statistics option.
=item B<-stats_info>
Outputs basic information such as number of reads (reads) and total bases (bases).
=item B<-stats_len>
Outputs minimum (min), maximum (max), range (range), mean (mean), standard deviation (stddev), mode (mode) and mode value (modeval), and median (median) for read length.
=item B<-stats_dinuc>
Outputs the dinucleotide odds ratio for AA/TT (aatt), AC/GT (acgt), AG/CT (agct), AT (at), CA/TG (catg), CC/GG (ccgg), CG (cg), GA/TC (gatc), GC (gc) and TA (ta).
=item B<-stats_tag>
Outputs the probability of a tag sequence at the 5'-end (prob5) and 3'-end (prob3) in percentage (0..100). Provides the number of predefined MIDs (midnum) and the MID sequences (midseq, separated by comma, only provided if midnum > 0) that occur in more than 34/100 (approx. 3%) of the reads.
=item B<-stats_dupl>
Outputs the number of exact duplicates (exact), 5' duplicates (5), 3' duplicates (3), exact duplicates with reverse complements (exactrevcom) and 5'/3' duplicates with reverse complements (revcomp), and total number of duplicates (total). The maximum number of duplicates is given under the value name with an additional "maxd" (e.g. exactmaxd or 5maxd).
=item B<-stats_ns>
Outputs the number of reads with ambiguous base N (seqswithn), the maximum number of Ns per read (maxn) and the maximum percentage of Ns per read (maxp). The maxn and maxp value are not necessary from the same sequence.
=item B<-stats_assembly>
Outputs the N50, N90, etc contig sizes. The Nxx contig size is a weighted median that is defined as the length of the smallest contig C in the sorted list of all contigs where the cumulative length from the largest contig to contig C is at least xx% of the total length (sum of contig lengths).
=item B<-stats_all>
Outputs all available summary statistics.
=item B<***** ORDER OF PROCESSING *****>
The available options are processed in the following order:
seq_num, trim_left, trim_right, trim_left_p, trim_right_p, trim_qual_left, trim_qual_right, trim_tail_left, trim_tail_right, trim_ns_left, trim_ns_right, trim_to_len, min_len, max_len, range_len, min_qual_score, max_qual_score, min_qual_mean, max_qual_mean, min_gc, max_gc, range_gc, ns_max_p, ns_max_n, noniupac, lc_method, derep, seq_id, seq_case, dna_rna, out_format
=back
=head1 AUTHOR
Robert SCHMIEDER, C<< <rschmieder_at_gmail_dot_com> >>
=head1 BUGS
If you find a bug please email me at C<< <rschmieder_at_gmail_dot_com> >> or use http://sourceforge.net/tracker/?group_id=315449 so that I can make PRINSEQ better.
=head1 COPYRIGHT
Copyright (C) 2010-2012 Robert SCHMIEDER
=head1 LICENSE
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
=cut
#
################################################################################
## DATA AND PARAMETER CHECKING
################################################################################
#
my ($file1,$file2,$command,@dataread,$aa,%filtercount,$slashnum,$trimnum1,$trimnum2);
#check if params file
if(exists $params{params}) {
my $ps = &readParamsFile($params{params});
foreach my $p (keys %$ps) {
next if(exists $params{$p});
$params{$p} = $ps->{$p};
}
}
#check if amino acid or nucleic acid input
if(exists $params{aa}) {
$aa = 1;
$command .= ' -aa';
} else {
$aa = 0;
}
#Check if input file exists and check if file format is correct
if(exists $params{fasta} && exists $params{fastq}) {
&printError('fasta and fastq cannot be used together');
} elsif(exists $params{fasta}) {
$command .= ' -fasta '.$params{fasta};
$file1 = $params{fasta};
if($params{fasta} eq 'stdin') {
if(exists $params{qual} && $params{qual} eq 'stdin') {
&printError('input from STDIN is only allowed for either of the input files');
} else {
my $format = &checkInputFormat();
unless($format eq 'fasta') {
&printError('input data for -fasta is in '.uc($format).' format not in FASTA format');
}
}
} elsif(-e $params{fasta}) {
#check for file format
my $format = &checkFileFormat($file1);
unless($format eq 'fasta') {
&printError('input file for -fasta is in '.uc($format).' format not in FASTA format');
}
} else {
&printError("could not find input file \"".$params{fasta}."\"");
}
} elsif(exists $params{fastq}) {
$command .= ' -fastq '.$params{fastq};
$file1 = $params{fastq};
if($params{fastq} eq 'stdin') {
my $format = &checkInputFormat();
unless($format eq 'fastq') {
&printError('input data for -fastq is in '.uc($format).' format not in FASTQ format');
}
} elsif(-e $params{fastq}) {
#check for file format
my $format = &checkFileFormat($file1);
unless($format eq 'fastq') {
&printError('input file for -fastq is in '.uc($format).' format not in FASTQ format');
}
} else {
&printError("could not find input file \"".$params{fastq}."\"");
}
} else {
&printError("you did not specify an input file containing the query sequences");
}
if(exists $params{fastq} && exists $params{qual}) {
&printError('fastq and qual cannot be used together');
} elsif(exists $params{qual}) {
$command .= ' -qual '.$params{qual};
if($params{qual} eq 'stdin') {
&printError('QUAL data cannot be read from STDIN');
} elsif(-e $params{qual}) {
#check for file format
my $format = &checkFileFormat($params{qual});
unless($format eq 'qual') {
&printError('input file for -qual is in '.uc($format).' format not in QUAL format');
}
} else {
&printError("could not find input file \"".$params{qual}."\"");
}
}
if(exists $params{fasta2} && exists $params{fastq2}) {
&printError('fasta2 and fastq2 cannot be used together');
} elsif(exists $params{fasta2}) {
if(!exists $params{fasta}) {
&printError('option fasta2 requires option fasta');
} elsif($params{fasta} eq $params{fasta2}) {
&printError('option fasta and fasta2 cannot be the same input file');
} else {
$command .= ' -fasta2 '.$params{fasta2};
$file2 = $params{fasta2};
if($params{fasta} eq 'stdin' || $params{fasta2} eq 'stdin') {
&printError('paired-end data cannot be processed from STDIN');
} elsif(-e $params{fasta2}) {
#check for file format
my $format = &checkFileFormat($file2);
unless($format eq 'fasta') {
&printError('input file for -fasta2 is in '.uc($format).' format not in FASTA format');
}
} else {
&printError("could not find input file \"".$params{fasta2}."\"");
}
}
($slashnum,$trimnum1,$trimnum2) = &checkSlashnum($file2);
} elsif(exists $params{fastq2}) {
if(!exists $params{fastq}) {
&printError('option fastq2 requires option fastq');
} elsif($params{fastq} eq $params{fastq2}) {
&printError('option fastq and fastq2 cannot be the same input file');
} else {
$command .= ' -fastq2 '.$params{fastq2};
$file2 = $params{fastq2};
if($params{fastq} eq 'stdin' || $params{fastq2} eq 'stdin') {
&printError('paired-end data cannot be processed from STDIN');
} elsif(-e $params{fastq2}) {
#check for file format
my $format = &checkFileFormat($file2);
unless($format eq 'fastq') {
&printError('input file for -fastq2 is in '.uc($format).' format not in FASTQ format');
}
} else {
&printError("could not find input file \"".$params{fastq2}."\"");
}
}
($slashnum,$trimnum1,$trimnum2) = &checkSlashnum($file2);
}
#check if stats_all
if(exists $params{stats_all}) {
$params{stats_info} = 1;
$params{stats_len} = 1;
$params{stats_dupl} = 1 unless($file2);
$params{stats_dinuc} = 1;
$params{stats_tag} = 1;
$params{stats_ns} = 1;
$params{stats_assembly} = 1;
delete($params{stats_all});
}
if($aa) {
delete($params{stats_dinuc});
delete($params{stats_tag});
delete($params{stats_ns});
}
if($file2) {
delete($params{stats_dupl});
delete($params{stats_assembly});
}
#check if anything todo
unless( exists $params{min_len} ||
exists $params{max_len} ||
exists $params{range_len} ||
exists $params{min_gc} ||
exists $params{max_gc} ||
exists $params{range_gc} ||
exists $params{min_qual_score} ||
exists $params{max_qual_score} ||
exists $params{min_qual_mean} ||
exists $params{max_qual_mean} ||
exists $params{ns_max_p} ||
exists $params{ns_max_n} ||
exists $params{noniupac} ||
exists $params{seq_num} ||
exists $params{derep} ||
exists $params{lc_method} ||
exists $params{lc_threshold} ||
exists $params{trim_to_len} ||
exists $params{trim_left} ||
exists $params{trim_right} ||
exists $params{trim_left_p} ||
exists $params{trim_right_p} ||
exists $params{trim_tail_left} ||
exists $params{trim_tail_right} ||
exists $params{trim_ns_left} ||
exists $params{trim_ns_right} ||
exists $params{trim_qual_left} ||
exists $params{trim_qual_right} ||
exists $params{trim_qual_type} ||
exists $params{trim_qual_rule} ||
exists $params{trim_qual_window} ||
exists $params{trim_qual_step} ||
exists $params{seq_case} ||
exists $params{dna_rna} ||
exists $params{exact_only} ||
exists $params{line_width} ||
exists $params{rm_header} ||
exists $params{seq_id} ||
exists $params{out_format} ||
exists $params{stats_info} ||
exists $params{stats_len} ||
exists $params{stats_dinuc} ||
exists $params{stats_tag} ||
exists $params{stats_dupl} ||
exists $params{stats_ns} ||
exists $params{stats_assembly} ||
exists $params{phred64} ||
exists $params{no_qual_header} ||
exists $params{graph_data} ||
exists $params{custom_params}
) {
&printError('nothing to do with input data');
}
#prevent out of files for stats
if(exists $params{stats_info} || exists $params{stats_len} || exists $params{stats_dinuc} || exists $params{stats_tag} || exists $params{stats_dupl} || exists $params{stats_ns} || exists $params{stats_assembly}) {
$params{out_good} = 'null';
$params{out_bad} = 'null';
$params{stats} = 1;
} elsif(exists $params{out_good} && $params{out_good} eq 'null' && exists $params{out_bad} && $params{out_bad} eq 'null' && !exists $params{graph_data}) {
&printError('no output selected (both set to null)');
}
#check if FASTQ file is given for option phred64
if(exists $params{phred64}) {
$command .= ' -phred64';
unless(exists $params{fastq}) {
&printError('option -phred64 can only be used for FASTQ input files');
}
}
#check if output format is possible
if(exists $params{out_format}) {
$command .= ' -out_format '.$params{out_format};
if($params{out_format} =~ /\D/) {
&printError('output format option has to be an integer value');
} elsif($params{out_format} == 2 || $params{out_format} == 3 || $params{out_format} == 4 || $params{out_format} == 5) {
unless(exists $params{fastq} || exists $params{qual}) {
&printError('cannot use this output format option without providing quality data as input');
}
if(exists $params{fastq2} && ($params{out_format} == 2 || $params{out_format} == 4 || $params{out_format} == 5)) {
&printError('cannot use this output format option for paired-end input data. Only values 1 and 3 are allowed');
}
} elsif($params{out_format} != 1) {
&printError('output format option not available');
}
} else {
if(exists $params{fastq}) {
$params{out_format} = 3;
} elsif(exists $params{fasta} && exists $params{qual}) {
$params{out_format} = 2;
} else {
$params{out_format} = 1;
}
}
if(exists $params{no_qual_header} && $params{out_format} != 3) {
&printError('the option -no_qual_header can only be used for FASTQ outputs');
}
#check if output names are different
if(exists $params{out_good} && exists $params{out_bad} && $params{out_good} eq $params{out_bad} && $params{out_good} ne 'null' && $params{out_good} ne 'stdout') {
&printError('the output names for -out_good and -out_bad have to be different');
}
#check if output can be written to standard output
if(($params{out_format} == 2 || $params{out_format} == 4 || $params{out_format} == 5) && ((exists $params{out_good} && $params{out_good} eq 'stdout') || (exists $params{out_bad} && $params{out_bad} eq 'stdout'))) {
&printError('the output cannot be written to STDOUT for multiple output files. This option can only be used for FASTA only (-out_format 1) or FASTQ output (-out_format 3)');
}
#check dereplication option
#1 - exact dub, 2 - prefix, 3 - suffix, 4 - revcomp exact, 5 - revcomp prefix/suffix
my $derep = 0;
my %dereptypes;
my $derepmin = 2;
if(exists $params{derep}) {
$command .= ' -derep '.$params{derep};
if($params{derep} < 0 || $params{derep} > 54321) {
&printError('invalid option for dereplication');
} else {
my @tmp = split('',$params{derep});
foreach(@tmp) {
if($_ < 1 || $_ > 5) {
&printError('invalid option '.$_.'for dereplication');
} else {
$derep = 1;
$dereptypes{($_-1)} = 0;
}
}
}
}
if(!exists $dereptypes{0} && (exists $dereptypes{1} || exists $dereptypes{2})) {
$dereptypes{0} = 0;
}
if(!exists $dereptypes{3} && exists $dereptypes{4}) {
$dereptypes{3} = 0;
}
my $exactonly = 0;
if(exists $params{exact_only}) {
$command .= ' -exact_only';
if(exists $dereptypes{1} || exists $dereptypes{2} || exists $dereptypes{4}) {
&printError('option -exact_only can only be used with -derep options 1 and/or 4');
}
if(!exists $params{graph_data}) {
&printError('option -exact_only requires option -graph_data');
}
if(!exists $params{derep}) {
$dereptypes{0} = 1;
$dereptypes{3} = 1;
}
$exactonly = 1;
} elsif((exists $dereptypes{0} || exists $dereptypes{3}) && !exists $dereptypes{1} && !exists $dereptypes{2} && !exists $dereptypes{4}) {
$command .= ' -exact_only';
$exactonly = 1;
$params{exact_only} = 1;
}
if(exists $params{derep_min}) {
$command .= ' -derep_min '.$params{derep_min};
if($params{derep_min} < 2) {
&printError('invalid option '.$params{derep_min}.'for derep_min. The values has to be greater than 1');
} elsif(exists $dereptypes{1} || exists $dereptypes{2} || exists $dereptypes{4}) {
&printError('option -derep_min can only be used with -derep options 1 and/or 4');
} else {
$derepmin = $params{derep_min};
}
}
#check for low complexity method
my $complval;
if(exists $params{lc_method}) {
$command .= ' -lc_method '.$params{lc_method};
unless($params{lc_method} eq 'dust' || $params{lc_method} eq 'entropy') {
&printError('invalid low complexity method');
}
unless(exists $params{lc_threshold}) {
&printError('the low complexity method requires a threshold value specified by -lc_threshold');
}
$command .= ' -lc_threshold '.$params{lc_threshold};
$complval = $params{lc_threshold};
}
if(exists $params{lc_threshold} && !exists $params{lc_method}) {
&printError('the low complexity threshold requires a method specified by -lc_method');
}
#check for quality trimming
my $trimscore;
if(exists $params{trim_qual_left} || exists $params{trim_qual_right}) {
$command .= ' -trim_qual_right '.$params{trim_qual_right} if(exists $params{trim_qual_right});
$command .= ' -trim_qual_left '.$params{trim_qual_left} if(exists $params{trim_qual_left});
if(exists $params{trim_qual_type}) {
unless($params{trim_qual_type} eq 'min' || $params{trim_qual_type} eq 'mean' || $params{trim_qual_type} eq 'max' || $params{trim_qual_type} eq 'sum') {
&printError('invalid value for trim_qual_type');
}
} else {
$params{trim_qual_type} = $TRIM_QUAL_TYPE;
}
$command .= ' -trim_qual_type '.$params{trim_qual_type};
if(exists $params{trim_qual_rule}) {
unless($params{trim_qual_rule} eq 'lt' || $params{trim_qual_rule} eq 'gt' || $params{trim_qual_rule} eq 'et') {
&printError('invalid value for trim_qual_rule');
}
} else {
$params{trim_qual_rule} = $TRIM_QUAL_RULE;
}
$command .= ' -trim_qual_rule '.$params{trim_qual_rule};
unless(exists $params{trim_qual_window}) {
$params{trim_qual_window} = $TRIM_QUAL_WINDOW;
}
$command .= ' -trim_qual_window '.$params{trim_qual_window};
unless(exists $params{trim_qual_step}) {
$params{trim_qual_step} = $TRIM_QUAL_STEP;
}
$command .= ' -trim_qual_step '.$params{trim_qual_step};
$trimscore = 1;
}
#check sequence case
if(exists $params{seq_case}) {
$command .= ' -seq_case '.$params{seq_case};
unless($params{seq_case} eq 'upper' || $params{seq_case} eq 'lower') {
&printError('invalid sequence case option');
}
}
#check for dna/rna
if(exists $params{dna_rna}) {
$command .= ' -dna_rna '.$params{dna_rna};
unless($params{dna_rna} eq 'dna' || $params{dna_rna} eq 'rna') {
&printError('invalid option for -dna_rna');
}
if($aa) {
&printError('option -dna_rna cannot be used with option -aa');
}
}
#set remaining parameters
my $linelen;
if($params{out_format} == 3) {
$linelen = 0;
} elsif(exists $params{line_width}) {
$linelen = $params{line_width};
$command .= ' -line_width '.$params{line_width};
} else {
$linelen = $LINE_WIDTH;
}
if(exists $params{seq_id}) {
$command .= ' -seq_id '.$params{seq_id};
#remove spaces, ">" and quotes from sequence ids
$params{seq_id} =~ s/[\s\>\"\'\`]//g;
} elsif(exists $params{seq_id_mappings}) {
&printError('option -seq_id_mappings requires option -seq_id');
}
if(exists $params{seq_id_mappings}) {
$command .= ' -seq_id_mappings'.($params{seq_id_mappings} ? ' '.$params{seq_id_mappings} : '');
}
my ($repAleft,$repTleft,$repAright,$repTright,$repNleft,$repNright);
if(exists $params{trim_tail_left}) {
$command .= ' -trim_tail_left '.$params{trim_tail_left};
$repAleft = 'A'x$params{trim_tail_left};
$repAleft = qr/^$repAleft/;
$repTleft = 'T'x$params{trim_tail_left};
$repTleft = qr/^$repTleft/;
}
if(exists $params{trim_tail_right}) {
$command .= ' -trim_tail_right '.$params{trim_tail_right};
$repAright = 'A'x$params{trim_tail_right};
$repAright = qr/$repAright$/;
$repTright = 'T'x$params{trim_tail_right};
$repTright = qr/$repTright$/;
}
if(exists $params{trim_ns_left}) {
$command .= ' -trim_ns_left '.$params{trim_ns_left};
$repNleft = 'N'x$params{trim_ns_left};
$repNleft = qr/^$repNleft/;
}
if(exists $params{trim_ns_right}) {
$command .= ' -trim_ns_right '.$params{trim_ns_right};
$repNright = 'N'x$params{trim_ns_right};
$repNright = qr/$repNright$/;
}
#graph data file
if(exists $params{graph_data}) {
if(exists $params{stats}) {
&printError("The graph data cannot be generated at the same time as the statistics");
}
$command .= ' -graph_data'.($params{graph_data} ? ' '.$params{graph_data} : '');
unless($params{graph_data}) {
$params{graph_data} = join("__",$file1||'nonamegiven').'.gd';
}
$params{graph_data} = cwd().'/'.$params{graph_data} unless($params{graph_data} =~ /^\//);
}
my $scale = 1;
if(exists $params{qual_noscale}) {
$command .= ' -qual_noscale';
$scale = 0;
}
#graph data selection
if(exists $params{graph_stats} && !exists $params{graph_data}) {
&printError('option -graph_stats requires option -graph_data');
}
my %webstats = %GRAPH_OPTIONS;
my %graphstats = %GRAPH_OPTIONS;
if(exists $params{graph_stats}) {
$command .= ' -graph_stats'.($params{graph_stats} ? ' '.$params{graph_stats} : '');
if($params{graph_stats}) {