new file: cell2loc.py
[GalaxyCodeBases.git] / perl / etc / justonce / toPCR.pl
blobc7cb386cfeb95da9d3e1bc85dade13ffe183077d
1 #!/usr/bin/env perl
2 =pod
3 Author: Hu Xuesong @ BGI <huxuesong@genomics.org.cn>
4 Version: 1.0.0 @ 20170612
5 =cut
6 use strict;
7 use warnings;
8 use Galaxy::IO;
9 use Galaxy::IO::FASTA qw(FastaReadNextA);
11 open O,'>','toPCR.p3' or die "Error opening [toPCR.p3]: $!\n";
12 print O <<'HEAD';
13 PRIMER_MIN_SIZE=19
14 PRIMER_MAX_SIZE=25
15 PRIMER_THERMODYNAMIC_PARAMETERS_PATH=/usr/local/opt/primer3/share/primer3/primer3_config/
16 PRIMER_PRODUCT_SIZE_RANGE=30-401
17 PRIMER_NUM_RETURN=1
19 HEAD
21 my $in = openfile('toPCR.fa.gz');
22 while (my $ret = FastaReadNextA($in)) {
23 my ($seqname,$genome,$seqdesc) = @$ret;
24 #print $seqname," | $seqdesc\n";
25 $seqdesc = (split / /,$seqdesc)[0];
26 $seqdesc = (split /:/,$seqdesc)[1];
27 my ($begin,$end) = split /-/,$seqdesc;
28 my $thePos = (split /_/,$seqname)[-1];
29 $begin -= $thePos;
30 $end -= $thePos;
31 my $seqlen = length $genome;
32 if( $begin > -20 or $end < 20 or $seqlen < 55) {
33 print "\n>$seqname $thePos-($begin,$end)->Skipped.\n";
34 next;
35 } else {
36 print '.';
38 #print "$thePos, $begin,$end\n";
39 # Position starts from 0.
40 my $targetPos = - $begin;
41 my $left = -55 - $begin;
42 $left = 0 if $begin < 0;
43 my $right = 20 - $begin;
44 my $maxL = $seqlen - $right;
45 $maxL = 55 if $maxL > 55;
46 #$end = $seqlen -1 if $end >= $seqlen;
47 print O <<" ITEM";
48 SEQUENCE_ID=$seqname
49 SEQUENCE_TEMPLATE=$genome
50 SEQUENCE_TARGET=$targetPos,1
51 SEQUENCE_INTERNAL_EXCLUDED_REGION=$targetPos,1
52 SEQUENCE_PRIMER_PAIR_OK_REGION_LIST=$left,55,, ; ,,$right,$maxL
54 ITEM
56 print "\n";
57 close $in;
58 close O;
59 print "Run [primer3_core < toPCR.p3 > toPCR.out] now.\n";
60 __END__
61 primer3_core -format_output < toPCR.p3.test
62 primer3_core < toPCR.p3.test