annotate pyCRAC/pyBarcodeFilter.pl @ 0:19b20927172d draft

Uploaded
author swebb
date Tue, 18 Jun 2013 09:11:00 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
19b20927172d Uploaded
swebb
parents:
diff changeset
1 #!/usr/bin/perl -w
19b20927172d Uploaded
swebb
parents:
diff changeset
2 use strict;
19b20927172d Uploaded
swebb
parents:
diff changeset
3 use Getopt::Long;
19b20927172d Uploaded
swebb
parents:
diff changeset
4
19b20927172d Uploaded
swebb
parents:
diff changeset
5 my %opt;
19b20927172d Uploaded
swebb
parents:
diff changeset
6
19b20927172d Uploaded
swebb
parents:
diff changeset
7
19b20927172d Uploaded
swebb
parents:
diff changeset
8 GetOptions(\%opt, "f=s", "b=s", "out=s", "output_path=s","id=s","m=i", "file_type=s", "both", "r=s", "version", "i");
19b20927172d Uploaded
swebb
parents:
diff changeset
9
19b20927172d Uploaded
swebb
parents:
diff changeset
10 my $cmnd;
19b20927172d Uploaded
swebb
parents:
diff changeset
11
19b20927172d Uploaded
swebb
parents:
diff changeset
12 if (exists $opt{version}){
19b20927172d Uploaded
swebb
parents:
diff changeset
13 $cmnd = "python /usr/local/bin/pyBarcodeFilter.py --version";
19b20927172d Uploaded
swebb
parents:
diff changeset
14 }
19b20927172d Uploaded
swebb
parents:
diff changeset
15 else{
19b20927172d Uploaded
swebb
parents:
diff changeset
16 $cmnd = "python /usr/local/bin/pyBarcodeFilter.py -f $opt{f} -b $opt{b} -m $opt{m} --file_type $opt{file_type}";
19b20927172d Uploaded
swebb
parents:
diff changeset
17
19b20927172d Uploaded
swebb
parents:
diff changeset
18 if(defined $opt{r}){
19b20927172d Uploaded
swebb
parents:
diff changeset
19
19b20927172d Uploaded
swebb
parents:
diff changeset
20 $cmnd.= " -r $opt{r}";
19b20927172d Uploaded
swebb
parents:
diff changeset
21
19b20927172d Uploaded
swebb
parents:
diff changeset
22 if(exists $opt{both}){
19b20927172d Uploaded
swebb
parents:
diff changeset
23 $cmnd .= " --both";
19b20927172d Uploaded
swebb
parents:
diff changeset
24 }
19b20927172d Uploaded
swebb
parents:
diff changeset
25 }
19b20927172d Uploaded
swebb
parents:
diff changeset
26
19b20927172d Uploaded
swebb
parents:
diff changeset
27 if(exists $opt{i}){
19b20927172d Uploaded
swebb
parents:
diff changeset
28 $cmnd .= " -i";
19b20927172d Uploaded
swebb
parents:
diff changeset
29 }
19b20927172d Uploaded
swebb
parents:
diff changeset
30 }
19b20927172d Uploaded
swebb
parents:
diff changeset
31
19b20927172d Uploaded
swebb
parents:
diff changeset
32 # Create the output directory (for the multiple output files)
19b20927172d Uploaded
swebb
parents:
diff changeset
33 my $output_path = $opt{output_path};
19b20927172d Uploaded
swebb
parents:
diff changeset
34
19b20927172d Uploaded
swebb
parents:
diff changeset
35 system $cmnd;
19b20927172d Uploaded
swebb
parents:
diff changeset
36
19b20927172d Uploaded
swebb
parents:
diff changeset
37 open(BC,$opt{b}) || die "Cannot open barcode file";
19b20927172d Uploaded
swebb
parents:
diff changeset
38 my %bc;
19b20927172d Uploaded
swebb
parents:
diff changeset
39 while(my $line = <BC>){
19b20927172d Uploaded
swebb
parents:
diff changeset
40 chomp($line);
19b20927172d Uploaded
swebb
parents:
diff changeset
41 my ($barcode,$sample) = (split(/\t/,$line))[0,1];
19b20927172d Uploaded
swebb
parents:
diff changeset
42 $bc{$barcode}=$sample;
19b20927172d Uploaded
swebb
parents:
diff changeset
43 }
19b20927172d Uploaded
swebb
parents:
diff changeset
44
19b20927172d Uploaded
swebb
parents:
diff changeset
45 system "mv barcode_statistics.txt $opt{out}";
19b20927172d Uploaded
swebb
parents:
diff changeset
46
19b20927172d Uploaded
swebb
parents:
diff changeset
47 my $ft = lc($opt{file_type});
19b20927172d Uploaded
swebb
parents:
diff changeset
48
19b20927172d Uploaded
swebb
parents:
diff changeset
49 foreach my $key(keys %bc){
19b20927172d Uploaded
swebb
parents:
diff changeset
50 my @split = (split(/\//,$opt{f}));
19b20927172d Uploaded
swebb
parents:
diff changeset
51 my $l = @split;
19b20927172d Uploaded
swebb
parents:
diff changeset
52 my $output = $split[$l-1];
19b20927172d Uploaded
swebb
parents:
diff changeset
53 $output = (split(/\./,$output))[0];
19b20927172d Uploaded
swebb
parents:
diff changeset
54 $output = "$output"."_"."$key"."_"."$bc{$key}"."."."$ft";
19b20927172d Uploaded
swebb
parents:
diff changeset
55 my $rename = "$output_path/primary_$opt{id}_$bc{$key}-1"."_visible_"."$ft";
19b20927172d Uploaded
swebb
parents:
diff changeset
56 system "mv $output $rename";
19b20927172d Uploaded
swebb
parents:
diff changeset
57
19b20927172d Uploaded
swebb
parents:
diff changeset
58 if(defined $opt{r}){
19b20927172d Uploaded
swebb
parents:
diff changeset
59 my @split2 = (split(/\//,$opt{r}));
19b20927172d Uploaded
swebb
parents:
diff changeset
60 $l = @split2;
19b20927172d Uploaded
swebb
parents:
diff changeset
61 $output = $split2[$l-1];
19b20927172d Uploaded
swebb
parents:
diff changeset
62 $output = (split(/\./,$output))[0];
19b20927172d Uploaded
swebb
parents:
diff changeset
63 $output = "$output"."_"."$key"."_"."$bc{$key}"."."."$ft";
19b20927172d Uploaded
swebb
parents:
diff changeset
64 $rename = "$output_path/primary_$opt{id}_$bc{$key}-2"."_visible_"."$ft";
19b20927172d Uploaded
swebb
parents:
diff changeset
65 system "mv $output $rename";
19b20927172d Uploaded
swebb
parents:
diff changeset
66 }
19b20927172d Uploaded
swebb
parents:
diff changeset
67 }
19b20927172d Uploaded
swebb
parents:
diff changeset
68
19b20927172d Uploaded
swebb
parents:
diff changeset
69
19b20927172d Uploaded
swebb
parents:
diff changeset
70 close BC;
19b20927172d Uploaded
swebb
parents:
diff changeset
71