comparison mlstAddFields.pl @ 13:59e137488c63 draft

Uploaded
author estrain
date Wed, 24 May 2023 17:24:23 +0000
parents
children
comparison
equal deleted inserted replaced
12:50867379763d 13:59e137488c63
1 #!/usr/bin/perl
2 #
3
4 use List::MoreUtils qw(first_index indexes);
5
6 open MLST,$ARGV[0];
7
8 @mlstout=split(/\t/,<MLST>);
9
10 $schema=$mlstout[1];
11 $mlstST=$mlstout[2];
12
13 # Assumes mlst command is installed and available in the path
14 # Retrieve the location of the MLST databases
15 $mlstdesc=`mlst -h | grep \"db/pubmlst\"`;
16 @vals = split(/\'/,$mlstdesc);
17 $mlstloc=$vals[1];
18 $mlstloc=~s/bin\/\.\.//g;
19
20 my(%schema);
21
22 $mlstfile = "$mlstloc/$schema/$schema.txt";
23 open IN,$mlstfile;
24 @headers=split(/\t/,<IN>);
25 my $clonal = first_index { /clonal\_complex/ } @headers;
26 my $cc = first_index { /CC/ } @headers;
27 my $lineage = first_index { /Lineage/ } @headers;
28 my $species = first_index { /species/ } @headers;
29 while($line=<IN>) {
30 chomp($line);
31 my(@vals)=split(/\t/,$line);
32 my(@desc);
33 if ($clonal>0 && length($vals[$clonal])>0) {
34 push(@desc,"clonal_complex=".$vals[$clonal]);
35 }
36 if ($cc>0 && length($vals[$clonal])>0) {
37 push(@desc,"CC=".$vals[$cc]);
38 }
39 if ($lineage>0 && length($vals[$linage])>0) {
40 push(@desc,"Lineage=".$vals[$lineage]);
41 }
42 if ($species>0 && length($vals[$species])>0) {
43 push(@desc,"species=".$vals[$species]);
44 }
45 $schema{$vals[0]}=join(',',@desc);
46 }
47
48 print shift(@mlstout)."\t".shift(@mlstout)."\t".shift(@mlstout)."\t";
49 if(exists($schema{$mlstST})) {
50 print $schema{$mlstST};
51 }
52 foreach(@mlstout) {
53 print "\t".$_;
54 }