-
Notifications
You must be signed in to change notification settings - Fork 0
/
uniref2panda_reduce_2.pl
executable file
·160 lines (106 loc) · 4.79 KB
/
uniref2panda_reduce_2.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/perl
###########################################################################
# $Id: uniref2panda.pl 1 2010-07-08 10:39:00Z rsanka $
#
# Description: Converts input fasta file with UniRef headers to fasta file
# with PANDA headers.
#
# Original version by Ravi
# Hadoop-fied by Ntino
###########################################################################
##looses one record in the beginning and one in the end
use strict;
use warnings;
my ( $unirefID, $unirefHEAD, $unirefCluster, $unirefTaxon, $isoform, @isoformData, $newHeader, $misc, $sequence, $crossIDs, $taxonID, $key, $value, $uniref_entry_flag, $cross_refs_flag, $kingdom_flag, $clusters_flag,@cluster_members, $members_taxons, $cluster_ids, $kingdom);
$uniref_entry_flag = 0;
$cross_refs_flag = 0;
$kingdom_flag = 0;
$clusters_flag = 0;
while (<STDIN>) {
if ($uniref_entry_flag == 1 and $cross_refs_flag == 1 and $kingdom_flag == 1 and $clusters_flag = 1) {
$uniref_entry_flag = 0;
$cross_refs_flag = 0;
$kingdom_flag = 0;
$clusters_flag = 0;
#NEED taxon:TAXID HERE FROM THE GI - NCBI TAXID MAPPING
if ($isoform eq "") {
$newHeader = ">Uniref100|$unirefID^|^$crossIDs^|^$cluster_ids^|^$members_taxons\@\@\@$kingdom $unirefCluster taxon:$taxonID {$unirefTaxon} $misc ";
}
else {
$newHeader = ">Uniref100|$unirefID^|^$crossIDs^|^$cluster_ids^|^$members_taxons^|^$isoform\@\@\@$kingdom $unirefCluster taxon:$taxonID {$unirefTaxon} $misc ";
}
$newHeader =~ s/\t//g;
print "$newHeader\n$sequence\n";
}
chomp $_;
($key,$value) = split(/\t/, $_);
# If the line is a uniref header
#if ( length($unirefHEAD) > 1 and $uniref_entry_flag == 0 ) {
#if ($key =~ s/-1//) {
if ($value =~ s/-1$//) {
($unirefHEAD,$sequence) = split(/@@@/,$value);
# Use regex to acquire the following:
$unirefHEAD =~ m/>([A-Za-z0-9]+)_([A-Za-z0-9-]+) (.+) n=\d+ Tax=(.+) RepID.*/;
$unirefID = $2; # UniRef ID
$unirefCluster = $3; # UniRef Cluster name.
$unirefTaxon = $4; # UniRef Taxon name.
$isoform = "";
@isoformData = split('-',$unirefID);
if (scalar(@isoformData) > 1) {
$isoform = $isoformData[1];
$unirefID = $isoformData[0];
}
$uniref_entry_flag = 1;
}
# line is a uniref id mapping header
#elsif ($key =~ s/-2//) {
elsif ($value =~ s/-2$//) {
# Intialize the remaining tags. Set wgp, cg, and closed to 1 if the EMBL ID starts with any of appropriate letters.
$misc = "(exp=0; wgp=0; cg=0; closed=0; pub=1; rf_status =;)";
if ($value =~ s/---//) {
$misc = "(exp=0; wgp=1; cg=1; closed=1; pub=1; rf_status =;)";
}
$value =~ /\^\|\^Taxon\|([0-9]+)/;
$taxonID = $1;
$value =~ s/\^\|\^Taxon\|[0-9]+//;
$crossIDs = $value;
$cross_refs_flag = 1;
}
#elsif ($key =~ s/-3// ) {
elsif ($value =~ s/-3$// ) {
$kingdom = $value;
$kingdom_flag = 1;
}
#elsif ($key =~ s/-4// ) {
elsif ($value =~ s/-4$// ) {
($members_taxons,$cluster_ids) = split(/---/,$value);
$members_taxons =~ s/^,//;
$members_taxons = "Cluster_Taxons|$members_taxons";
@cluster_members = split(/,/,$cluster_ids);
$cluster_ids = '';
foreach(@cluster_members) {
if (length($_)>0) {
$cluster_ids = $cluster_ids.'SP|'.$_.'^|';
}
}
$cluster_ids =~ s/\^\|$//;
$clusters_flag = 1;
}
}
#need that for after processing the last trio of records
if ($uniref_entry_flag == 1 and $cross_refs_flag == 1 and $kingdom_flag == 1 and $clusters_flag = 1 ) {
$uniref_entry_flag = 0;
$cross_refs_flag = 0;
$kingdom_flag = 0;
$clusters_flag = 0;
if ($isoform eq "") {
$newHeader = ">Uniref100|$unirefID^|^$crossIDs^|^$cluster_ids^|^$members_taxons\@\@\@$kingdom $unirefCluster taxon:$taxonID {$unirefTaxon} $misc";
}
else {
$newHeader = ">Uniref100|$unirefID^|^$crossIDs^|^$cluster_ids^|^$members_taxons^|^$isoform\@\@\@$kingdom $unirefCluster taxon:$taxonID {$unirefTaxon} $misc";
}
$newHeader =~ s/\t//g;
print "$newHeader\n$sequence\n";
#$unirefHEAD = '';
#$giID = '';
}