Mercurial > repos > big-tiandm > mirplant2
comparison rfam.pl @ 19:141a337097e1 draft
Uploaded
author | big-tiandm |
---|---|
date | Fri, 25 Jul 2014 05:22:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
18:a79212816cbc | 19:141a337097e1 |
---|---|
1 #!/usr/bin/perl -w | |
2 #Filename: | |
3 #Author: Tian Dongmei | |
4 #Email: tiandm@big.ac.cn | |
5 #Date: 2013/7/19 | |
6 #Modified: | |
7 #Description: | |
8 my $version=1.00; | |
9 | |
10 use strict; | |
11 use Getopt::Long; | |
12 use File::Basename; | |
13 | |
14 my %opts; | |
15 GetOptions(\%opts,"i=s","ref=s","index:s","v:i","p:i","o=s","time:s","h"); | |
16 if (!(defined $opts{i} and defined $opts{o} ) || defined $opts{h}) { #necessary arguments | |
17 &usage; | |
18 } | |
19 | |
20 my $filein=$opts{'i'}; | |
21 my $dir=$opts{'o'}; | |
22 unless ($dir=~/\/$/) {$dir.="/";} | |
23 my $rfam=$opts{'ref'}; | |
24 my $mis=defined $opts{'v'}? $opts{'v'} : 0; | |
25 my $index=defined $opts{'index'} ? $opts{'index'} : ""; | |
26 my $threads=defined $opts{'p'} ? $opts{'p'} : 1; | |
27 | |
28 if (not -d $dir) { | |
29 mkdir $dir; | |
30 } | |
31 | |
32 | |
33 my $time=Time(); | |
34 if (defined $opts{'time'}) { | |
35 $time=$opts{'time'}; | |
36 } | |
37 my $mapdir=$dir."/rfam_match_".$time; | |
38 if(not -d $mapdir){ | |
39 mkdir $mapdir; | |
40 } | |
41 chdir $mapdir; | |
42 ###check genome index | |
43 if (-s $index.".1.ebwt") { | |
44 }else{ | |
45 &checkACGT($rfam); | |
46 `bowtie-build $rfam`; | |
47 $index="$rfam"; | |
48 } | |
49 ### genome mapping | |
50 `bowtie -v $mis -f -p $threads -k 1 $index $filein --al rfam_mapped.fa --un rfam_not_mapped.fa > rfam_mapped.bwt`; | |
51 | |
52 sub checkACGT{ | |
53 my $string; | |
54 open IN,"<$rfam"; | |
55 while (my $aline=<IN>) { | |
56 if ($aline!~/^>/) { | |
57 $aline=~s/U/T/gi; | |
58 } | |
59 $string .=$aline; | |
60 } | |
61 close IN; | |
62 $rfam=basename($rfam); | |
63 open OUT, ">$rfam"; | |
64 print OUT $string; | |
65 close OUT; | |
66 } | |
67 | |
68 sub Time{ | |
69 my $time=time(); | |
70 my ($sec,$min,$hour,$day,$month,$year) = (localtime($time))[0,1,2,3,4,5,6]; | |
71 $month++; | |
72 $year+=1900; | |
73 if (length($sec) == 1) {$sec = "0"."$sec";} | |
74 if (length($min) == 1) {$min = "0"."$min";} | |
75 if (length($hour) == 1) {$hour = "0"."$hour";} | |
76 if (length($day) == 1) {$day = "0"."$day";} | |
77 if (length($month) == 1) {$month = "0"."$month";} | |
78 #print "$year-$month-$day $hour:$min:$sec\n"; | |
79 return("$year-$month-$day-$hour-$min-$sec"); | |
80 } | |
81 sub usage{ | |
82 print <<"USAGE"; | |
83 Version $version | |
84 Usage: | |
85 $0 -i -o | |
86 options: | |
87 -i input file# input reads fasta/fastq file | |
88 -ref input file# rfam file, which do not contain miRNAs | |
89 -index file-prefix #(must be indexed by bowtie-build) The parameter | |
90 string must be the prefix of the bowtie index. For instance, if | |
91 the first indexed file is called 'h_sapiens_37_asm.1.ebwt' then | |
92 the prefix is 'h_sapiens_37_asm'.##can be null | |
93 -v <int> report end-to-end hits w/ <=v mismatches; ignore qualities,default 0; | |
94 | |
95 -p/--threads <int> number of alignment threads to launch (default: 1) | |
96 | |
97 -o output directory | |
98 -time sting #make directory time,default is the local time | |
99 -h help | |
100 USAGE | |
101 exit(1); | |
102 } | |
103 |