annotate rfam.pl @ 19:141a337097e1 draft

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