Mercurial > repos > vipints > qseq2fastq
annotate qseq2fastq/qseq2fastq.pl @ 0:6682236a1432 default tip
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
author | vipints |
---|---|
date | Tue, 07 Jun 2011 17:42:46 -0400 |
parents | |
children |
rev | line source |
---|---|
0
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
1 #!/usr/bin/perl -w |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
2 use strict; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
3 use Carp; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
4 |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
5 my $usage = q( |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
6 qseq2fastq.pl - a script to convert all qseq files in a directory into a single fastq file with sanger-style ASCII q-score encoding |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
7 USAGE: qseq2fastq.pl <qseq.txt file> <output file> |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
8 ); |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
9 |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
10 if (scalar(@ARGV) != 2) { |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
11 print $usage; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
12 exit; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
13 } |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
14 |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
15 my $in_file = $ARGV[0]; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
16 my $output_fastq_file = $ARGV[1]; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
17 |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
18 my $qfilter = ""; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
19 open(OUTFASTAQFILE, "> $output_fastq_file"); |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
20 |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
21 open INFILE, "< $in_file" || die "Error: Couldn't open $in_file\n"; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
22 while(<INFILE>) |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
23 { |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
24 chomp; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
25 my @this_line = split/\t/, $_; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
26 croak("Error: invalid column number in $in_file\n") unless(scalar(@this_line) == 11); |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
27 if($this_line[10] == 1) { |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
28 $qfilter = "Y"; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
29 } else { |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
30 $qfilter = "N"; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
31 } |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
32 # Convert quality scores |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
33 my @quality_array = split(//, $this_line[9]); |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
34 my $phred_quality_string = ""; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
35 # convert each char to Phred quality score |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
36 foreach my $this_char (@quality_array){ |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
37 my $phred_quality = ord($this_char) - 64; # convert illumina scaled phred char to phred quality score |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
38 my $phred_char = chr($phred_quality + 33); # convert phred quality score into phred char (sanger style) |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
39 $phred_quality_string = $phred_quality_string . $phred_char; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
40 } |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
41 # replace "." gaps with N |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
42 $this_line[8] =~ s/\./N/g; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
43 # output line |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
44 print OUTFASTAQFILE "@" . $this_line[2] . ":" . $this_line[3] . ":" . $this_line[4] . ":" . $this_line[5] . ":" . $qfilter . "\n" . #header line |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
45 $this_line[8] . "\n" . # output sequence |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
46 "+" . $this_line[2] . ":" . $this_line[3] . ":" . $this_line[4] . ":" . $this_line[5] . ":" . $qfilter . "\n" . # header line |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
47 $phred_quality_string . "\n"; # output quality string |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
48 } |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
49 close INFILE; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
50 close OUTFASTAQFILE; |
6682236a1432
Migrated tool version 0.2 from old tool shed archive to new tool shed repository
vipints
parents:
diff
changeset
|
51 exit; |