annotate PanExplorer_workflow/Perl/bp_genbank2gff3.pl @ 2:97e4e3e818b6 draft

Uploaded
author dereeper
date Thu, 30 May 2024 11:48:09 +0000
parents 032f6b3806a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1 #!/opt/anaconda1anaconda2anaconda3/bin/perl
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
3 eval 'exec /opt/anaconda1anaconda2anaconda3/bin/perl -S $0 ${1+"$@"}'
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
4 if 0; # not running under some shell
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
5
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
6
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
7
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
8 =pod
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
9
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
10 =head1 NAME
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
11
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
12 bp_genbank2gff3.pl -- Genbank-E<gt>gbrowse-friendly GFF3
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
13
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
14 =head1 SYNOPSIS
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
15
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
16 bp_genbank2gff3.pl [options] filename(s)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
17
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
18 # process a directory containing GenBank flatfiles
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
19 perl bp_genbank2gff3.pl --dir path_to_files --zip
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
20
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
21 # process a single file, ignore explicit exons and introns
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
22 perl bp_genbank2gff3.pl --filter exon --filter intron file.gbk.gz
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
23
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
24 # process a list of files
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
25 perl bp_genbank2gff3.pl *gbk.gz
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
26
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
27 # process data from URL, with Chado GFF model (-noCDS), and pipe to database loader
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
28 curl ftp://ftp.ncbi.nih.gov/genomes/Saccharomyces_cerevisiae/CHR_X/NC_001142.gbk \
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
29 | perl bp_genbank2gff3.pl -noCDS -in stdin -out stdout \
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
30 | perl gmod_bulk_load_gff3.pl -dbname mychado -organism fromdata
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
31
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
32 Options:
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
33 --noinfer -r don't infer exon/mRNA subfeatures
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
34 --conf -i path to the curation configuration file that contains user preferences
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
35 for Genbank entries (must be YAML format)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
36 (if --manual is passed without --ini, user will be prompted to
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
37 create the file if any manual input is saved)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
38 --sofile -l path to to the so.obo file to use for feature type mapping
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
39 (--sofile live will download the latest online revision)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
40 --manual -m when trying to guess the proper SO term, if more than
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
41 one option matches the primary tag, the converter will
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
42 wait for user input to choose the correct one
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
43 (only works with --sofile)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
44 --dir -d path to a list of genbank flatfiles
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
45 --outdir -o location to write GFF files (can be 'stdout' or '-' for pipe)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
46 --zip -z compress GFF3 output files with gzip
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
47 --summary -s print a summary of the features in each contig
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
48 --filter -x genbank feature type(s) to ignore
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
49 --split -y split output to separate GFF and fasta files for
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
50 each genbank record
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
51 --nolump -n separate file for each reference sequence
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
52 (default is to lump all records together into one
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
53 output file for each input file)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
54 --ethresh -e error threshold for unflattener
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
55 set this high (>2) to ignore all unflattener errors
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
56 --[no]CDS -c Keep CDS-exons, or convert to alternate gene-RNA-protein-exon
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
57 model. --CDS is default. Use --CDS to keep default GFF gene model,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
58 use --noCDS to convert to g-r-p-e.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
59 --format -f Input format (SeqIO types): GenBank, Swiss or Uniprot, EMBL work
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
60 (GenBank is default)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
61 --GFF_VERSION 3 is default, 2 and 2.5 and other Bio::Tools::GFF versions available
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
62 --quiet don't talk about what is being processed
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
63 --typesource SO sequence type for source (e.g. chromosome; region; contig)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
64 --help -h display this message
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
65
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
66
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
67 =head1 DESCRIPTION
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
68
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
69 This script uses Bio::SeqFeature::Tools::Unflattener and
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
70 Bio::Tools::GFF to convert GenBank flatfiles to GFF3 with gene
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
71 containment hierarchies mapped for optimal display in gbrowse.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
72
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
73 The input files are assumed to be gzipped GenBank flatfiles for refseq
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
74 contigs. The files may contain multiple GenBank records. Either a
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
75 single file or an entire directory can be processed. By default, the
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
76 DNA sequence is embedded in the GFF but it can be saved into separate
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
77 fasta file with the --split(-y) option.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
78
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
79 If an input file contains multiple records, the default behaviour is
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
80 to dump all GFF and sequence to a file of the same name (with .gff
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
81 appended). Using the 'nolump' option will create a separate file for
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
82 each genbank record. Using the 'split' option will create separate
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
83 GFF and Fasta files for each genbank record.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
84
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
85
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
86 =head2 Notes
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
87
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
88 =head3 'split' and 'nolump' produce many files
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
89
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
90 In cases where the input files contain many GenBank records (for
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
91 example, the chromosome files for the mouse genome build), a very
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
92 large number of output files will be produced if the 'split' or
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
93 'nolump' options are selected. If you do have lists of files E<gt> 6000,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
94 use the --long_list option in bp_bulk_load_gff.pl or
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
95 bp_fast_load_gff.pl to load the gff and/ or fasta files.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
96
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
97 =head3 Designed for RefSeq
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
98
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
99 This script is designed for RefSeq genomic sequence entries. It may
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
100 work for third party annotations but this has not been tested.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
101 But see below, Uniprot/Swissprot works, EMBL and possibly EMBL/Ensembl
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
102 if you don't mind some gene model unflattener errors (dgg).
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
103
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
104 =head3 G-R-P-E Gene Model
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
105
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
106 Don Gilbert worked this over with needs to produce GFF3 suited to
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
107 loading to GMOD Chado databases. Most of the changes I believe are
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
108 suited for general use. One main chado-specific addition is the
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
109 --[no]cds2protein flag
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
110
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
111 My favorite GFF is to set the above as ON by default (disable with --nocds2prot)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
112 For general use it probably should be OFF, enabled with --cds2prot.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
113
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
114 This writes GFF with an alternate, but useful Gene model,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
115 instead of the consensus model for GFF3
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
116
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
117 [ gene > mRNA> (exon,CDS,UTR) ]
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
118
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
119 This alternate is
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
120
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
121 gene > mRNA > polypeptide > exon
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
122
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
123 means the only feature with dna bases is the exon. The others
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
124 specify only location ranges on a genome. Exon of course is a child
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
125 of mRNA and protein/peptide.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
126
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
127 The protein/polypeptide feature is an important one, having all the
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
128 annotations of the GenBank CDS feature, protein ID, translation, GO
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
129 terms, Dbxrefs to other proteins.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
130
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
131 UTRs, introns, CDS-exons are all inferred from the primary exon bases
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
132 inside/outside appropriate higher feature ranges. Other special gene
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
133 model features remain the same.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
134
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
135 Several other improvements and bugfixes, minor but useful are included
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
136
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
137 * IO pipes now work:
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
138 curl ftp://ncbigenomes/... | bp_genbank2gff3 --in stdin --out stdout | gff2chado ...
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
139
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
140 * GenBank main record fields are added to source feature, e.g. organism, date,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
141 and the sourcetype, commonly chromosome for genomes, is used.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
142
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
143 * Gene Model handling for ncRNA, pseudogenes are added.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
144
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
145 * GFF header is cleaner, more informative.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
146 --GFF_VERSION flag allows choice of v2 as well as default v3
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
147
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
148 * GFF ##FASTA inclusion is improved, and
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
149 CDS translation sequence is moved to FASTA records.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
150
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
151 * FT -> GFF attribute mapping is improved.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
152
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
153 * --format choice of SeqIO input formats (GenBank default).
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
154 Uniprot/Swissprot and EMBL work and produce useful GFF.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
155
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
156 * SeqFeature::Tools::TypeMapper has a few FT -> SOFA additions
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
157 and more flexible usage.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
158
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
159 =head1 TODO
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
160
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
161 =head2 Are these additions desired?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
162
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
163 * filter input records by taxon (e.g. keep only organism=xxx or taxa level = classYYY
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
164 * handle Entrezgene, other non-sequence SeqIO structures (really should change
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
165 those parsers to produce consistent annotation tags).
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
166
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
167 =head2 Related bugfixes/tests
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
168
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
169 These items from Bioperl mail were tested (sample data generating
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
170 errors), and found corrected:
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
171
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
172 From: Ed Green <green <at> eva.mpg.de>
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
173 Subject: genbank2gff3.pl on new human RefSeq
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
174 Date: 2006-03-13 21:22:26 GMT
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
175 -- unspecified errors (sample data works now).
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
176
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
177 From: Eric Just <e-just <at> northwestern.edu>
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
178 Subject: genbank2gff3.pl
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
179 Date: 2007-01-26 17:08:49 GMT
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
180 -- bug fixed in genbank2gff3 for multi-record handling
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
181
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
182 This error is for a /trans_splice gene that is hard to handle, and
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
183 unflattner/genbank2 doesn't
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
184
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
185 From: Chad Matsalla <chad <at> dieselwurks.com>
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
186 Subject: genbank2gff3.PLS and the unflatenner - Inconsistent order?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
187 Date: 2005-07-15 19:51:48 GMT
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
188
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
189 =head1 AUTHOR
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
190
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
191 Sheldon McKay (mckays@cshl.edu)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
192
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
193 Copyright (c) 2004 Cold Spring Harbor Laboratory.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
194
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
195 =head2 AUTHOR of hacks for GFF2Chado loading
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
196
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
197 Don Gilbert (gilbertd@indiana.edu)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
198
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
199
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
200 =cut
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
201
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
202 use strict;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
203 use warnings;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
204
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
205 use lib "$ENV{HOME}/bioperl-live";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
206 # chad put this here to enable situations when this script is tested
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
207 # against bioperl compiled into blib along with other programs using blib
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
208 BEGIN {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
209 unshift(@INC,'blib/lib');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
210 };
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
211 use Pod::Usage;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
212 use Bio::Root::RootI;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
213 use Bio::SeqIO;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
214 use File::Spec;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
215 use Bio::SeqFeature::Tools::Unflattener;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
216 use Bio::SeqFeature::Tools::TypeMapper;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
217 use Bio::SeqFeature::Tools::IDHandler;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
218 use Bio::Location::SplitLocationI;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
219 use Bio::Location::Simple;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
220 use Bio::Tools::GFF;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
221 use Getopt::Long;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
222 use List::Util qw(first);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
223 use Bio::OntologyIO;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
224 use YAML qw(Dump LoadFile DumpFile);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
225 use File::Basename;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
226
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
227 use vars qw/$split @filter $zip $outdir $help $ethresh
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
228 $ONTOLOGY %FEATURES %DESCENDANTS @RETURN $MANUAL @GFF_LINE_FEAT
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
229 $CONF $YAML $TYPE_MAP $SYN_MAP $noinfer $SO_FILE
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
230 $file @files $dir $summary $nolump
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
231 $source_type %proteinfa %exonpar $didheader $verbose $DEBUG $GFF_VERSION
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
232 $gene_id $rna_id $tnum $ncrna_id $rnum %method %id %seen/;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
233
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
234 use constant SO_URL =>
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
235 'http://song.cvs.sourceforge.net/viewvc/*checkout*/song/ontology/so.obo';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
236 use constant ALPHABET => [qw(a b c d e f g h i j k l m n o p q r s t u v w x y z)];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
237 use constant ALPHABET_TO_NUMBER => {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
238 a => 0, b => 1, c => 2, d => 3, e => 4, f => 5, g => 6, h => 7, i => 8,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
239 j => 9, k => 10, l => 11, m => 12, n => 13, o => 14, p => 15, q => 16,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
240 r => 17, s => 18, t => 19, u => 20, v => 21, w => 22, x => 23, y => 24,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
241 z => 25,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
242 };
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
243 use constant ALPHABET_DIVISOR => 26;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
244 use constant GM_NEW_TOPLEVEL => 2;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
245 use constant GM_NEW_PART => 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
246 use constant GM_DUP_PART => 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
247 use constant GM_NOT_PART => -1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
248
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
249 # Options cycle in multiples of 2 because of left side/right side pairing.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
250 # You can make this number odd, but displayed matches will still round up
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
251 use constant OPTION_CYCLE => 6;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
252
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
253 $GFF_VERSION = 3; # allow v2 ...
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
254 $verbose = 1; # right default? -nov to turn off
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
255
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
256 # dgg: change the gene model to Gene/mRNA/Polypeptide/exons...
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
257 my $CDSkeep= 1; # default should be ON (prior behavior), see gene_features()
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
258 my $PROTEIN_TYPE = 'polypeptide'; # for noCDSkeep;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
259 # protein = flybase chado usage; GMOD Perls use 'polypeptide' with software support
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
260
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
261 my $FORMAT="GenBank"; # swiss ; embl; genbank ; ** guess from SOURCEID **
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
262 my $SOURCEID= $FORMAT; # "UniProt" "GenBank" "EMBL" should work
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
263 # other Bio::SeqIO formats may work. TEST: EntrezGene < problematic tags; InterPro KEGG
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
264
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
265
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
266 my %TAG_MAP = (
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
267 db_xref => 'Dbxref',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
268 name => 'Name',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
269 note => 'Note', # also pull GO: ids into Ontology_term
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
270 synonym => 'Alias',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
271 symbol => 'Alias', # is symbol still used?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
272 # protein_id => 'Dbxref', also seen Dbxref tags: EC_number
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
273 # translation: handled in gene_features
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
274 );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
275
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
276
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
277 $| = 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
278 my $quiet= !$verbose;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
279 my $ok= GetOptions( 'd|dir|input:s' => \$dir,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
280 'z|zip' => \$zip,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
281 'h|help' => \$help,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
282 's|summary' => \$summary,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
283 'r|noinfer' => \$noinfer,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
284 'i|conf=s' => \$CONF,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
285 'sofile=s' => \$SO_FILE,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
286 'm|manual' => \$MANUAL,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
287 'o|outdir|output:s'=> \$outdir,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
288 'x|filter:s'=> \@filter,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
289 'y|split' => \$split,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
290 "ethresh|e=s"=>\$ethresh,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
291 'c|CDS!' => \$CDSkeep,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
292 'f|format=s' => \$FORMAT,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
293 'typesource=s' => \$source_type,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
294 'GFF_VERSION=s' => \$GFF_VERSION,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
295 'quiet!' => \$quiet, # swap quiet to verbose
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
296 'DEBUG!' => \$DEBUG,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
297 'n|nolump' => \$nolump);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
298
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
299 my $lump = 1 unless $nolump || $split;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
300 $verbose= !$quiet;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
301
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
302 # look for help request
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
303 pod2usage(2) if $help || !$ok;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
304
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
305 # keep SOURCEID as-is and change FORMAT for SeqIO types;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
306 # note SeqIO uses file.suffix to guess type; not useful here
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
307 $SOURCEID= $FORMAT;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
308 $FORMAT = "swiss" if $FORMAT =~/UniProt|trembl/;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
309 $verbose =1 if($DEBUG);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
310
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
311 # initialize handlers
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
312 my $unflattener = Bio::SeqFeature::Tools::Unflattener->new; # for ensembl genomes (-trust_grouptag=>1);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
313 $unflattener->error_threshold($ethresh) if $ethresh;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
314 $unflattener->verbose(1) if($DEBUG);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
315 # $unflattener->group_tag('gene') if($FORMAT =~ /embl/i) ; #? ensembl only?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
316 # ensembl parsing is still problematic, forget this
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
317
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
318 my $tm = Bio::SeqFeature::Tools::TypeMapper->new;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
319 my $idh = Bio::SeqFeature::Tools::IDHandler->new;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
320
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
321 # dgg
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
322 $source_type ||= "region"; # should really parse from FT.source contents below
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
323
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
324 #my $FTSOmap = $tm->FT_SO_map();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
325 my $FTSOmap;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
326 my $FTSOsynonyms;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
327
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
328 if (defined($SO_FILE) && $SO_FILE eq 'live') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
329 print "\nDownloading the latest SO file from ".SO_URL."\n\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
330 use LWP::UserAgent;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
331 my $ua = LWP::UserAgent->new(timeout => 30);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
332 my $request = HTTP::Request->new(GET => SO_URL);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
333 my $response = $ua->request($request);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
334
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
335
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
336 if ($response->status_line =~ /200/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
337 use File::Temp qw/ tempfile /;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
338 my ($fh, $fn) = tempfile();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
339 print $fh $response->content;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
340 $SO_FILE = $fn;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
341 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
342 print "Couldn't download SO file online...skipping validation.\n"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
343 . "HTTP Status was " . $response->status_line . "\n"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
344 and undef $SO_FILE
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
345 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
346 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
347
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
348 if ($SO_FILE) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
349
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
350
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
351 my (%terms, %syn);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
352
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
353 my $parser = Bio::OntologyIO->new( -format => "obo", -file => $SO_FILE );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
354 $ONTOLOGY = $parser->next_ontology();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
355
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
356 for ($ONTOLOGY->get_all_terms) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
357 my $feat = $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
358
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
359 $terms{$feat->name} = $feat->name;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
360 #$terms{$feat->name} = $feat;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
361
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
362 my @syn = $_->each_synonym;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
363
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
364 push @{$syn{$_}}, $feat->name for @syn;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
365 #push @{$syn{$_}}, $feat for @syn;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
366 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
367
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
368 $FTSOmap = \%terms;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
369 $FTSOsynonyms = \%syn;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
370
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
371 my %hardTerms = %{ $tm->FT_SO_map() };
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
372 map { $FTSOmap->{$_} ||= $hardTerms{$_} } keys %hardTerms;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
373
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
374 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
375 my %terms = %{ $tm->FT_SO_map() };
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
376 while (my ($k,$v) = each %terms) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
377 $FTSOmap->{$k} = ref($v) ? shift @$v : $v;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
378 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
379 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
380
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
381 $TYPE_MAP = $FTSOmap;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
382 $SYN_MAP = $FTSOsynonyms;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
383
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
384
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
385 # #convert $FTSOmap undefined to valid SO : moved to TypeMapper->map_types( -undefined => "region")
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
386
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
387 # stringify filter list if applicable
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
388 my $filter = join ' ', @filter if @filter;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
389
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
390 # determine input files
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
391 my $stdin=0; # dgg: let dir == stdin == '-' for pipe use
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
392 if ($dir && ($dir eq '-' || $dir eq 'stdin')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
393 $stdin=1; $dir=''; @files=('stdin');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
394
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
395 } elsif ( $dir ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
396 if ( -d $dir ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
397 opendir DIR, $dir or die "could not open $dir for reading: $!";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
398 @files = map { "$dir/$_";} grep { /\.gb.*/ } readdir DIR;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
399 closedir DIR;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
400 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
401 else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
402 die "$dir is not a directory\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
403 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
404 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
405 else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
406 @files = @ARGV;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
407 $dir = '';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
408 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
409
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
410 # we should have some files by now
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
411 pod2usage(2) unless @files;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
412
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
413
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
414 my $stdout=0; # dgg: let outdir == stdout == '-' for pipe use
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
415 if($outdir && ($outdir eq '-' || $outdir eq 'stdout')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
416 warn("std. output chosen: cannot split\n") if($split);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
417 warn("std. output chosen: cannot zip\n") if($zip);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
418 warn("std. output chosen: cannot nolump\n") if($nolump);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
419 $stdout=1; $lump=1; $split= 0; $zip= 0; # unless we pipe stdout thru gzip
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
420
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
421 } elsif ( $outdir && !-e $outdir ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
422 mkdir($outdir) or die "could not create directory $outdir: $!\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
423 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
424 elsif ( !$outdir ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
425 $outdir = $dir || '.';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
426 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
427
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
428 for my $file ( @files ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
429 # dgg ; allow 'stdin' / '-' input ?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
430 chomp $file;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
431 die "$! $file" unless($stdin || -e $file);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
432 print "# Input: $file\n" if($verbose);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
433
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
434 my ($lump_fh, $lumpfa_fh, $outfile, $outfa);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
435 if ($stdout) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
436 $lump_fh= *STDOUT; $lump="stdout$$";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
437 $outfa= "stdout$$.fa"; # this is a temp file ... see below
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
438 open $lumpfa_fh, ">$outfa" or die "Could not create a lump outfile called ($outfa) because ($!)\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
439
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
440 } elsif ( $lump ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
441 my ($vol,$dirs,$fileonly) = File::Spec->splitpath($file);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
442 $lump = File::Spec->catfile($outdir, $fileonly.'.gff');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
443 ($outfa = $lump) =~ s/\.gff/\.fa/;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
444 open $lump_fh, ">$lump" or die "Could not create a lump outfile called ($lump) because ($!)\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
445 open $lumpfa_fh, ">$outfa" or die "Could not create a lump outfile called ($outfa) because ($!)\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
446
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
447 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
448
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
449 # open input file, unzip if req'd
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
450 if ($stdin) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
451 *FH = *STDIN;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
452 } elsif ( $file =~ /\.gz/ ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
453 open FH, "gunzip -c $file |";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
454 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
455 else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
456 open FH, '<', $file;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
457 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
458
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
459 my $in = Bio::SeqIO->new(-fh => \*FH, -format => $FORMAT, -debug=>$DEBUG);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
460 my $gffio = Bio::Tools::GFF->new( -noparse => 1, -gff_version => $GFF_VERSION );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
461
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
462 while ( my $seq = $in->next_seq() ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
463 my $seq_name = $seq->accession_number;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
464 my $end = $seq->length;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
465 my @to_print;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
466
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
467 # arrange disposition of GFF output
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
468 $outfile = $lump || File::Spec->catfile($outdir, $seq_name.'.gff');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
469 my $out;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
470
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
471 if ( $lump ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
472 $outfile = $lump;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
473 $out = $lump_fh;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
474 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
475 else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
476 $outfile = File::Spec->catfile($outdir, $seq_name.'.gff');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
477 open $out, ">$outfile";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
478 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
479
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
480 # filter out unwanted features
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
481 my $source_feat= undef;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
482 my @source= filter($seq); $source_feat= $source[0];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
483
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
484 ($source_type,$source_feat)=
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
485 getSourceInfo( $seq, $source_type, $source_feat ) ;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
486 # always; here we build main prot $source_feat; # if @source;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
487
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
488 # abort if there are no features
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
489 warn "$seq_name has no features, skipping\n" and next
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
490 if !$seq->all_SeqFeatures;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
491
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
492
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
493 $FTSOmap->{'source'} = $source_type;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
494 ## $FTSOmap->{'CDS'}= $PROTEIN_TYPE; # handle this in gene_features
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
495
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
496 # construct a GFF header
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
497 # add: get source_type from attributes of source feature? chromosome=X tag
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
498 # also combine 1st ft line here with source ft from $seq ..
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
499 my($header,$info)= gff_header($seq_name, $end, $source_type, $source_feat);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
500 print $out $header;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
501 print "# working on $info\n" if($verbose);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
502
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
503 # unflatten gene graphs, apply SO types, etc; this also does TypeMapper ..
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
504 unflatten_seq($seq);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
505
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
506 # Note that we use our own get_all_SeqFeatures function
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
507 # to rescue cloned exons
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
508
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
509 @GFF_LINE_FEAT = ();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
510 for my $feature ( get_all_SeqFeatures($seq) ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
511
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
512 my $method = $feature->primary_tag;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
513 next if($SOURCEID =~/UniProt|swiss|trembl/i && $method ne $source_type);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
514
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
515 $feature->seq_id($seq->id) unless($feature->seq_id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
516 $feature->source_tag($SOURCEID);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
517
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
518 # dgg; need to convert some Genbank to GFF tags: note->Note; db_xref->Dbxref;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
519 ## also, pull any GO:000 ids from /note tag and put into Ontology_term
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
520 maptags2gff($feature);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
521
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
522 # current gene name. The unflattened gene features should be in order so any
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
523 # exons, CDSs, etc that follow will belong to this gene
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
524 my $gene_name;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
525 if ( $method eq 'gene' || $method eq 'pseudogene' ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
526 @to_print= print_held($out, $gffio, \@to_print);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
527 $gene_id = $gene_name= gene_name($feature);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
528 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
529 $gene_name= gene_name($feature);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
530 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
531
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
532 #?? should gene_name from /locus_tag,/gene,/product,/transposon=xxx
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
533 # be converted to or added as Name=xxx (if not ID= or as well)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
534 ## problematic: convert_to_name ($feature); # drops /locus_tag,/gene, tags
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
535 convert_to_name($feature);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
536
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
537 ## dgg: extended to protein|polypeptide
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
538 ## this test ($feature->has_tag('gene') ||) is not good: repeat_regions over genes
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
539 ## in yeast have that genbank tag; why?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
540 ## these include pseudogene ...
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
541
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
542 ## Note we also have mapped types to SO, so these RNA's are now transcripts:
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
543 # pseudomRNA => "pseudogenic_transcript",
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
544 # pseudotranscript" => "pseudogenic_transcript",
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
545 # misc_RNA=>'processed_transcript',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
546
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
547 warn "#at: $method $gene_id/$gene_name\n" if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
548
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
549 if ( $method =~ /(gene|RNA|CDS|exon|UTR|protein|polypeptide|transcript)/
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
550 || ( $gene_id && $gene_name eq $gene_id ) ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
551
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
552 my $action = gene_features($feature, $gene_id, $gene_name); # -1, 0, 1, 2 result
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
553 if ($action == GM_DUP_PART) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
554 # ignore, this is dupl. exon with new parent ...
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
555
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
556 } elsif ($action == GM_NOT_PART) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
557 add_generic_id( $feature, $gene_name, "nocount");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
558 my $gff = $gffio->gff_string($feature);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
559 push @GFF_LINE_FEAT, $feature;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
560 #print $out "$gff\n" if $gff;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
561
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
562 } elsif ($action > 0) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
563 # hold off print because exon etc. may get 2nd, 3rd parents
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
564 @to_print= print_held($out, $gffio, \@to_print) if ($action == GM_NEW_TOPLEVEL);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
565 push(@to_print, $feature);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
566 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
567
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
568 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
569
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
570 # otherwise handle as generic feats with IDHandler labels
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
571 else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
572 add_generic_id( $feature, $gene_name, "");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
573 my $gff= $gffio->gff_string($feature);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
574 push @GFF_LINE_FEAT, $feature;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
575 #print $out "$gff\n" if $gff;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
576 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
577 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
578
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
579 # don't like doing this after others; do after each new gene id?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
580 @to_print= print_held($out, $gffio, \@to_print);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
581
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
582 gff_validate(@GFF_LINE_FEAT);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
583
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
584 for my $feature (@GFF_LINE_FEAT) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
585 my $gff= $gffio->gff_string($feature);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
586 print $out "$gff\n" if $gff;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
587 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
588
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
589 # deal with the corresponding DNA
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
590 my ($fa_out,$fa_outfile);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
591 my $dna = $seq->seq;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
592 if($dna || %proteinfa) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
593 $method{'RESIDUES'} += length($dna);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
594 $dna =~ s/(\S{60})/$1\n/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
595 $dna .= "\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
596
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
597 if ($split) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
598 $fa_outfile = $outfile;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
599 $fa_outfile =~ s/gff$/fa/;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
600 open $fa_out, ">$fa_outfile" or die $!;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
601 print $fa_out ">$seq_name\n$dna" if $dna;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
602 foreach my $aid (sort keys %proteinfa) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
603 my $aa= delete $proteinfa{$aid};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
604 $method{'RESIDUES(tr)'} += length($aa);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
605 $aa =~ s/(\S{60})/$1\n/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
606 print $fa_out ">$aid\n$aa\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
607 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
608
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
609 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
610 else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
611 ## problem here when multiple GB Seqs in one file; all FASTA needs to go at end of $out
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
612 ## see e.g. Mouse: mm_ref_chr19.gbk has NT_082868 and NT_039687 parts in one .gbk
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
613 ## maybe write this to temp .fa then cat to end of lumped gff $out
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
614 print $lumpfa_fh ">$seq_name\n$dna" if $dna;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
615 foreach my $aid (sort keys %proteinfa) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
616 my $aa= delete $proteinfa{$aid};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
617 $method{'RESIDUES(tr)'} += length($aa);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
618 $aa =~ s/(\S{60})/$1\n/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
619 print $lumpfa_fh ">$aid\n$aa\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
620 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
621 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
622
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
623 %proteinfa=();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
624 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
625
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
626 if ( $zip && !$lump ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
627 system "gzip -f $outfile";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
628 system "gzip -f $fa_outfile" if($fa_outfile);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
629 $outfile .= '.gz';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
630 $fa_outfile .= '.gz' if $split;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
631 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
632
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
633 # print "\n>EOF\n" if($stdout); #?? need this if summary goes to stdout after FASTA
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
634 print "# GFF3 saved to $outfile" unless( !$verbose || $stdout || $lump);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
635 print ($split ? "; DNA saved to $fa_outfile\n" : "\n") unless($stdout|| $lump);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
636
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
637 # dgg: moved to after all inputs; here it prints cumulative sum for each record
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
638 #if ( $summary ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
639 # print "# Summary:\n# Feature\tCount\n# -------\t-----\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
640 #
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
641 # for ( keys %method ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
642 # print "# $_ $method{$_}\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
643 # }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
644 # print "# \n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
645 # }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
646
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
647 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
648
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
649 print "# GFF3 saved to $outfile\n" if( $verbose && $lump);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
650 if ( $summary ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
651 print "# Summary:\n# Feature\tCount\n# -------\t-----\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
652 for ( keys %method ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
653 print "# $_ $method{$_}\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
654 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
655 print "# \n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
656 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
657
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
658 ## FIXME for piped output w/ split FA files ...
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
659 close($lumpfa_fh) if $lumpfa_fh;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
660 if (!$split && $outfa && $lump_fh) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
661 print $lump_fh "##FASTA\n"; # GFF3 spec
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
662 open $lumpfa_fh, $outfa or warn "reading FA $outfa: $!";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
663 while( <$lumpfa_fh>) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
664 print $lump_fh $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
665 } # is $lump_fh still open?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
666 close($lumpfa_fh);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
667 unlink($outfa);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
668 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
669
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
670
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
671 if ( $zip && $lump ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
672 system "gzip -f $lump";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
673 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
674
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
675 close FH;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
676 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
677
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
678
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
679
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
680
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
681
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
682 sub typeorder {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
683 return 1 if ($_[0] =~ /gene/);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
684 return 2 if ($_[0] =~ /RNA|transcript/);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
685 return 3 if ($_[0] =~ /protein|peptide/);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
686 return 4 if ($_[0] =~ /exon|CDS/);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
687 return 3; # default before exon (smallest part)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
688 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
689
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
690 sub sort_by_feattype {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
691 my($at,$bt)= ($a->primary_tag, $b->primary_tag);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
692 return (typeorder($at) <=> typeorder($bt))
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
693 or ($at cmp $bt);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
694 ## or ($a->name() cmp $b->name());
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
695 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
696
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
697 sub print_held {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
698 my($out,$gffio,$to_print)= @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
699 return unless(@$to_print);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
700 @$to_print = sort sort_by_feattype @$to_print; # put exons after mRNA, otherwise chado loader chokes
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
701 while ( my $feature = shift @$to_print) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
702 my $gff= $gffio->gff_string($feature); # $gff =~ s/\'/./g; # dang bug in encode
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
703 push @GFF_LINE_FEAT, $feature;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
704 #print $out "$gff\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
705 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
706 return (); # @to_print
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
707 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
708
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
709 sub maptags2gff {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
710 my $f = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
711 ## should copy/move locus_tag to Alias, if not ID/Name/Alias already
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
712 # but see below /gene /locus_tag usage
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
713 foreach my $tag (keys %TAG_MAP) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
714 if ($f->has_tag($tag)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
715 my $newtag= $TAG_MAP{$tag};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
716 my @v= $f->get_tag_values($tag);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
717 $f->remove_tag($tag);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
718 $f->add_tag_value($newtag,@v);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
719
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
720 ## also, pull any GO:000 ids from /note tag and put into Ontology_term
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
721 ## ncbi syntax in CDS /note is now '[goid GO:0005886]' OR '[goid 0005624]'
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
722 if ($tag eq 'note') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
723 map { s/\[goid (\d+)/\[goid GO:$1/g; } @v;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
724 my @go= map { m/(GO:\d+)/g } @v;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
725 $f->add_tag_value('Ontology_term',@go) if(@go);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
726 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
727
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
728 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
729 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
730 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
731
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
732
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
733 sub getSourceInfo {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
734 my ($seq, $source_type, $sf) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
735
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
736 my $is_swiss= ($SOURCEID =~/UniProt|swiss|trembl/i);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
737 my $is_gene = ($SOURCEID =~/entrezgene/i);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
738 my $is_rich = (ref($seq) =~ /RichSeq/);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
739 my $seq_name= $seq->accession_number();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
740
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
741 unless($sf) { # make one
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
742 $source_type= $is_swiss ? $PROTEIN_TYPE
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
743 : $is_gene ? "eneg" # "gene" # "region" #
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
744 : $is_rich ? $seq->molecule : $source_type;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
745 $sf = Bio::SeqFeature::Generic->direct_new();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
746
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
747 my $len = $seq->length(); $len=1 if($len<1); my $start = 1; ##$start= $len if ($len<1);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
748 my $loc= $seq->can('location') ? $seq->location()
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
749 : new Bio::Location::Simple( -start => $start, -end => $len);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
750 $sf->location( $loc );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
751 $sf->primary_tag($source_type);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
752 $sf->source_tag($SOURCEID);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
753 $sf->seq_id( $seq_name);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
754 #? $sf->display_name($seq->id()); ## Name or Alias ?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
755 $sf->add_tag_value( Alias => $seq->id()); # unless id == accession
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
756 $seq->add_SeqFeature($sf);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
757 ## $source_feat= $sf;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
758 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
759
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
760 if ($sf->has_tag("chromosome")) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
761 $source_type= "chromosome";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
762 my ($chrname) = $sf->get_tag_values("chromosome");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
763 ## PROBLEM with Name <> ID, RefName for Gbrowse; use Alias instead
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
764 ## e.g. Mouse chr 19 has two IDs in NCBI genbank now
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
765 $sf->add_tag_value( Alias => $chrname );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
766 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
767
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
768 # pull GB Comment, Description for source ft ...
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
769 # add reference - can be long, not plain string...
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
770 warn "# $SOURCEID:$seq_name fields = ", join(",", $seq->annotation->get_all_annotation_keys()),"\n" if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
771 # GenBank fields: keyword,comment,reference,date_changed
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
772 # Entrezgene fields 850293 =ALIAS_SYMBOL,RefSeq status,chromosome,SGD,dblink,Entrez Gene Status,OntologyTerm,LOCUS_SYNONYM
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
773
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
774 # is this just for main $seq object or for all seqfeatures ?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
775 my %AnnotTagMap= (
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
776 'gene_name' => 'Alias',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
777 'ALIAS_SYMBOL' => 'Alias', # Entrezgene
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
778 'LOCUS_SYNONYM' => 'Alias', #?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
779 'symbol' => 'Alias',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
780 'synonym' => 'Alias',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
781 'dblink' => 'Dbxref',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
782 'product' => 'product',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
783 'Reference' => 'reference',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
784 'OntologyTerm' => 'Ontology_term',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
785 'comment' => 'Note',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
786 'comment1' => 'Note',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
787 # various map-type locations
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
788 # gene accession tag is named per source db !??
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
789 # 'Index terms' => keywords ??
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
790 );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
791
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
792
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
793 my ($desc)= $seq->annotation->get_Annotations("desc") || ( $seq->desc() );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
794 my ($date)= $seq->annotation->get_Annotations("dates")
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
795 || $seq->annotation->get_Annotations("update-date")
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
796 || $is_rich ? $seq->get_dates() : ();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
797 my ($comment)= $seq->annotation->get_Annotations("comment");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
798 my ($species)= $seq->annotation->get_Annotations("species");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
799 if (!$species
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
800 && $seq->can('species')
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
801 && defined $seq->species()
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
802 && $seq->species()->can('binomial') ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
803 $species= $seq->species()->binomial();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
804 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
805
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
806 # update source feature with main GB fields
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
807 $sf->add_tag_value( ID => $seq_name ) unless $sf->has_tag('ID');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
808 $sf->add_tag_value( Note => $desc ) if($desc && ! $sf->has_tag('Note'));
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
809 $sf->add_tag_value( organism => $species ) if($species && ! $sf->has_tag('organism'));
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
810 $sf->add_tag_value( comment1 => $comment ) if(!$is_swiss && $comment && ! $sf->has_tag('comment1'));
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
811 $sf->add_tag_value( date => $date ) if($date && ! $sf->has_tag('date'));
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
812
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
813 $sf->add_tag_value( Dbxref => $SOURCEID.':'.$seq_name ) if $is_swiss || $is_gene;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
814
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
815 foreach my $atag (sort keys %AnnotTagMap) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
816 my $gtag= $AnnotTagMap{$atag}; next unless($gtag);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
817 my @anno = map{
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
818 if (ref $_ && $_->can('get_all_values')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
819 split( /[,;] */, join ";", $_->get_all_values)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
820 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
821 elsif (ref $_ && $_->can('display_text')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
822 split( /[,;] */, $_->display_text)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
823 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
824 elsif (ref $_ && $_->can('value')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
825 split( /[,;] */, $_->value)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
826 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
827 else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
828 ();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
829 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
830 } $seq->annotation->get_Annotations($atag);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
831 foreach(@anno) { $sf->add_tag_value( $gtag => $_ ); }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
832 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
833
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
834 #my @genes = map{ split( /[,;] */, "$_"); } $seq->annotation->get_Annotations('gene_name');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
835 #$sf->add_tag_value( Alias => $_ ) foreach(@genes);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
836 #
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
837 #my @dblink= map { "$_"; } $seq->annotation->get_Annotations("dblink"); # add @all
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
838 #$sf->add_tag_value( Dbxref => $_ ) foreach(@dblink);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
839
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
840 return (wantarray)? ($source_type,$sf) : $source_type; #?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
841 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
842
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
843
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
844 sub gene_features {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
845 my ($f, $gene_id, $genelinkID) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
846 local $_ = $f->primary_tag;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
847 $method{$_}++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
848
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
849 if ( /gene/ ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
850 $f->add_tag_value( ID => $gene_id ) unless($f->has_tag('ID')); # check is same value!?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
851 $tnum = $rnum= 0; $ncrna_id= $rna_id = '';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
852 return GM_NEW_TOPLEVEL;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
853
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
854 } elsif ( /mRNA/ ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
855 return GM_NOT_PART unless $gene_id;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
856 return GM_NOT_PART if($genelinkID && $genelinkID ne $gene_id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
857 ($rna_id = $gene_id ) =~ s/gene/mRNA/;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
858 $rna_id .= '.t0' . ++$tnum;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
859 $f->add_tag_value( ID => $rna_id );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
860 $f->add_tag_value( Parent => $gene_id );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
861
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
862 } elsif ( /RNA|transcript/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
863 ## misc_RNA here; missing exons ... flattener problem?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
864 # all of {t,nc,sn}RNA can have gene models now
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
865 ## but problem in Worm chr: mRNA > misc_RNA > CDS with same locus tag
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
866 ## CDS needs to use mRNA, not misc_RNA, rna_id ...
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
867 ## also need to fix cases where tRNA,... lack a 'gene' parent: make this one top-level
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
868
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
869 if($gene_id) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
870 return GM_NOT_PART if($genelinkID && $genelinkID ne $gene_id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
871 ($ncrna_id = $gene_id) =~ s/gene/ncRNA/;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
872 $ncrna_id .= '.r0' . ++$rnum;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
873 $f->add_tag_value( Parent => $gene_id );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
874 $f->add_tag_value( ID => $ncrna_id );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
875 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
876 unless ($f->has_tag('ID')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
877 if($genelinkID) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
878 $f->add_tag_value( ID => $genelinkID ) ;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
879 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
880 $idh->generate_unique_persistent_id($f);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
881 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
882 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
883 ($ncrna_id)= $f->get_tag_values('ID');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
884 return GM_NEW_TOPLEVEL;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
885 # this feat now acts as gene-top-level; need to print @to_print to flush prior exons?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
886 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
887
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
888 } elsif ( /exon/ ) { # can belong to any kind of RNA
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
889 return GM_NOT_PART unless ($rna_id||$ncrna_id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
890 return GM_NOT_PART if($genelinkID && $genelinkID ne $gene_id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
891 ## we are getting duplicate Parents here, which chokes chado loader, with reason...
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
892 ## problem is when mRNA and ncRNA have same exons, both ids are active, called twice
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
893 ## check all Parents
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
894 for my $expar ($rna_id, $ncrna_id) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
895 next unless($expar);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
896 if ( $exonpar{$expar} and $f->has_tag('Parent') ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
897 my @vals = $f->get_tag_values('Parent');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
898 next if (grep {$expar eq $_} @vals);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
899 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
900 $exonpar{$expar}++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
901 $f->add_tag_value( Parent => $expar);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
902 # last; #? could be both
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
903 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
904 # now we can skip cloned exons
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
905 # dgg note: multiple parents get added and printed for each unique exon
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
906 return GM_DUP_PART if ++$seen{$f} > 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
907
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
908 } elsif ( /CDS|protein|polypeptide/ ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
909 return GM_NOT_PART unless $rna_id; ## ignore $ncrna_id ??
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
910 return GM_NOT_PART if($genelinkID && $genelinkID ne $gene_id); #??
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
911 (my $pro_id = $rna_id) =~ s/\.t/\.p/;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
912
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
913 if( ! $CDSkeep && /CDS/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
914 $f->primary_tag($PROTEIN_TYPE);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
915
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
916 ## duplicate problem is Location ..
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
917 if ($f->location->isa("Bio::Location::SplitLocationI")) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
918 # my($b,$e)=($f->start, $f->end); # is this all we need?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
919 my($b,$e)=(-1,0);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
920 foreach my $l ($f->location->each_Location) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
921 $b = $l->start if($b<0 || $b > $l->start);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
922 $e = $l->end if($e < $l->end);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
923 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
924 $f->location( Bio::Location::Simple->new(
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
925 -start => $b, -end => $e, -strand => $f->strand) );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
926 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
927
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
928 $f->add_tag_value( Derives_from => $rna_id );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
929 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
930 else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
931 $f->add_tag_value( Parent => $rna_id );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
932 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
933
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
934 $f->add_tag_value( ID => $pro_id );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
935
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
936 move_translation_fasta($f, $pro_id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
937 #if( $f->has_tag('translation')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
938 # my ($aa) = $f->get_tag_values("translation");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
939 # $proteinfa{$pro_id}= $aa;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
940 # $f->remove_tag("translation");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
941 # $f->add_tag_value("translation","length.".length($aa)); # hack for odd chado gbl problem
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
942 #}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
943 } elsif ( /region/ ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
944 $f->primary_tag('gene_component_region');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
945 $f->add_tag_value( Parent => $gene_id );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
946 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
947 return GM_NOT_PART unless $gene_id;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
948 $f->add_tag_value( Parent => $gene_id );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
949 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
950
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
951 ## return GM_DUP_PART if /exon/ && ++$seen{$f} > 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
952
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
953 return GM_NEW_PART;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
954 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
955
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
956 ## was generic_features > add_generic_id
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
957 sub add_generic_id {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
958 my ($f, $ft_name, $flags) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
959 my $method = $f->primary_tag;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
960 $method{$method}++ unless($flags =~ /nocount/); ## double counts GM_NOT_PART from above
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
961
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
962 if ($f->has_tag('ID')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
963
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
964 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
965 elsif ( $f->has_tag($method) ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
966 my ($name) = $f->get_tag_values($method);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
967 $f->add_tag_value( ID => "$method:$name" );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
968 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
969 elsif($ft_name) { # is this unique ?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
970 $f->add_tag_value( ID => $ft_name );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
971 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
972 else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
973 $idh->generate_unique_persistent_id($f);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
974 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
975
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
976 move_translation_fasta( $f, ($f->get_tag_values("ID"))[0] )
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
977 if($method =~ /CDS/);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
978
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
979 # return $io->gff_string($f);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
980 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
981
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
982 sub move_translation_fasta {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
983 my ($f, $ft_id) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
984 if( $ft_id && $f->has_tag('translation') ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
985 my ($aa) = $f->get_tag_values("translation");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
986 if($aa && $aa !~ /^length/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
987 $proteinfa{$ft_id}= $aa;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
988 $f->remove_tag("translation");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
989 $f->add_tag_value("translation","length.".length($aa)); # hack for odd chado gbl problem
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
990 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
991 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
992 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
993
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
994 sub gff_header {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
995 my ($name, $end, $source_type, $source_feat) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
996 $source_type ||= "region";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
997
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
998 my $info = "$source_type:$name";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
999 my $head = "##gff-version $GFF_VERSION\n".
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1000 "##sequence-region $name 1 $end\n".
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1001 "# conversion-by bp_genbank2gff3.pl\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1002 if ($source_feat) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1003 ## dgg: these header comment fields are not useful when have multi-records, diff organisms
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1004 for my $key (qw(organism Note date)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1005 my $value;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1006 if ($source_feat->has_tag($key)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1007 ($value) = $source_feat->get_tag_values($key);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1008 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1009 if ($value) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1010 $head .= "# $key $value\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1011 $info .= ", $value";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1012 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1013 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1014 $head = "" if $didheader;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1015 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1016 $head .= "$name\t$SOURCEID\t$source_type\t1\t$end\t.\t.\t.\tID=$name\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1017 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1018 $didheader++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1019 return (wantarray) ? ($head,$info) : $head;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1020 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1021
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1022 sub unflatten_seq {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1023 my $seq = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1024
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1025 ## print "# working on $source_type:", $seq->accession, "\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1026 my $uh_oh = "Possible gene unflattening error with" . $seq->accession_number .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1027 ": consult STDERR\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1028
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1029 eval {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1030 $unflattener->unflatten_seq( -seq => $seq,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1031 -noinfer => $noinfer,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1032 -use_magic => 1 );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1033 };
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1034
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1035 # deal with unflattening errors
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1036 if ( $@ ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1037 warn $seq->accession_number . " Unflattening error:\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1038 warn "Details: $@\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1039 print "# ".$uh_oh;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1040 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1041
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1042 return 0 if !$seq || !$seq->all_SeqFeatures;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1043
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1044 # map feature types to the sequence ontology
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1045 ## $tm->map_types_to_SO( -seq => $seq );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1046 #$tm->map_types( -seq => $seq, -type_map => $FTSOmap, -undefined => "region" ); #dgg
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1047
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1048 map_types(
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1049 $tm,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1050 -seq => $seq,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1051 -type_map => $FTSOmap,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1052 -syn_map => $FTSOsynonyms,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1053 -undefined => "region"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1054 ); #nml
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1055
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1056 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1057
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1058 sub filter {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1059 my $seq = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1060 ## return unless $filter;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1061 my @feats;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1062 my @sources; # dgg; pick source features here; only 1 always?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1063 if ($filter) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1064 for my $f ( $seq->remove_SeqFeatures ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1065 my $m = $f->primary_tag;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1066 push @sources, $f if ($m eq 'source'); # dgg? but leave in @feats ?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1067 push @feats, $f unless $filter =~ /$m/i;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1068 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1069 $seq->add_SeqFeature($_) foreach @feats;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1070 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1071 for my $f ( $seq->get_SeqFeatures ){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1072 my $m = $f->primary_tag;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1073 push @sources, $f if ($m eq 'source'); # dgg? but leave in @feats ?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1074 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1075 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1076
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1077 return @sources;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1078 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1079
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1080
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1081 # The default behaviour of Bio::FeatureHolderI:get_all_SeqFeatures
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1082 # changed to filter out cloned features. We have to implement the old
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1083 # method. These two subroutines were adapted from the v1.4 Bio::FeatureHolderI
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1084 sub get_all_SeqFeatures {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1085 my $seq = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1086 my @flatarr;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1087
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1088 foreach my $feat ( $seq->get_SeqFeatures ){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1089 push(@flatarr,$feat);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1090 _add_flattened_SeqFeatures(\@flatarr,$feat);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1091 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1092 return @flatarr;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1093 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1094
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1095 sub gene_name {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1096 my $g = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1097 my $gene_id = ''; # zero it;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1098
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1099 if ($g->has_tag('locus_tag')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1100 ($gene_id) = $g->get_tag_values('locus_tag');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1101 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1102
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1103 elsif ($g->has_tag('gene')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1104 ($gene_id) = $g->get_tag_values('gene');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1105 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1106 elsif ($g->has_tag('ID')) { # for non-Genbank > Entrezgene
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1107 ($gene_id) = $g->get_tag_values('ID');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1108 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1109
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1110 ## See Unflattener comment:
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1111 # on rare occasions, records will have no /gene or /locus_tag
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1112 # but it WILL have /product tags. These serve the same purpose
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1113 # for grouping. For an example, see AY763288 (also in t/data)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1114 # eg. product=tRNA-Asp ; product=similar to crooked neck protein
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1115 elsif ($g->has_tag('product')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1116 my ($name)= $g->get_tag_values('product');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1117 ($gene_id) = $name unless($name =~ / /); # a description not name
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1118 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1119
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1120 ## dgg; also handle transposon=xxxx ID/name
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1121 # ID=GenBank:repeat_region:NC_004353:1278337:1281302;transposon=HeT-A{}1685;Dbxref=FLYBASE:FBti0059746
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1122 elsif ($g->has_tag('transposon')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1123 my ($name)= $g->get_tag_values('transposon');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1124 ($gene_id) = $name unless($name =~ / /); # a description not name
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1125 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1126
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1127 return $gene_id;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1128 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1129
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1130 # same list as gene_name .. change tag to generic Name
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1131 sub convert_to_name {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1132 my $g = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1133 my $gene_id = ''; # zero it;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1134
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1135 if ($g->has_tag('gene')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1136 ($gene_id) = $g->get_tag_values('gene');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1137 $g->remove_tag('gene');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1138 $g->add_tag_value('Name', $gene_id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1139 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1140 elsif ($g->has_tag('locus_tag')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1141 ($gene_id) = $g->get_tag_values('locus_tag');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1142 $g->remove_tag('locus_tag');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1143 $g->add_tag_value('Name', $gene_id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1144 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1145
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1146 elsif ($g->has_tag('product')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1147 my ($name)= $g->get_tag_values('product');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1148 ($gene_id) = $name unless($name =~ / /); # a description not name
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1149 ## $g->remove_tag('product');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1150 $g->add_tag_value('Name', $gene_id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1151 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1152
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1153 elsif ($g->has_tag('transposon')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1154 my ($name)= $g->get_tag_values('transposon');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1155 ($gene_id) = $name unless($name =~ / /); # a description not name
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1156 ## $g->remove_tag('transposon');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1157 $g->add_tag_value('Name', $gene_id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1158 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1159 elsif ($g->has_tag('ID')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1160 my ($name)= $g->get_tag_values('ID');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1161 $g->add_tag_value('Name', $name);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1162 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1163 return $gene_id;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1164 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1165
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1166
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1167 sub _add_flattened_SeqFeatures {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1168 my ($arrayref,$feat) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1169 my @subs = ();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1170
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1171 if ($feat->isa("Bio::FeatureHolderI")) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1172 @subs = $feat->get_SeqFeatures;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1173 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1174 elsif ($feat->isa("Bio::SeqFeatureI")) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1175 @subs = $feat->sub_SeqFeature;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1176 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1177 else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1178 warn ref($feat)." is neither a FeatureHolderI nor a SeqFeatureI. ".
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1179 "Don't know how to flatten.";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1180 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1181
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1182 for my $sub (@subs) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1183 push(@$arrayref,$sub);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1184 _add_flattened_SeqFeatures($arrayref,$sub);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1185 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1186
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1187 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1188
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1189 sub map_types {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1190
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1191 my ($self, @args) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1192
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1193 my($sf, $seq, $type_map, $syn_map, $undefmap) =
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1194 $self->_rearrange([qw(FEATURE
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1195 SEQ
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1196 TYPE_MAP
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1197 SYN_MAP
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1198 UNDEFINED
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1199 )],
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1200 @args);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1201
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1202 if (!$sf && !$seq) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1203 $self->throw("you need to pass in either -feature or -seq");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1204 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1205
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1206 my @sfs = ($sf);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1207 if ($seq) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1208 $seq->isa("Bio::SeqI") || $self->throw("$seq NOT A SeqI");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1209 @sfs = $seq->get_all_SeqFeatures;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1210 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1211 $type_map = $type_map || $self->typemap; # dgg: was type_map;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1212 foreach my $feat (@sfs) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1213
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1214 $feat->isa("Bio::SeqFeatureI") || $self->throw("$feat NOT A SeqFeatureI");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1215 $feat->isa("Bio::FeatureHolderI") || $self->throw("$feat NOT A FeatureHolderI");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1216
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1217 my $primary_tag = $feat->primary_tag;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1218
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1219 #if ($primary_tag =~ /^pseudo(.*)$/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1220 # $primary_tag = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1221 # $feat->primary_tag($primary_tag);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1222 #}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1223
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1224 my $mtype = $type_map->{$primary_tag};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1225 if ($mtype) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1226 if (ref($mtype)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1227 if (ref($mtype) eq 'ARRAY') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1228 my $soID;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1229 ($mtype, $soID) = @$mtype;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1230
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1231 if ($soID && ref($ONTOLOGY)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1232 my ($term) = $ONTOLOGY->find_terms(-identifier => $soID);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1233 $mtype = $term->name if $term;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1234 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1235 # if SO ID is undefined AND we have an ontology to search, we want to delete
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1236 # the feature type hash entry in order to force a fuzzy search
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1237 elsif (! defined $soID && ref($ONTOLOGY)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1238 undef $mtype;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1239 delete $type_map->{$primary_tag};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1240 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1241 elsif ($undefmap && $mtype eq 'undefined') { # dgg
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1242 $mtype= $undefmap;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1243 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1244
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1245 $type_map->{$primary_tag} = $mtype if $mtype;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1246 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1247 elsif (ref($mtype) eq 'CODE') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1248 $mtype = $mtype->($feat);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1249 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1250 else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1251 $self->throw('must be scalar or CODE ref');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1252 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1253 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1254 elsif ($undefmap && $mtype eq 'undefined') { # dgg
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1255 $mtype= $undefmap;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1256 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1257 $feat->primary_tag($mtype);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1258 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1259
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1260 if ($CONF) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1261 conf_read();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1262 my %perfect_matches;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1263 while (my ($p_tag,$rules) = each %$YAML) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1264 RULE:
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1265 for my $rule (@$rules) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1266 for my $tags (@$rule) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1267 while (my ($tag,$values) = each %$tags) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1268 for my $value (@$values) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1269 if ($feat->has_tag($tag)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1270 for ($feat->get_tag_values($tag)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1271 next RULE unless $_ =~ /\Q$value\E/;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1272 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1273 } elsif ($tag eq 'primary_tag') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1274 next RULE unless $value eq
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1275 $feat->primary_tag;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1276 } elsif ($tag eq 'location') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1277 next RULE unless $value eq
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1278 $feat->start.'..'.$feat->end;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1279 } else { next RULE }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1280 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1281 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1282 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1283 $perfect_matches{$p_tag}++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1284 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1285 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1286 if (scalar(keys %perfect_matches) == 1) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1287 $mtype = $_ for keys %perfect_matches;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1288 } elsif (scalar(keys %perfect_matches) > 1) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1289 warn "There are conflicting rules in the config file for the" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1290 " following types: ";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1291 warn "\t$_\n" for keys %perfect_matches;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1292 warn "Until conflict resolution is built into the converter," .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1293 " you will have to manually edit the config file to remove the" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1294 " conflict. Sorry :(. Skipping user preference for this entry";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1295 sleep(2);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1296 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1297 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1298
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1299 if ( ! $mtype && $syn_map) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1300 if ($feat->has_tag('note')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1301
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1302 my @all_matches;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1303
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1304 my @note = $feat->each_tag_value('note');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1305
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1306 for my $k (keys %$syn_map) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1307
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1308 if ($k =~ /"(.+)"/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1309
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1310 my $syn = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1311
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1312 for my $note (@note) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1313
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1314 # look through the notes to see if the description
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1315 # is an exact match for synonyms
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1316 if ( $syn eq $note ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1317
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1318 my @map = @{$syn_map->{$k}};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1319
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1320
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1321 my $best_guess = $map[0];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1322
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1323 unshift @{$all_matches[-1]}, [$best_guess];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1324
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1325 $mtype = $MANUAL
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1326 ? manual_curation($feat, $best_guess, \@all_matches)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1327 : $best_guess;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1328
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1329 print '#' x 78 . "\nGuessing the proper SO term for GenBank"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1330 . " entry:\n\n" . GenBank_entry($feat) . "\nis:\t$mtype\n"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1331 . '#' x 78 . "\n\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1332
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1333 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1334 # check both primary tag and and note against
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1335 # SO synonyms for best matching description
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1336
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1337 SO_fuzzy_match( $k, $primary_tag, $note, $syn, \@all_matches);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1338 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1339
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1340 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1341 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1342 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1343
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1344 #unless ($mtype) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1345 for my $note (@note) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1346 for my $name (values %$type_map) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1347 # check primary tag against SO names for best matching
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1348 # descriptions //NML also need to check against
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1349 # definition && camel case split terms
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1350
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1351 SO_fuzzy_match($name, $primary_tag, $note, $name, \@all_matches);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1352 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1353 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1354 #}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1355
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1356 if (scalar(@all_matches) && !$mtype) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1357
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1358 my $top_matches = first { defined $_ } @{$all_matches[-1]};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1359
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1360 my $best_guess = $top_matches->[0];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1361
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1362
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1363
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1364 # if guess has quotes, it is a synonym term. we need to
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1365 # look up the corresponding name term
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1366 # otherwise, guess is a name, so we can use it directly
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1367 if ($best_guess =~ /"(.+)"/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1368
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1369 $best_guess = $syn_map->{$best_guess}->[0];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1370
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1371 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1372
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1373 @RETURN = @all_matches;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1374 $mtype = $MANUAL
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1375 ? manual_curation($feat, $best_guess, \@all_matches)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1376 : $best_guess;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1377
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1378 print '#' x 78 . "\nGuessing the proper SO term for GenBank"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1379 . " entry:\n\n" . GenBank_entry($feat) . "\nis:\t$mtype\n"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1380 . '#' x 78 . "\n\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1381
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1382 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1383 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1384 $mtype ||= $undefmap;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1385 $feat->primary_tag($mtype);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1386 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1387 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1388
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1389
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1390 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1391
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1392 sub SO_fuzzy_match {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1393
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1394 my $candidate = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1395 my $primary_tag = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1396 my $note = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1397 my $SO_terms = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1398 my $best_matches_ref = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1399 my $modifier = shift;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1400
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1401 $modifier ||= '';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1402
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1403 my @feat_terms;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1404
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1405 for ( split(" |_", $primary_tag) ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1406 #my @camelCase = /(?:[A-Z]|[a-z])(?:[A-Z]+|[a-z]*)(?=$|[A-Z])/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1407 my @camelCase = /(?:[A-Z]|[a-z])(?:[A-Z]+|[a-z]*)(?=$|[A-Z]|[;:.,])/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1408 push @feat_terms, @camelCase;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1409 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1410
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1411 for ( split(" |_", $note) ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1412 #my @camelCase = /(?:[A-Z]|[a-z])(?:[A-Z]+|[a-z]*)(?=$|[A-Z])/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1413 #my @camelCase = /(?:[A-Z]|[a-z])(?:[A-Z]+|[a-z]*)(?=$|[A-Z]|[;:.,])/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1414 (my $word = $_) =~ s/[;:.,]//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1415 push @feat_terms, $word;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1416 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1417
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1418
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1419 my @SO_terms = split(" |_", $SO_terms);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1420
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1421 # fuzzy match works on a simple point system. When 2 words match,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1422 # the $plus counter adds one. When they don't, the $minus counter adds
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1423 # one. This is used to sort similar matches together. Better matches
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1424 # are found at the end of the array, near the top.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1425
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1426 # NML: can we improve best match by using synonym tags
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1427 # EXACT,RELATED,NARROW,BROAD?
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1428
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1429 my ($plus, $minus) = (0, 0);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1430 my %feat_terms;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1431 my %SO_terms;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1432
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1433 #unique terms
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1434 map {$feat_terms{$_} = 1} @feat_terms;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1435 map {$SO_terms{$_} = 1} @SO_terms;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1436
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1437 for my $st (keys %SO_terms) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1438 for my $ft (keys %feat_terms) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1439
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1440 ($st =~ m/$modifier\Q$ft\E/) ? $plus++ : $minus++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1441
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1442 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1443 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1444
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1445 push @{$$best_matches_ref[$plus][$minus]}, $candidate if $plus;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1446
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1447 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1448
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1449 sub manual_curation {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1450
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1451 my ($feat, $default_opt, $all_matches) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1452
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1453 my @all_matches = @$all_matches;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1454
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1455 # convert all SO synonyms into names and filter
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1456 # all matches into unique term list because
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1457 # synonyms can map to multiple duplicate names
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1458
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1459 my (@unique_SO_terms, %seen);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1460 for (reverse @all_matches) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1461 for (@$_) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1462 for (@$_) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1463 #my @names;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1464 if ($_ =~ /"(.+)"/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1465 for (@{$SYN_MAP->{$_}}) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1466 push @unique_SO_terms, $_ unless $seen{$_};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1467 $seen{$_}++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1468 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1469 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1470 push @unique_SO_terms, $_ unless $seen{$_};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1471 $seen{$_}++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1472 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1473 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1474 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1475 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1476
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1477 my $s = scalar(@unique_SO_terms);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1478
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1479 my $choice = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1480
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1481 my $more =
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1482 "[a]uto : automatic input (selects best guess for remaining entries)\r" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1483 "[f]ind : search for other SO terms matching your query (e.g. f gene)\r" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1484 "[i]nput : add a specific term\r" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1485 "[r]eset : reset to the beginning of matches\r" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1486 "[s]kip : skip this entry (selects best guess for this entry)\r"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1487 ;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1488
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1489 $more .=
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1490 "[n]ext : view the next ".OPTION_CYCLE." terms\r" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1491 "[p]rev : view the previous ".OPTION_CYCLE." terms" if ($s > OPTION_CYCLE);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1492
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1493 my $msg = #"\n\n" . '-' x 156 . "\n"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1494 "The converter found $s possible matches for the following GenBank entry: ";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1495
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1496 my $directions =
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1497 "Type a number to select the SO term that best matches"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1498 . " the genbank entry, or use any of the following options:\r" . '_' x 76 . "\r$more";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1499
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1500
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1501 # lookup filtered list to pull out definitions
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1502 my @options = map {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1503 my $term = $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1504 my %term;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1505 for (['name', 'name'], ['def', 'definition'], ['synonym',
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1506 'each_synonym']) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1507 my ($label, $method) = @$_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1508 $term{$label} = \@{[$term->$method]};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1509 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1510 [++$choice, $_->name, ($_->definition || 'none'), \%term, $_->each_synonym ];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1511 } map { $ONTOLOGY->find_terms(-name => $_) } @unique_SO_terms;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1512
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1513
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1514 my $option = options_cycle(0, OPTION_CYCLE, $msg, $feat, $directions,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1515 $default_opt, @options);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1516
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1517 if ($option eq 'skip') { return $default_opt
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1518 } elsif ($option eq 'auto') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1519 $MANUAL = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1520 return $default_opt;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1521 } else { return $option }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1522
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1523 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1524
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1525 sub options_cycle {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1526
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1527 my ($start, $stop, $msg, $feat, $directions, $best_guess, @opt) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1528
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1529 #NML: really should only call GenBank_entry once. Will need to change
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1530 #method to return array & shift off header
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1531 my $entry = GenBank_entry($feat, "\r");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1532
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1533 my $total = scalar(@opt);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1534
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1535 ($start,$stop) = (0, OPTION_CYCLE)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1536 if ( ($start < 0) && ($stop > 0) );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1537
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1538 ($start,$stop) = (0, OPTION_CYCLE)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1539 if ( ( ($stop - $start) < OPTION_CYCLE ) && $stop < $total);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1540
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1541 ($start,$stop) = ($total - OPTION_CYCLE, $total) if $start < 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1542 ($start,$stop) = (0, OPTION_CYCLE) if $start >= $total;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1543
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1544 $stop = $total if $stop > $total;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1545
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1546 my $dir_copy = $directions;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1547 my $msg_copy = $msg;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1548 my $format = "format STDOUT = \n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1549 '-' x 156 . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1550 '^' . '<' x 77 . '| Available Commands:' . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1551 '$msg_copy' . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1552 '-' x 156 . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1553 ' ' x 78 . "|\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1554 '^' . '<' x 77 . '| ^' . '<' x 75 . '~' . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1555 '$entry' . ' ' x 74 . '$dir_copy,' . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1556 (' ' x 20 . '^' . '<' x 57 . '| ^' . '<' x 75 . '~' . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1557 ' ' x 20 . '$entry,' . ' ' x 53 . '$dir_copy,' . "\n") x 1000 . ".\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1558
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1559 {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1560 # eval throws redefined warning that breaks formatting.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1561 # Turning off warnings just for the eval to fix this.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1562 no warnings 'redefine';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1563 eval $format;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1564 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1565
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1566 write;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1567
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1568 print '-' x 156 . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1569 'Showing results ' . ( $stop ? ( $start + 1 ) : $start ) .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1570 " - $stop of possible SO term matches: (best guess is \"$best_guess\")" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1571 "\n" . '-' x 156 . "\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1572
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1573 for (my $i = $start; $i < $stop; $i+=2) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1574
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1575 my ($left, $right) = @opt[$i,$i+1];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1576
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1577 my ($nL, $nmL, $descL, $termL, @synL) = @$left;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1578
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1579 #odd numbered lists can cause fatal undefined errors, so check
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1580 #to make sure we have data
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1581
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1582 my ($nR, $nmR, $descR, $termR, @synR) = ref($right) ? @$right : (undef, undef, undef);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1583
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1584
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1585 my $format = "format STDOUT = \n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1586
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1587 $format .=
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1588 ' ' x 78 . "|\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1589
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1590 '@>>: name: ^' . '<' x 64 . '~' . ' |' .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1591 ( ref($right) ? ('@>>: name: ^' . '<' x 64 . '~' ) : '' ) . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1592 '$nL,' . ' ' x 7 . '$nmL,' .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1593 ( ref($right) ? (' ' x 63 . '$nR,' . ' ' x 7 . "\$nmR,") : '' ) . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1594
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1595 ' ' x 11 . '^' . '<' x 61 . '...~' . ' |' .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1596 (ref($right) ? (' ^' . '<' x 61 . '...~') : '') . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1597 ' ' x 11 . '$nmL,' .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1598 (ref($right) ? (' ' x 74 . '$nmR,') : '') . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1599 #' ' x 78 . '|' . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1600
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1601
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1602 ' def: ^' . '<' x 65 . ' |' .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1603 (ref($right) ? (' def: ^' . '<' x 64 . '~') : '') . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1604 ' ' x 11 . '$descL,' .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1605 (ref($right) ? (' ' x 72 . '$descR,') : '') . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1606
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1607
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1608 (' ^' . '<' x 65 . ' |' .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1609 (ref($right) ? (' ^' . '<' x 64 . '~') : '') . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1610 ' ' x 11 . '$descL,' .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1611 (ref($right) ? (' ' x 72 . '$descR,') : '') . "\n") x 5 .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1612
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1613
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1614 ' ^' . '<' x 61 . '...~ |' .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1615 (ref($right) ? (' ^' . '<' x 61 . '...~') : '') . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1616 ' ' x 11 . '$descL,' .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1617 (ref($right) ? (' ' x 72 . '$descR,') : '') . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1618
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1619 ".\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1620
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1621 {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1622 # eval throws redefined warning that breaks formatting.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1623 # Turning off warnings just for the eval to fix this.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1624 no warnings 'redefine';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1625 eval $format;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1626 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1627 write;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1628
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1629 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1630 print '-' x 156 . "\nenter a command:";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1631
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1632 while (<STDIN>) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1633
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1634 (my $input = $_) =~ s/\s+$//;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1635
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1636 if ($input =~ /^\d+$/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1637 if ( $input && defined $opt[$input-1] ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1638 return $opt[$input-1]->[1]
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1639 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1640 print "\nThat number is not an option. Please enter a valid number.\n:";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1641 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1642 } elsif ($input =~ /^n/i | $input =~ /next/i ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1643 return options_cycle($start + OPTION_CYCLE, $stop + OPTION_CYCLE, $msg,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1644 $feat, $directions, $best_guess, @opt)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1645 } elsif ($input =~ /^p/i | $input =~ /prev/i ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1646 return options_cycle($start - OPTION_CYCLE, $stop - OPTION_CYCLE, $msg,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1647 $feat, $directions, $best_guess, @opt)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1648 } elsif ( $input =~ /^s/i || $input =~ /skip/i ) { return 'skip'
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1649 } elsif ( $input =~ /^a/i || $input =~ /auto/i ) { return 'auto'
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1650 } elsif ( $input =~ /^r/i || $input =~ /reset/i ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1651 return manual_curation($feat, $best_guess, \@RETURN );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1652 } elsif ( $input =~ /^f/i || $input =~ /find/i ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1653
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1654 my ($query, @query_results);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1655
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1656 if ($input =~ /(?:^f|find)\s+?(.*?)$/) { $query = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1657 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1658
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1659 #do a SO search
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1660 print "Type your search query\n:";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1661 while (<STDIN>) { chomp($query = $_); last }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1662 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1663
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1664 for (keys(%$TYPE_MAP), keys(%$SYN_MAP)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1665 SO_fuzzy_match($_, $query, '', $_, \@query_results, '(?i)');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1666 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1667
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1668 return manual_curation($feat, $best_guess, \@query_results);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1669
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1670 } elsif ( $input =~ /^i/i || $input =~ /input/i ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1671
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1672 #NML fast input for later
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1673 #my $query;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1674 #if ($input =~ /(?:^i|input)\s+?(.*?)$/) { $query = $1 };
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1675
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1676 #manual input
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1677 print "Type the term you want to use\n:";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1678 while (<STDIN>) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1679 chomp(my $input = $_);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1680
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1681 if (! $TYPE_MAP->{$input}) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1682
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1683 print "\"$input\" doesn't appear to be a valid SO term. Are ".
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1684 "you sure you want to use it? (y or n)\n:";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1685
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1686 while (<STDIN>) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1687
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1688 chomp(my $choice = $_);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1689
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1690 if ($choice eq 'y') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1691 print
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1692 "\nWould you like to save your preference for " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1693 "future use (so you don't have to redo manual " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1694 "curation for this feature everytime you run " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1695 "the converter)? (y or n)\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1696
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1697 #NML: all these while loops are a mess. Really should condense it.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1698 while (<STDIN>) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1699
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1700 chomp(my $choice = $_);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1701
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1702 if ($choice eq 'y') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1703 curation_save($feat, $input);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1704 return $input;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1705 } elsif ($choice eq 'n') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1706 return $input
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1707 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1708 print "\nDidn't recognize that command. Please " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1709 "type y or n.\n:"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1710 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1711 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1712
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1713
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1714 } elsif ($choice eq 'n') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1715 return options_cycle($start, $stop, $msg, $feat,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1716 $directions, $best_guess, @opt)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1717 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1718 print "\nDidn't recognize that command. Please " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1719 "type y or n.\n:"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1720 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1721 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1722
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1723 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1724 print
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1725 "\nWould you like to save your preference for " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1726 "future use (so you don't have to redo manual " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1727 "curation for this feature everytime you run " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1728 "the converter)? (y or n)\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1729
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1730 #NML: all these while loops are a mess. Really should condense it.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1731 while (<STDIN>) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1732
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1733 chomp(my $choice = $_);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1734
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1735 if ($choice eq 'y') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1736 curation_save($feat, $input);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1737 return $input;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1738 } elsif ($choice eq 'n') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1739 return $input
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1740 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1741 print "\nDidn't recognize that command. Please " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1742 "type y or n.\n:"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1743 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1744 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1745
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1746 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1747
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1748 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1749 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1750 print "\nDidn't recognize that command. Please re-enter your choice.\n:"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1751 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1752 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1753
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1754 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1755
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1756 sub GenBank_entry {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1757 my ($f, $delimiter, $num) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1758
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1759 $delimiter ||= "\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1760
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1761
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1762 my $entry =
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1763
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1764 ($num ? ' [1] ' : ' ' x 5) . $f->primary_tag
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1765 . ($num
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1766 ? ' ' x (12 - length $f->primary_tag ) . ' [2] '
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1767 : ' ' x (15 - length $f->primary_tag)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1768 )
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1769 . $f->start.'..'.$f->end
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1770
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1771 . "$delimiter";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1772
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1773 if ($num) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1774 words_tag($f, \$entry);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1775 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1776 for my $tag ($f->all_tags) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1777 for my $val ( $f->each_tag_value($tag) ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1778 $entry .= ' ' x 20;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1779 #$entry .= "/$tag=\"$val\"$delimiter";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1780 $entry .= $val eq '_no_value'
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1781 ? "/$tag$delimiter"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1782 : "/$tag=\"$val\"$delimiter";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1783 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1784 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1785
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1786 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1787
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1788 return $entry;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1789 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1790
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1791
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1792 sub gff_validate {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1793 warn "Validating GFF file\n" if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1794 my @feat = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1795
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1796 my (%parent2child, %all_ids, %descendants, %reserved);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1797
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1798 for my $f (@feat) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1799 for my $aTags (['Parent', \%parent2child], ['ID', \%all_ids]) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1800 map { push @{$$aTags[1]->{$_}}, $f } $f->get_tag_values($$aTags[0])
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1801 if $f->has_tag($$aTags[0]);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1802 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1803 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1804
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1805 if ($SO_FILE) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1806 while (my ($parentID, $aChildren) = each %parent2child) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1807 parent_validate($parentID, $aChildren, \%all_ids, \%descendants, \%reserved);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1808 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1809 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1810
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1811 id_validate(\%all_ids, \%reserved);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1812 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1813
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1814 sub parent_validate {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1815 my ($parentID, $aChildren, $hAll, $hDescendants, $hReserved) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1816
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1817 my $aParents = $hAll->{$parentID};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1818
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1819 map {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1820 my $child = $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1821 $child->add_tag_value( validation_error =>
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1822 "feature tried to add Parent tag, but no Parent found with ID $parentID"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1823 );
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1824 my %parents;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1825 map { $parents{$_} = 1 } $child->get_tag_values('Parent');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1826 delete $parents{$parentID};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1827 my @parents = keys %parents;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1828
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1829 $child->remove_tag('Parent');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1830
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1831 unless ($child->has_tag('ID')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1832 my $id = gene_name($child);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1833 $child->add_tag_value('ID', $id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1834 push @{$hAll->{$id}}, $child
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1835 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1836
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1837 $child->add_tag_value('Parent', @parents) if @parents;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1838
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1839 } @$aChildren and return unless scalar(@$aParents);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1840
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1841 my $par = join(',', map { $_->primary_tag } @$aParents);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1842 warn scalar(@$aParents)." POSSIBLE PARENT(S): $par" if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1843
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1844 #NML manual curation needs to happen here
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1845
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1846
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1847 my %parentsToRemove;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1848
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1849 CHILD:
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1850 for my $child (@$aChildren) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1851 my $childType = $child->primary_tag;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1852
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1853 warn "WORKING ON $childType at ".$child->start.' to '.$child->end
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1854 if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1855
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1856 for (my $i = 0; $i < scalar(@$aParents); $i++) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1857 my $parent = $aParents->[$i];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1858 my $parentType = $parent->primary_tag;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1859
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1860 warn "CHECKING $childType against $parentType" if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1861
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1862 #cache descendants so we don't have to do repeat searches
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1863 unless ($hDescendants->{$parentType}) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1864
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1865 for my $term ($ONTOLOGY->find_terms(
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1866 -name => $parentType
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1867 ) ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1868
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1869 map {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1870 $hDescendants->{$parentType}{$_->name}++
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1871 } $ONTOLOGY->get_descendant_terms($term);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1872
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1873 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1874
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1875 # NML: hopefully temporary fix.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1876 # SO doesn't consider exon/CDS to be a child of mRNA
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1877 # even though common knowledge dictates that they are
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1878 # This cheat fixes the false positives for now
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1879 if ($parentType eq 'mRNA') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1880 $hDescendants->{$parentType}{'exon'} = 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1881 $hDescendants->{$parentType}{'CDS'} = 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1882 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1883
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1884 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1885
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1886 warn "\tCAN $childType at " . $child->start . ' to ' . $child->end .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1887 " be a child of $parentType?" if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1888 if ($hDescendants->{$parentType}{$childType}) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1889 warn "\tYES, $childType can be a child of $parentType" if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1890
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1891 #NML need to deal with multiple children matched to multiple different
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1892 #parents. This model only assumes the first parent id that matches a child will
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1893 #be the reserved feature.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1894
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1895 $hReserved->{$parentID}{$parent}{'parent'} = $parent;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1896 push @{$hReserved->{$parentID}{$parent}{'children'}}, $child;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1897
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1898 #mark parent for later removal from all IDs
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1899 #so we don't accidentally change any parents
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1900
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1901 $parentsToRemove{$i}++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1902
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1903 next CHILD;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1904 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1905 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1906
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1907
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1908
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1909 #NML shouldn't have to check this; somehow child can lose Parent
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1910 #it's happening W3110
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1911 #need to track this down
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1912 if ( $child->has_tag('Parent') ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1913
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1914 warn "\tNO, @{[$child->primary_tag]} cannot be a child of $parentID"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1915 if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1916
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1917 my %parents;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1918
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1919 map { $parents{$_} = 1 } $child->get_tag_values('Parent');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1920
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1921 delete $parents{$parentID};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1922 my @parents = keys %parents;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1923
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1924 warn 'VALIDATION ERROR '.$child->primary_tag." at ".$child->start .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1925 ' to ' . $child->end . " cannot be a child of ID $parentID"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1926 if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1927
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1928 $child->add_tag_value( validation_error =>
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1929 "feature cannot be a child of $parentID");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1930
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1931 $child->remove_tag('Parent');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1932
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1933 unless ($child->has_tag('ID')) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1934 my $id = gene_name($child);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1935 $child->add_tag_value('ID', $id);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1936 push @{$hAll->{$id}}, $child
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1937 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1938
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1939 $child->add_tag_value('Parent', @parents) if @parents;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1940 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1941
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1942 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1943
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1944 #delete $aParents->[$_] for keys %parentsToRemove;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1945 splice(@$aParents, $_, 1) for keys %parentsToRemove;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1946 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1947
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1948 sub id_validate {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1949 my ($hAll, $hReserved) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1950
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1951
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1952 for my $id (keys %$hAll) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1953
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1954 #since 1 feature can have this id,
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1955 #let's just shift it off and uniquify
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1956 #the rest (unless it's reserved)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1957
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1958 shift @{$hAll->{$id}} unless $hReserved->{$id};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1959 for my $feat (@{$hAll->{$id}}) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1960 id_uniquify(0, $id, $feat, $hAll);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1961 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1962 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1963
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1964 for my $parentID (keys %$hReserved) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1965
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1966 my @keys = keys %{$hReserved->{$parentID}};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1967
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1968 shift @keys;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1969
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1970 for my $k (@keys) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1971 my $parent = $hReserved->{$parentID}{$k}{'parent'};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1972 my $aChildren= $hReserved->{$parentID}{$k}{'children'};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1973
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1974 my $value = id_uniquify(0, $parentID, $parent, $hAll);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1975 for my $child (@$aChildren) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1976
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1977 my %parents;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1978 map { $parents{$_}++ } $child->get_tag_values('Parent');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1979 $child->remove_tag('Parent');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1980 delete $parents{$parentID};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1981 $parents{$value}++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1982 my @parents = keys %parents;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1983 $child->add_tag_value('Parent', @parents);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1984 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1985
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1986 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1987 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1988 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1989
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1990 sub id_uniquify {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1991 my ($count, $value, $feat, $hAll) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1992
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1993 warn "UNIQUIFYING $value" if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1994
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1995 if (! $count) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1996 $feat->add_tag_value(Alias => $value);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1997 $value .= ('.' . $feat->primary_tag)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1998 } elsif ($count == 1) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1999 $value .= ".$count"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2000 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2001 chop $value;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2002 $value .= $count
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2003 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2004 $count++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2005
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2006 warn "ENDED UP WITH $value" if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2007 if ( $hAll->{$value} ) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2008 warn "$value IS ALREADY TAKEN" if $DEBUG;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2009 id_uniquify($count, $value, $feat, $hAll);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2010 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2011 #warn "something's breaking ".$feat->primary_tag.' at '.$feat->start.' to '.$feat->end;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2012 $feat->remove_tag('ID');
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2013 $feat->add_tag_value('ID', $value);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2014 push @{$hAll->{$value}}, $value;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2015 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2016
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2017 $value;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2018 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2019
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2020 sub conf_read {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2021
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2022 print "\nCannot read $CONF. Change file permissions and retry, " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2023 "or enter another file\n" and conf_locate() unless -r $CONF;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2024
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2025 print "\nCannot write $CONF. Change file permissions and retry, " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2026 "or enter another file\n" and conf_locate() unless -w $CONF;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2027
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2028 $YAML = LoadFile($CONF);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2029
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2030 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2031
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2032 sub conf_create {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2033
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2034 my ($path, $input) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2035
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2036 print "Cannot write to $path. Change directory permissions and retry " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2037 "or enter another save path\n" and conf_locate() unless -w $path;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2038
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2039 $CONF = $input;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2040
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2041 open(FH, '>', $CONF);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2042 close(FH);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2043 conf_read();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2044
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2045
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2046 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2047
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2048 sub conf_write { DumpFile($CONF, $YAML) }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2049
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2050 sub conf_locate {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2051
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2052 print "\nEnter the location of a previously saved config, or a new " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2053 "path and file name to create a new config (this step is " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2054 "necessary to save any preferences)";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2055
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2056 print "\n\nenter a command:";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2057
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2058 while (<STDIN>) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2059 chomp(my $input = $_);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2060 my ($fn, $path, $suffix) = fileparse($input, qr/\.[^.]*/);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2061
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2062 if (-e $input && (! -d $input)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2063
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2064 print "\nReading $input...\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2065 $CONF = $input;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2066
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2067 conf_read();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2068 last;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2069
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2070 } elsif (! -d $input && $fn.$suffix) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2071
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2072 print "Creating $input...\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2073 conf_create($path, $input);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2074 last;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2075
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2076 } elsif (-e $input && -d $input) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2077 print "You only entered a directory. " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2078 "Please enter BOTH a directory and filename\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2079 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2080 print "$input does not appear to be a valid path. Please enter a " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2081 "valid directory and filename\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2082 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2083 print "\nenter a command:";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2084 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2085 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2086
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2087 sub curation_save {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2088
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2089 my ($feat, $input) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2090
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2091 #my $error = "Enter the location of a previously saved config, or a new " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2092 # "path and file name to create a new config (this step is " .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2093 # "necessary to save any preferences)\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2094
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2095 if (!$CONF) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2096 print "\n\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2097 conf_locate();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2098 } elsif (! -e $CONF) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2099 print "\n\nThe config file you have chosen doesn't exist.\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2100 conf_locate();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2101 } else { conf_read() }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2102
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2103 my $entry = GenBank_entry($feat, "\r", 1);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2104
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2105 my $msg = "Term entered: $input";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2106 my $directions = "Please select any/all tags that provide evidence for the term you
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2107 have entered. You may enter multiple tags by separating them by commas/dashes
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2108 (e.g 1,3,5-7). For tags with more than one word value (i.e 'note'), you have
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2109 the option of either selecting the entire note as evidence, or specific
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2110 keywords. If a tag has multiple keywords, they will be tagged alphabetically
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2111 for selection. To select a specific keyword in a tag field, you must enter the
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2112 tag number followed by the keyword letter (e.g 3a). Multiple keywords may be
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2113 selected by entering each letter separated by commas/dashes (e.g 3b,f,4a-c). The more tags you select, the more specific the GenBank entry will have
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2114 to be to match your curation. To match the GenBank entry exactly as it
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2115 appears, type every number (start-end), or just type 'all'. Remember, once the converter saves your
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2116 preference, you will no longer be prompted to choose a feature type for any
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2117 matching entries until you edit the curation.ini file.";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2118 my $msg_copy = $msg;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2119 my $dir_copy = $directions;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2120
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2121 my $format = "format STDOUT = \n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2122 '-' x 156 . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2123 '^' . '<' x 77 . '| Directions:' . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2124 '$msg_copy' . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2125 '-' x 156 . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2126 ' ' x 78 . "|\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2127 '^' . '<' x 77 . '| ^' . '<' x 75 . '~' . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2128 '$entry' . ' ' x 74 . '$dir_copy,' . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2129 (' ' x 15 . '^' . '<' x 62 . '| ^' . '<' x 75 . '~' . "\n" .
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2130 ' ' x 15 . '$entry,' . ' ' x 58 . '$dir_copy,' . "\n") x 20 . ".\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2131
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2132 {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2133 # eval throws redefined warning that breaks formatting.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2134 # Turning off warnings just for the eval to fix this.
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2135 no warnings 'redefine';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2136 eval $format;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2137 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2138
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2139 write;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2140 print '-' x 156 . "\nenter a command:";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2141
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2142 my @tags = words_tag($feat);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2143
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2144 my $final = {};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2145 my $choices;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2146 while (<STDIN>) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2147
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2148 chomp(my $choice = $_);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2149
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2150 if (scalar(keys %$final) && $choice =~ /^y/i) { last
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2151
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2152 } elsif (scalar(keys %$final) && $choice =~ /^n/i) { curation_save($feat, $input)
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2153
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2154 } elsif (scalar(keys %$final)) { print "\nInvalid selection. Please try again\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2155
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2156 } elsif ($choice eq 'all') {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2157
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2158 $choice = '';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2159 for (my $i=1; $i < scalar(@tags); $i++) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2160 $choice .= "$i,";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2161 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2162 chop $choice;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2163 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2164 #print "CHOICE [$choice]";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2165
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2166 my @selections;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2167 for (split(/(?<=\w)[^[:alnum:]\-]+(?=\d)/, $choice)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2168 if ($_ =~ /(\d+)(?:\D*)-(\d+)(.*)/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2169
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2170 for ($1..$2) { push @selections, $_ }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2171
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2172 my $dangling_alphas = $3;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2173 alpha_expand($dangling_alphas, \@selections);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2174
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2175 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2176 alpha_expand($_, \@selections);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2177 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2178 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2179
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2180 foreach my $numbers (@selections) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2181
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2182 my @c = split(/(?=[\w])/, $numbers);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2183 s/\W+//g foreach @c;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2184 my $num;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2185
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2186 {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2187 $^W = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2188 $num = 0 + shift @c;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2189 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2190
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2191 my $tag = $tags[$num];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2192 if (ref $tag && scalar(@c)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2193 my $no_value;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2194 foreach (@c) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2195 if (defined $tag->{$_}) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2196 $choices .= "${num}[$_] ";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2197 my ($t,$v) = @{$tag->{$_}};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2198 push @{${$final->{$input}}[0]{$t}}, $v;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2199
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2200 } else { $no_value++ }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2201 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2202
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2203 if ($no_value) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2204 _selection_add($tag,$final,$input,\$choices,$num);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2205 #my ($t,$v) = @{$tag->{'all'}};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2206 #unless (defined ${$final->{$input}}[0]{$t}) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2207 #$choices .= "$num, ";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2208 #push @{${$final->{$input}}[0]{$t}}, $v
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2209 #}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2210 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2211
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2212 $choices = substr($choices, 0, -2);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2213 $choices .= ', ';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2214
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2215 } elsif (ref $tag) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2216 _selection_add($tag,$final,$input,\$choices,$num);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2217 #my ($t,$v) = @{$tag->{'all'}};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2218 #unless (defined ${$final->{$input}}[0]{$t}) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2219 #$choices .= "$num, ";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2220 #push @{${$final->{$input}}[0]{$t}}, $v
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2221 #}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2222 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2223 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2224 $choices = substr($choices, 0, -2) if $choices;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2225 if ($final) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2226 print "\nYou have chosen the following tags:\n$choices\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2227 print "This will be written to the config file as:\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2228 print Dump $final;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2229 print "\nIs this correct? (y or n)\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2230 } else { print "\nInvalid selection. Please try again\n" }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2231 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2232 push @{$YAML->{$input}}, $final->{$input};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2233 conf_write();
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2234 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2235
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2236 # words_tag() splits each tag value string into multiple words so that the
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2237 # user can select the parts he/she wants to use for curation
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2238 # it can tag 702 (a - zz) separate words; this should be enough
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2239
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2240 sub words_tag {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2241
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2242 my ($feat, $entry) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2243
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2244 my @tags;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2245
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2246 @tags[1,2] = ({'all' => ['primary_tag', $feat->primary_tag]}, {'all' => ['location', $feat->start.'..'.$feat->end]});
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2247 my $i = 3;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2248 foreach my $tag ($feat->all_tags) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2249 foreach my $value ($feat->each_tag_value($tag)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2250
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2251 my ($string, $tagged_string);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2252
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2253 my @words = split(/(?=\w+?)/, $value);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2254
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2255 my $pos = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2256
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2257
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2258 foreach my $word (@words) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2259
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2260 (my $sanitized_word = $word) =~ s/\W+?//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2261 $string .= $word;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2262
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2263 my $lead = int($pos/ALPHABET_DIVISOR);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2264 my $lag = $pos % ALPHABET_DIVISOR;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2265
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2266 my $a = $lead ? ${(ALPHABET)}[$lead-1] : '';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2267 $a .= $lag ? ${(ALPHABET)}[$lag] : 'a';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2268
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2269 $tagged_string .= " ($a) $word";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2270
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2271 $tags[$i]{$a} = [$tag, $sanitized_word];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2272 $pos++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2273 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2274
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2275 $value = $tagged_string if scalar(@words) > 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2276
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2277 $$entry .= "[$i] /$tag=\"$value\"\r";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2278
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2279 $tags[$i]{'all'} = [$tag, $string];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2280 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2281 $i++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2282 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2283
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2284 return @tags;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2285
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2286 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2287
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2288 sub alpha_expand {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2289
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2290 my ($dangling_alphas, $selections) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2291
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2292 if (defined($dangling_alphas) && $dangling_alphas =~ /(\d)*([[:alpha:]]+)-([[:alpha:]]+)/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2293
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2294 my $digit = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2295 push @$selections, $digit if $digit;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2296
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2297 my $start = $2;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2298 my $stop = $3;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2299
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2300 my @starts = split('', $start);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2301 my @stops = split('', $stop);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2302
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2303 my ($final_start, $final_stop);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2304
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2305 for ([\$final_start, \@starts], [\$final_stop, \@stops]) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2306
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2307 my ($final, $splits) = @$_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2308
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2309 my $int = ${(ALPHABET_TO_NUMBER)}{$$splits[0]};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2310 my $rem;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2311
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2312
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2313 if ($$splits[1]) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2314 $rem = ${(ALPHABET_TO_NUMBER)}{$$splits[1]};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2315 $int++
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2316 } else {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2317 $rem = $int;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2318 $int = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2319 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2320
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2321
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2322 $$final = $int * ALPHABET_DIVISOR;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2323 $$final += $rem;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2324
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2325 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2326
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2327 my $last_number = pop @$selections;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2328 for my $pos ($final_start..$final_stop) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2329 my $lead = int($pos/ALPHABET_DIVISOR);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2330 my $lag = $pos % ALPHABET_DIVISOR;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2331 my $alpha = $lead ? ${(ALPHABET)}[$lead-1] : '';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2332 $alpha .= $lag ? ${(ALPHABET)}[$lag] : 'a';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2333 push @$selections, $last_number.$alpha;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2334 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2335
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2336 } elsif (defined($dangling_alphas)) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2337 if ($dangling_alphas =~ /^\d/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2338 push @$selections, $dangling_alphas;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2339 } elsif ($dangling_alphas =~ /^\D/) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2340 #print "$dangling_alphas ".Dumper @$selections;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2341 my $last_number = pop @$selections;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2342 $last_number ||= '';
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2343 push @$selections, $last_number.$dangling_alphas;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2344 #$$selections[-1] .= $dangling_alphas;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2345 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2346 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2347
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2348 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2349
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2350 sub _selection_add {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2351
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2352 my ($tag, $final, $input, $choices, $num) = @_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2353 my ($t,$v) = @{$tag->{'all'}};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2354 unless (defined ${$final->{$input}}[0]{$t}) {
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2355 $$choices .= "$num, ";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2356 push @{${$final->{$input}}[0]{$t}}, $v
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2357 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2358
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2359 }