Mercurial > repos > ucsb-phylogenetics > osiris_phylogenetics
annotate getdata/get_seqs.pl @ 0:5b9a38ec4a39 draft default tip
First commit of old repositories
author | osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu> |
---|---|
date | Tue, 11 Mar 2014 12:19:13 -0700 |
parents | |
children |
rev | line source |
---|---|
0
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
1 #!/jgi/tools/bin/perl -w |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
2 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
3 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
4 # This script creates a Fasta/Qual/Fastq file of selected sequences, with optional filters. |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
5 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
6 # 02/24/10 : created by Ed Kirton |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
7 # 12/07/10 : fixed Fastq bug |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
8 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
9 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
10 use strict; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
11 use warnings; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
12 use Getopt::Long; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
13 use IO::File; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
14 #use PerlIO::gzip; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
15 use FindBin; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
16 use lib $FindBin::Bin; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
17 use FastaDb; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
18 use FastqDb; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
19 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
20 my $usage = <<'ENDHERE'; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
21 NAME: |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
22 get_seqs.pl |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
23 PURPOSE: |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
24 To extract a subset of sequences by ID. |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
25 INPUT: |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
26 --db <*.fasta|fastq> : file containing sequences in Fasta or Fastq format |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
27 --table <*.tsv> : file containing sequence IDs (optional; default=stdin) |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
28 --col <int> : column of table containing sequence IDs (optional; default=1=first column) |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
29 OUTPUT: |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
30 --selected <*.fasta|fastq> : file containing named sequences |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
31 --unselected <*.fasta|fastq> : file containing unselected sequences |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
32 OPTIONS: |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
33 --cosorted : uses faster algorithm if IDs appear in both files in the same order |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
34 --paired : filter complete read-pair when one read is selected (requires Illumina-style read IDs; i.e. */1, */2) |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
35 --ignore case : ignore case differences between IDs |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
36 --gzip : compress all outfiles |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
37 OPTIONAL FILTERS: |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
38 Optional filters, each in the form of column:condition:value. |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
39 Where column is the column in the table (containing IDs) |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
40 Condition is one of the following: |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
41 String operators: |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
42 s_eq |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
43 s_ne |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
44 s_contains |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
45 s_notcontains |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
46 s_startswith |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
47 s_notstartswith |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
48 s_endswith |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
49 s_notendswith |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
50 Numerical operators: |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
51 n_eq |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
52 n_ne |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
53 n_gt |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
54 n_lt |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
55 Where value is a string or number as appropriate. |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
56 AUTHOR/SUPPORT: |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
57 Edward Kirton (ESKirton@LBL.gov) |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
58 ENDHERE |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
59 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
60 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
61 # VALIDATE INPUT |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
62 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
63 my ($help, $dbfile, $tablefile, $id_col, $ignorecase, $cosorted, $selected, $unselected, $gzip, $paired); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
64 GetOptions( |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
65 'd|db=s' => \$dbfile, |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
66 't|table=s' => \$tablefile, |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
67 'c|col=i' => \$id_col, |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
68 'ignorecase' => \$ignorecase, |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
69 'cosorted' => \$cosorted, |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
70 's|selected=s' => \$selected, |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
71 'u|unselected=s' => \$unselected, |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
72 'g|gzip' => \$gzip, |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
73 'p|paired' => \$paired, |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
74 'h|help' => \$help |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
75 ); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
76 if ($help) { print $usage; exit; } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
77 die("DB required\n") unless $dbfile; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
78 die("DB file not found: $dbfile\n") unless -f $dbfile; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
79 die("Table required\n") unless $tablefile; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
80 die("Table file not found: $tablefile\n") unless -f $tablefile; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
81 $selected = '' if !defined($selected) or $selected eq 'None'; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
82 $unselected = '' if !defined($unselected) or $unselected eq 'None'; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
83 $id_col=1 unless $id_col; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
84 die("Invalid id column, $id_col\n") unless $id_col > 0; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
85 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
86 my $filters = []; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
87 while (my $filter = shift @ARGV) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
88 next unless $filter; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
89 my @a_filter = split(/:/, $filter); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
90 die("Invalid number of filter options: @a_filter") unless @a_filter == 3; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
91 push @$filters, \@a_filter; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
92 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
93 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
94 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
95 # MAIN |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
96 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
97 my ($n_selected,$n_unselected); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
98 if ($cosorted) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
99 # SEARCH IS FAST AND EASY IF INPUTS SIMILARLY SORTED! |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
100 ($n_selected,$n_unselected) = search_cosorted($dbfile, $tablefile, $id_col, $ignorecase, $selected, $unselected, $paired, $gzip, $filters); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
101 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
102 # INPUT NOT CO-SORTED SO KEEP ALL IDS IN RAM |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
103 ($n_selected,$n_unselected) = search($dbfile, $tablefile, $id_col, $ignorecase, $selected, $unselected, $paired, $gzip, $filters); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
104 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
105 print "Selected = $n_selected; Unselected = $n_unselected\n"; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
106 exit; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
107 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
108 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
109 # RETURNS TRUE ONLY IF RECORD MATCHES (OPTIONAL) SEARCH CRITERIA |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
110 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
111 sub match |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
112 { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
113 my ($filters, $row) = @_; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
114 foreach my $filterA (@$filters) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
115 my ($condition, $col, $value) = @$filterA; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
116 my $x = $row->[ $col - 1 ]; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
117 if ($condition eq 's_eq') { return 0 unless $x eq $value } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
118 elsif ($condition eq 's_ne') { return 0 unless $x ne $value } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
119 elsif ($condition eq 's_contains') { return 0 unless $x =~ /$value/ } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
120 elsif ($condition eq 's_notcontains') { return 0 unless $x !~ /$value/ } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
121 elsif ($condition eq 's_startswith') { return 0 unless $x =~ /^$value/ } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
122 elsif ($condition eq 's_notstartswith') { return 0 unless $x !~ /^$value/ } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
123 elsif ($condition eq 's_endswith') { return 0 unless $x =~ /$value$/ } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
124 elsif ($condition eq 's_notendswith') { return 0 unless $x !~ /$value$/ } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
125 elsif ($condition eq 'n_eq') { return 0 unless $x == $value } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
126 elsif ($condition eq 'n_ne') { return 0 unless $x != $value } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
127 elsif ($condition eq 'n_gt') { return 0 unless $x > $value } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
128 elsif ($condition eq 'n_lt') { return 0 unless $x < $value } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
129 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
130 return 1; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
131 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
132 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
133 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
134 # SIMULTANEOUSLY PARSE TWO STREAMS |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
135 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
136 sub search_cosorted |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
137 { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
138 my ($dbfile, $tablefile, $id_col, $ignorecase, $selected, $unselected, $paired, $gzip, $filters) = @_; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
139 my $sfh = new IO::File; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
140 my $ufh = new IO::File; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
141 my $table = new IO::File; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
142 my $n_selected = 0; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
143 my $n_unselected = 0; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
144 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
145 # OPEN FILES |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
146 if ($tablefile) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
147 open($table, "<$tablefile") or die("Unable to open file, $tablefile: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
148 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
149 $table=*STDIN; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
150 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
151 if ($selected) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
152 if ($gzip) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
153 # open($sfh, '>:gzip', $selected) or die("Unable to open file, $selected: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
154 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
155 open($sfh, ">$selected") or die("Unable to open file, $selected: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
156 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
157 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
158 open($sfh, ">/dev/null"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
159 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
160 if ($unselected) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
161 if ($gzip) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
162 # open($ufh, '>:gzip', $unselected) or die("Unable to open file, $unselected: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
163 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
164 open($ufh, ">$unselected") or die("Unable to open file, $unselected: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
165 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
166 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
167 open($ufh, ">/dev/null"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
168 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
169 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
170 # GET FIRST MATCHING TARGET ID |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
171 my $prev_target_id = ''; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
172 my $target_id = ''; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
173 get_next_matching_target_id($table,$id_col,$ignorecase,$filters,\$target_id,\$prev_target_id,$paired); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
174 unless ($target_id) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
175 # no records match search criteria |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
176 close $table; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
177 close $sfh if $selected; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
178 if ($unselected) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
179 open(DB, "<$dbfile") or die("Unable to open file, $dbfile: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
180 while (<DB>) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
181 print $ufh $_; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
182 ++$n_unselected; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
183 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
184 close DB; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
185 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
186 close $ufh; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
187 return 0; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
188 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
189 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
190 # DETERMINE FILETYPE |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
191 open(DB, "<$dbfile") or die("Unable to open file, $dbfile: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
192 my $format; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
193 while (<DB>) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
194 chomp; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
195 if (/^#/ or ! $_) { next } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
196 elsif (/^>/) { $format='fasta' } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
197 elsif (/^@/) { $format='fastq' } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
198 else { die "Invalid DB file format" } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
199 last; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
200 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
201 close DB; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
202 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
203 # PARSE |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
204 my $db = $format eq 'fasta' ? FastaDb->new($dbfile) : FastqDb->new($dbfile); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
205 while (my $rec=$db->next_seq ) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
206 unless ($target_id) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
207 last unless $unselected; # done if no more seqs to get |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
208 # otherwise dump rest of seqs in unselected file |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
209 print $ufh $rec->output; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
210 ++$n_unselected; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
211 while ($rec=$db->next_seq ) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
212 print $ufh $rec->output; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
213 ++$n_unselected; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
214 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
215 last; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
216 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
217 my $id=$ignorecase ? uc($rec->id):$rec->id; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
218 if ($id eq $prev_target_id or $id eq $target_id) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
219 # selected seq |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
220 print $sfh $rec->output; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
221 ++$n_selected; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
222 get_next_matching_target_id($table,$id_col,$ignorecase,$filters,\$target_id,\$prev_target_id,$paired); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
223 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
224 # unselected seq |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
225 print $ufh $rec->output; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
226 ++$n_unselected; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
227 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
228 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
229 close $table; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
230 close $sfh; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
231 close $ufh; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
232 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
233 # If some target seqs not found, it's likely the files were not cosorted, so try unsorted search function. |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
234 if ($target_id) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
235 print "Files don't appear to be cosorted, trying unsorted search\n"; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
236 return search($dbfile, $tablefile, $id_col, $ignorecase, $selected, $unselected, $filters); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
237 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
238 return ($n_selected,$n_unselected); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
239 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
240 sub get_next_matching_target_id { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
241 my ($table,$id_col,$ignorecase,$filters,$target_idR,$prev_target_idR,$paired)=@_; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
242 $$prev_target_idR = $$target_idR; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
243 $$target_idR = ''; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
244 while (<$table>) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
245 chomp; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
246 my @row = split(/\t/); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
247 die("Bad input table") unless @row >= $id_col; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
248 next unless match($filters, \@row); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
249 my $new_target_id = $ignorecase ? uc($row[ $id_col - 1 ]) : $row[ $id_col - 1 ]; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
250 $new_target_id=$1 if $new_target_id =~ /^(\S+)/; # use first word only |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
251 $new_target_id=$1 if $paired and $new_target_id =~ /^(\S+)\/[12]$/; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
252 next if $new_target_id eq $$prev_target_idR; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
253 $$target_idR=$new_target_id; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
254 last; # return to parsing db file |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
255 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
256 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
257 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
258 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
259 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
260 # LOAD IDS IN RAM THEN PARSE DB. |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
261 # |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
262 sub search |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
263 { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
264 my ($dbfile, $tablefile, $id_col, $ignorecase, $selected, $unselected, $paired, $gzip, $filters) = @_; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
265 my $sfh = new IO::File; # selected seqs |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
266 my $ufh = new IO::File; # unselected seqs |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
267 my $table=new IO::File; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
268 my $n_selected=0; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
269 my $n_unselected=0; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
270 my %ids = (); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
271 open(DB, "<$dbfile") or die("Unable to open file, $dbfile: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
272 if ($tablefile) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
273 open($table, "<$tablefile") or die("Unable to open file, $tablefile: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
274 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
275 $table=*STDIN; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
276 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
277 if ($selected) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
278 if ($gzip) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
279 # open($sfh, '>:gzip', $selected) or die("Unable to open file, $selected: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
280 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
281 open($sfh, ">$selected") or die("Unable to open file, $selected: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
282 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
283 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
284 open($sfh, ">/dev/null"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
285 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
286 if ($unselected) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
287 if ($gzip) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
288 # open($ufh, '>:gzip', $unselected) or die("Unable to open file, $unselected: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
289 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
290 open($ufh, ">$unselected") or die("Unable to open file, $unselected: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
291 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
292 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
293 open($ufh, ">/dev/null"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
294 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
295 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
296 # LOAD IDS OF MATCHING ROWS |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
297 my $num_targets=0; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
298 while (<$table>) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
299 next if /^#/; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
300 chomp; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
301 my @row = split(/\t/); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
302 my $id = $ignorecase ? uc($row[ $id_col - 1 ]) : $row[ $id_col - 1 ]; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
303 $id=$1 if $id =~ /^(\S+)/; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
304 $id=$1 if $paired and $id =~ /^(\S+)\/[12]$/; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
305 if (match($filters, \@row)) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
306 # remember this ID |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
307 $ids{$id} = 0; # number of reads with this ID found (counter for paired option) |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
308 ++$num_targets; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
309 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
310 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
311 unless ($num_targets) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
312 # no records match search criteria |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
313 close $table; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
314 close $sfh if $selected; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
315 if ($unselected) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
316 open(DB, "<$dbfile") or die("Unable to open file, $dbfile: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
317 while (<DB>) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
318 print $ufh $_; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
319 ++$n_unselected; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
320 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
321 close DB; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
322 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
323 close $ufh; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
324 return 0; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
325 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
326 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
327 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
328 # DETERMINE FILETYPE |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
329 open(DB, "<$dbfile") or die("Unable to open file, $dbfile: $!\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
330 my $format; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
331 while (<DB>) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
332 chomp; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
333 if (/^#/ or /^$/) { next } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
334 elsif (/^>/) { $format='fasta' } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
335 elsif (/^@/) { $format='fastq' } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
336 else { die "Invalid DB file format" } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
337 last; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
338 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
339 close DB; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
340 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
341 # GET SEQS |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
342 my $db = $format eq 'fasta' ? FastaDb->new($dbfile) : FastqDb->new($dbfile); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
343 while (my $rec=$db->next_seq ) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
344 my $id = $ignorecase ? uc($rec->id) : $rec->id; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
345 $id = $1 if $paired and $id =~ /^(\S+)\/[12]$/; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
346 if (exists($ids{$id})) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
347 # selected |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
348 print $sfh $rec->output; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
349 ++$n_selected; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
350 if (!$paired) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
351 delete $ids{$id}; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
352 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
353 $ids{$id} += 1; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
354 delete $ids{$id} if $ids{$id} == 2; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
355 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
356 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
357 # unselected |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
358 print $ufh $rec->output; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
359 ++$n_unselected; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
360 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
361 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
362 close $table; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
363 close $sfh; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
364 close $ufh; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
365 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
366 # MAKE SURE ALL TARGETS WERE FOUND |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
367 foreach my $id (keys %ids) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
368 if ($ids{$id}) { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
369 delete($ids{$id}); # SOMETIMES INFILES CONTAIN ONLY ONE READ OF PAIR |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
370 }elsif($id eq 'EMPTY') { #ADDEDBY THO TO ALLOW EMPTY blast results |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
371 #in workflow using checkempty.pl |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
372 exit; |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
373 } else { |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
374 warn("Seq not found: $id\n"); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
375 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
376 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
377 return ($n_selected,$n_unselected); |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
378 } |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
379 |
5b9a38ec4a39
First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff
changeset
|
380 __END__ |