-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFindPattern.pl
More file actions
220 lines (196 loc) · 6.63 KB
/
Copy pathFindPattern.pl
File metadata and controls
220 lines (196 loc) · 6.63 KB
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
#!/usr/bin/perl
#AUTHORS
# Kaining Hu (c) 2018
# Find Pattern (EAHelitron)v1.0000 2018/07/26
# hukaining@gmail.com
use strict;
use warnings;
use 5.010;
use Getopt::Long;
use Pod::Usage;
use Time::HiRes 'time';
#use Parallel::ForkManager;
#our $MAX_processes=2;
#my $pm=Parallel::ForkManager->new($MAX_processes);
use re 'eval';
our $opfn="";
my $verbose;
our $upstreml=3000;
our $downstreml=1100;
#our $seqfilename ='';
#GetOptions("i=s"=>\$seqfilename,"o=s" => \$opfn,"verbose"=>\$verbose)
#or die("Error in command line arguments\n perl Searchhelitron -o <outputfile> (inputfile)\n");
GetOptions("o=s" => \$opfn,"verbose"=>\$verbose,"u=i"=>\$upstreml,"d=i"=>\$downstreml)
or die("Error in command line arguments\nUsage: perl FindPattern [-o outfileprefix][-u|upstremlength int][-d|downstremlength int] <inputFASTA>\n");
###################sub TRseq##########
sub TRseq($)
{
my ($pinseq) = @_;
#say $pinseq;
my $pinseqtr = reverse $pinseq;
#say $pinseqtr;
$pinseqtr =~ tr/ACGTacgt/TGCAtgca/;
#say $pinseqtr;
return $pinseqtr;
}
##################TRseq End#############
our $loadingstarttime=time();
print "Start loading genomeic sequence.\n";
#if(!open SEQFILENAME,"< $seqfilename"){
# die "File not Found\n";
#}
#if(!open SEQFILENAME,"< $_"){
# die "File not Found\n";
#}
our $Chri=0;
our @Chrname=();
our @Chrseq=();
#@ARGV = qw#'' Not_Find_a_File#;
#say @ARGV;
#say $0;
while(defined(our $seq = <>)){
#while(our $seq = <SEQFILENAME>){
if ($seq =~ m/^.*>/) {
$seq=~ m/^.*>([a-zA-Z0-9_.-]+) ?.*/;
print "$1\n";
$Chrname[$Chri]= $1;
$Chri++;
}else{
$seq =~ s/\s//;
$seq =~ tr/MRWSYKVHDBmrwsykvhdb/CGTGCGGCGGCGTGCGGCGG/;#1.31add snp replace
$Chrseq[$Chri-1] .=$seq;
}
}
#close SEQFILENAME;
our $loadingendtime=time();
print "$Chri Sequences\n";
print "Finished loading!\n";
printf "%g Sec %g Min\n",$loadingendtime-$loadingstarttime,($loadingendtime-$loadingstarttime)/60;
if ($opfn eq ""){
$opfn="EAHeli_out";
print "Output files:$opfn.fas $opfn.gff3\n";
}else{
print "Output files:$opfn.fas $opfn.gff3\n";
}
our $starttime=time();
our $hairpinpattern="cccgccc";
say our $testseq='((GA){4,20})';
#say our $TCseq='([atgcn]{5}(TC(TCTACTA|T.TACTA.T|T.TACTAC|.{2}TACTACT|T.TAC.ACT|T.TA.TACT|T.TACT.CT|T.T.CTACT|.CTACTA.T|.{9}TATTAAG))[atgcn]{20})';
print "Running. Please wait for a minite.\n";
#####################################
#Start main
#####################################
open RSUT,"> $opfn.3.txt" or die ("[-] Error: Can't open or creat $opfn.3.txt\n");
open FASTARESULT,"> $opfn.u$upstreml.fa" or die ("[-] Error: Can't open or creat $opfn.u$upstreml.fa\n");
#open TCRSUT, "> $opfn.5.txt" or die ("[-] Error: Can't open or creat $opfn.5.txt\n");
#open TCFARESULT, "> $opfn.5.fa" or die ("[-] Error: Can't open or creat $opfn.5.fa\n");
open OUTGFF, "> $opfn.gff3" or die ("[-] Error: Can't open or creat $opfn.gff3\n");
print OUTGFF "##gff-version 3\n";
open DOWNFA,"> $opfn.down$downstreml.fa" or die ("[-] Error: Can't open or creat $opfn.down$downstreml.fa\n");
for (our $ni=0;$ni<$Chri;$ni++){
say "Deal with $Chrname[$ni].";
our $count1=0;
our $seqall = $Chrseq[$ni];
################Start deal with plus seqs.################
while ($seqall=~ /$testseq/igc){
#while ($seqall =~ /$testseq/igc){
#say $seqfilename;
#say "Chrom:",$AN;
$count1++;
#say "No.",$count1;
#our $l3=length ($3);
our $l1=length ($1);
our $seqpos=pos($seqall);
our $seqstarpos=$seqpos-$l1+1;
our $seqdownpos=$seqpos+$downstreml;
our $ChrID=$Chrname[$ni];
our $HID ="$ChrID"."H$count1";
#say $HID;
print RSUT ">$HID"," ";
print RSUT "$ChrID:$seqstarpos..",$seqpos," \n";
#print RSUT $l3," ";
#print RSUT $2," ";
#print RSUT $3," ";
#print RSUT $4,"\n";
print RSUT $1,"\n";
# print RSUT "-----------------------------------------\n";
print FASTARESULT ">$ChrID"."H$count1.up $ChrID:$seqstarpos..$seqpos\n";
our $rightfinalseq="";
if ($seqpos<$upstreml){
$rightfinalseq = substr($seqall,1,$seqpos);
}else{
$rightfinalseq = substr($seqall,$seqpos-$upstreml,$upstreml);
}
print FASTARESULT "$rightfinalseq\n";
print DOWNFA ">$ChrID"."H$count1.down $ChrID:$seqpos..$seqdownpos\n";
our $downfasta = substr($seqall,$seqpos,$downstreml);
print DOWNFA "$downfasta\n";
print OUTGFF "$ChrID\tFindpattern\tCDS\t$seqstarpos\t$seqpos\t.\t+\t.\tName=$HID.3;ID=$HID;Parent=$HID;Type=GA;Super_Family=GA\n";
our $TCi=0;
#say our $TCseq='([atgcn]{10}(TC(TCTACTA|T.TACTA.T|T.TACTAC|.{2}TACTACT|T.TAC.ACT|T.TA.TACT|T.TACT.CT|T.T.CTACT|.CTACTA.T|.{9}TATTAAG))[atgcn]{15})';
our $rfsl=length($rightfinalseq);
}
################ deal with plus seqs End#################
################Start TR-seqs#############################
$seqall = TRseq($seqall);
our $count2=0;
our $seqalll = length($seqall);
while ($seqall=~ /$testseq/igc){
#while ($seqall =~ /$testseq/igc){
#say $seqfilename;
#say "Chrom:",$AN;
$count2++;
#say "No.",$count2;
#our $l3=length ($3);
our $l1=length ($1);
our $seqpos=$seqalll-(pos($seqall))+1;
our $seqstarpos=$seqpos+$l1-1;
our $ChrID=$Chrname[$ni];
our $trHID ="tr$ChrID"."H$count2";
#say $trHID;
print RSUT ">tr$ChrID","H",$count2," ";
print RSUT "$ChrID:$seqstarpos..",$seqpos," \n";
#print RSUT $l3," ";
#print RSUT $2," ";
#print RSUT $3," ";
#print RSUT $4,"\n";
print RSUT $1,"\n";
# print RSUT "-----------------------------------------\n";
print FASTARESULT ">tr$ChrID"."H$count2.up $ChrID:$seqstarpos..$seqpos\n";
our $trseqpos = pos($seqall);
our $rightfinalseq="";
if($trseqpos<$upstreml){
$rightfinalseq = substr($seqall,1,$trseqpos);
}else{
$rightfinalseq = substr($seqall,$trseqpos-$upstreml,$upstreml);
}
print FASTARESULT "$rightfinalseq\n";
if ($seqpos<$downstreml) {
print DOWNFA ">tr$ChrID"."H$count2.down $ChrID:$seqpos..1\n";
}else {
my $temppos=$seqpos-$downstreml;
print DOWNFA ">tr$ChrID"."H$count2.down $ChrID:$seqpos..$temppos\n";
}
#print DOWNFA ">tr$ChrID"."H$count2.down $ChrID:$seqpos..$seqpos-$downstreml\n";
our $downfasta = substr($seqall,$trseqpos,$downstreml);
print DOWNFA "$downfasta\n";
print OUTGFF "$ChrID\tFindPattern\tCDS\t$seqpos\t$seqstarpos\t.\t-\t.\tName=$trHID.3;ID=$trHID;Parent=$trHID;Type=GA;Super_Family=GA\n";
our $TCi=0;
#say our $TCseq='([atgcn]{10}(TC(TCTACTA|T.TACTA.T|T.TACTAC|.{2}TACTACT|T.TAC.ACT|T.TA.TACT|T.TACT.CT|T.T.CTACT|.CTACTA.T|.{9}TATTAAG))[atgcn]{15})';
our $rfsl=length($rightfinalseq);
}
################ TR-seqs End#############################
}
close RSUT;
#close TCRSUT;
close FASTARESULT;
#close TCFARESULT;
close OUTGFF;
close DOWNFA;
######################################
#End main
######################################
our $endtime=time();
#say $starttime;
#say $endtime;
printf "Done! %g Sec %g Min\n",$endtime-$starttime,($endtime-$starttime)/60;