annotate matching.pl @ 0:87fe81de0931 draft default tip

Uploaded
author bigrna
date Sun, 04 Jan 2015 02:47:25 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
1 #!/usr/bin/perl -w
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
2 #Filename:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
3 #Author: Tian Dongmei
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
4 #Email: tiandm@big.ac.cn
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
5 #Date: 2013/7/19
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
6 #Modified:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
7 #Description:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
8 my $version=1.00;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
9
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
10 use strict;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
11 use Getopt::Long;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
12
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
13 my %opts;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
14 GetOptions(\%opts,"i=s","g=s","index:s","v:i","p:i","r:s","o=s","h");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
15 if (!(defined $opts{i} and defined $opts{o} ) || defined $opts{h}) { #necessary arguments
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
16 &usage;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
17 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
18
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
19 my $filein=$opts{'i'};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
20 my $fileout=$opts{'o'};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
21 unless ($fileout=~/\/$/) {$fileout.="/";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
22 my $genome=$opts{'g'};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
23 my $mis=defined $opts{'v'}? $opts{'v'} : 0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
24 my $hits=defined $opts{'r'}? $opts{'r'} : 25;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
25 my $index=defined $opts{'index'} ? $opts{'index'} : "";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
26 my $threads=defined $opts{'p'} ? $opts{'p'} : 1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
27
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
28
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
29 my $time=&Time();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
30 my $mapdir=$fileout."/genome_match";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
31 if(not -d $mapdir){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
32 mkdir $mapdir;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
33 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
34 chdir $mapdir;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
35 ###check genome index
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
36 if (-s $index.".1.ebwt") {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
37 }else{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
38 `bowtie-build $genome $genome`;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
39 $index="$genome";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
40 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
41
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
42 ### genome mapping
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
43 `bowtie -v $mis -f -p $threads -m $hits -a --best --strata $index $filein --al genome_mapped.fa --un genome_not_mapped.fa --max genome_mapped_Mlimit.fa > genome_mapped.bwt 2> run.log`;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
44
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
45 #`convert_bowtie_to_blast.pl genome_mapped.bwt genome_mapped.fa $genome > genome_mapped.bst`;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
46
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
47 sub Time{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
48 my $time=time();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
49 my ($sec,$min,$hour,$day,$month,$year) = (localtime($time))[0,1,2,3,4,5,6];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
50 $month++;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
51 $year+=1900;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
52 if (length($sec) == 1) {$sec = "0"."$sec";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
53 if (length($min) == 1) {$min = "0"."$min";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
54 if (length($hour) == 1) {$hour = "0"."$hour";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
55 if (length($day) == 1) {$day = "0"."$day";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
56 if (length($month) == 1) {$month = "0"."$month";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
57 #print "$year-$month-$day $hour:$min:$sec\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
58 return("$year-$month-$day-$hour-$min-$sec");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
59 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
60
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
61 sub usage{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
62 print <<"USAGE";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
63 Version $version
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
64 Usage:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
65 $0 -i -o
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
66 options:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
67 -i input file# input reads fasta/fastq file
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
68 -g input file# genome file
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
69 -index file-prefix #(must be indexed by bowtie-build) The parameter
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
70 string must be the prefix of the bowtie index. For instance, if
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
71 the first indexed file is called 'h_sapiens_37_asm.1.ebwt' then
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
72 the prefix is 'h_sapiens_37_asm'.##can be null
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
73 -v <int> report end-to-end hits w/ <=v mismatches; ignore qualities,default 0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
74
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
75 -p/--threads <int> number of alignment threads to launch (default: 1)
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
76
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
77 -r int a read is allowed to map up to this number of positions in the genome
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
78 default is 25
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
79
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
80 -o output directory
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
81
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
82 -h help
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
83 USAGE
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
84 exit(1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
85 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
86