ServerAdministration: expand_IPI_dat_random.pl

File expand_IPI_dat_random.pl, 1.6 KB (added by fredrik, 3 years ago)

Script to add decoy entries to .dat file

Line 
1#!/usr/local/bin/perl
2
3#############################################################################
4# Script to expand IPI .dat file with minimal IPRND entries at the end      #
5#############################################################################
6 use strict;
7
8# print usage information if no arguments supplied 
9  unless ($ARGV[0]) {
10    print "The .dat database to expand should be given as argument";
11    exit 1;
12  }
13
14my($infile);
15$infile = $ARGV[0];
16
17open (INFILE,  "+<$infile")          || die "Error: cannot open input file";
18open (OUTFILE, "+>$infile" . ".tmp") || die "Error: cannot create temp file";
19
20# use the same EOL for the output as found in the input file
21  binmode INFILE;
22  binmode OUTFILE;
23  $/ = "\012ID";
24  my $eol;
25  while (<INFILE>) {
26    if (length($_) > 1) {
27      if (/\015\012/) {
28        $eol = "\015\012"; #DOS
29      } else {
30        $eol = "\012"; #Unix
31      }
32      last;
33    } else {
34      next;
35    }
36  }
37
38# read a complete sequence entry at a time
39  $/ = $eol."ID";
40
41# set the cursor to start of file + 2 characters, skip first "ID"
42  seek(INFILE, 2, 0);
43
44# loop through input file and create the output file
45  while (<INFILE>) {
46    my($idline, $accline, $rest) = split(/$eol/o, $_, 3);
47    $idline =~ s/IPI/IPRND/;
48    $accline =~ s/IPI/IPRND/;
49    print OUTFILE "ID" . $idline . $eol;
50    print OUTFILE $accline . $eol;
51    print OUTFILE "DE    Random sequence".$eol;   
52  }
53
54#now write everything to the end of old file
55  seek(OUTFILE, 0, 0);
56  while (<OUTFILE>) {
57     print INFILE $_;     
58  }
59  close OUTFILE;
60  unlink "$infile" . ".tmp";
61 
62  exit 0;
63