#!/usr/local/bin/perl # make.p i=inputs t=targets f=1 p=1 # generates net data from tim hubbards files. # the data should be read from d/bb4sq... # which has 61 chars (plus newline) per line # # f=1,2,3,4,5,6 determines which of the # target types is written to the files. # p=0/1 states whether the 3,4 data is for a # parallel net or an antiparallel. # # if f=1 then Hits of type 1 are antiparallel, and NC type is given # if f=2 then Hits of type 2 are parallel, and NC type is given. # (this program also reports # min distance [10?] between 2,3) # if f=3 or 4, then two examples are written # corresponding to the two permutations of 1234 NC and 3412 CN. # # The p=1 flag only has an effect in cases 3 and 4, and then only # if the distance between the # 12 and the 34 is too small, in which case parallel is impossible # # For efficiency of data storage, I will make p=0 cause *only* # the short range dudes to be printed out. So to get data to train a # parallel net, concatenate p=1 and p=0 together. sub aa_number { # returns a number in 0-19 or 20 for "-" #usage ( $c ) local($c)=@_; local($ans)=0; if ( ord($c) == ord('-') ) { $ans = 20 ; } else { $ans = ord($c) - ord('A') ; # 0 - 24 with gaps at 1,9,14,20,23. if( $ans <= 8 && $ans >=2 ){ $ans -= 1 ; } elsif( $ans <= 13 && $ans >= 10 ){ $ans -= 2 ; } elsif( $ans <= 19 && $ans >= 15 ){ $ans -= 3 ; } elsif( $ans == 21 || $ans == 22 ){ $ans -= 4 ; } elsif( $ans == 24 ){ $ans -= 5; } elsif( $ans != 0 ) { print STDERR "Not an amino acid: " , $c, "\n" ; $ans = - 1 ; } } return($ans); } sub target { # 1,2-> "1" 3,4,5,6-> "0" #usage ( $c ) local($c)=@_; if( $c == 1 || $c ==2 ){ $c = 1 ; } elsif( $c <= 6 && $c >= 3 ){ $c = 0 ; } else { print STDERR "Not a target: " , $c, "\n" ; $c = 0 ; } return($c); } sub distance { # 0 -> 100; # 1,2 .. 99 -> divide by 100.0 #usage ( $c ) local($c)=@_; if( $c == 0 || $c== -1 || $c > 100 ){ $c = 100 ; } return(substr(($c+0.1)/100.0,0,4)); } # # START HERE # $i=inputs; $t=targets; $f=4; $p=0; # p only relevant to 3 & 4. $min=11; $smallest=100; $count= 0; $naa = 6 ; $ntot = 28 ; # How to override min and max values with command line eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; # calculate start and end of the two aa sequences if ( $naa % 2 ) { print STDERR "Warning, naa is odd\n" ; } $hnaa = $naa / 2 ; $firstlo = $ntot / 4 - $hnaa ; $firsthi = $ntot / 4 + $hnaa - 1; $secndlo = 3 * $ntot / 4 - $hnaa ; $secndhi = 3 * $ntot / 4 + $hnaa - 1 ; printf STDERR "amino acids %d - %d , %d - %d \n" , $firstlo , $firsthi, $secndlo , $secndhi ; printf STDERR "number of inputs is %d\n", 2 * $naa * 21 + 2 ; if($f>=3){ $doreverse = 1; } else { $doreverse = 0; } open(OUT,">$i"); open(TA,">$t"); while (<>) { if ( $_ ne "\n" && substr($_,0,1) ne "#" && !( /\!/ ) ) { # no "!" permitted $le = length($_); if ( $le == 61 || $le == 62 ) { # Decide what the target is; # only proceed if it matches f. if ( ( $cc = substr($_,28,1) ) == $f ) { # extract separation of 12,34 $oa = substr($_,58,3) ; if ( $f<=2 || # ( all distances are reported ) ( $p == 0 && $oa < $min ) || # antiparallel ( $p == 1 && $oa >= $min ) ) # parallel { $di = &distance( $oa ) ; # 0-1 variable if ( $oa < $smallest && $oa > 0 ) { # keep track of min separation. Zero doesn't count. $smallest = $oa; } $ta = &target( $cc ); $out=""; # Turn the first 28 amino acids into unary codes $first = ""; for ( $a = $firstlo ; $a<= $firsthi ; $a++ ) { $v = &aa_number(substr($_,$a,1)); @count[$v] ++ ; for ( $k = 0 ; $k <= 20 ; $k++ ){ if ($k != $v ) { $first = $first."0 "; } else { $first = $first."1 "; } } $first = $first."\n "; } $out = $out.$first." "; $secnd = ""; for ( $a = $secndlo ; $a<= $secndhi ; $a++ ) { $v = &aa_number(substr($_,$a,1)); @count[$v] ++ ; for ( $k = 0 ; $k <= 20 ; $k++ ){ if ($k != $v ) { $secnd = $secnd."0 "; } else { $secnd = $secnd."1 "; } } $secnd = $secnd."\n "; } $out = $out.$secnd." "; # Other stuff # The NC flag. $oa = substr($_,$ntot+1,1) - 1 ; $out = $out.$oa." ".$di."\n"; $count++; print OUT $out ; print TA $ta, "\n"; if ( $doreverse ) { $oa = 1 - $oa ; #flip sign of $oa # double check - TH says that all 3 & 4 examples have NC flag set to 1. if ( $oa != 1 ) { print STDERR "Warning: oa = " , $oa, "\n" ; } $rev = $secnd.$first." ".$oa." ".$di."\n" ; print OUT $rev ; print TA $ta, "\n"; # extra target line. } } else { $skippedcount++ ; } } } else { printf STDERR "Warning: non standard line ", $_ ; } } } for ( $v=0; $v<=20; $v++ ) {print $v, " ", @count[$v], "\n"; } print STDERR " count = ",$count ,": smallest distance = ", $smallest, "\n"; print STDERR " skipped count = ",$skippedcount ,"\n";