#!/usr/bin/perl ##------------------------------------------------------------------------------# # Copyright 1998 # # Burkhard Rost rost@EMBL-Heidelberg.DE # # Wilckensstr. 15 http://www.embl-heidelberg.de/~rost/ # # D-69120 Heidelberg # # version 0.1 May, 1998 # # version 1.1 Oct, 1998 # #------------------------------------------------------------------------------# =pod =head1 NAME RG::Utils::Conv_hssp2saf - Rost Lab perl utilities =head1 SYNOPSIS use RG::Utils::Conv_hssp2saf; =head1 FUNCTIONS See module source for description. =over =item bynumber =item bynumber_high2low =item conv_hssp2saf =item convHssp2saf =item convHssp2saf_hsspRdLoc =item errSbr =item errSbrMsg =item get_range =item get_rangeHyphen =item hsspGetChain =item hsspRdAli =item hsspRdHeader =item hsspRdSeqSecAccOneLine =item is_hssp =item is_pdbid =item open_file =item safWrt =back =head1 VARIABLES =over =back =head1 AUTHOR B. Rost =head1 SEE ALSO =over =item Main website L =back =cut package RG::Utils::Conv_hssp2saf; no warnings 'deprecated'; INIT: { $scrName=$0;$scrName=~s/^.*\/|\.pl//g; $scrGoal="converts HSSP 2 SAF\n"; } #=============================================================================== sub conv_hssp2saf { #------------------------------------------------------------------------------- # conv_hssp2saf package version of script #------------------------------------------------------------------------------- $[ =1 ; # sets array count to start at 1, not at 0 @PARAMS=@_; # pass from calling $par{packName} = __FILE__; # ------------------------------ foreach $arg(@PARAMS){ # highest priority arguments next if ($arg !~/=/); if ($arg=~/^packName=(.*)/) { $par{"packName"}=$1; shift @PARAMS if ($PARAMS[1] eq $arg); } } # ------------------------------ &convHssp2saf("ini"); # sets %par # ------------------------------ if ($#PARAMS<1){ # help print "goal:\t $scrGoal\n"; print "use: \t '$scrName list.hssp (or *.hssp)'\n"; print "opt: \t \n"; printf " \t %-15s= %-20s %-s\n","fileOut", "x",""; printf " \t %-15s= %-20s %-s\n","extr", "p1-p2,p3","(extract proteins p1-p2,p3 only)"; printf " \t %-15s= %-20s %-s\n","frag", "n1-n2", "(extract residues n1-n2 only)"; printf " \t %-15s %-20s %-s\n","noScreen", "no value",""; printf " \t %-15s %-20s %-s\n","expand", "no value","(do expand the insertion list)"; # printf " \t %-15s %-20s %-s\n","", "no value",""; if (%par){ printf " \t %-15s %-20s %-s\n","-" x 15 ,"-" x 20,"-" x 30; printf " \t %-15s %-20s %-s\n","other:","default settings: "," "; foreach $kwd (@kwd){ if ($par{"$kwd"}!~/\D/){ printf " \t %-15s= %10d %9s %-s\n",$kwd,$par{"$kwd"}," ","(def)";} elsif ($par{"$kwd"}!~/[0-9\.]/){ printf " \t %-15s= %10.3f %9s %-s\n",$kwd,$par{"$kwd"}," ","(def)";} else { printf " \t %-15s= %-20s %-s\n",$kwd,$par{"$kwd"},"(def)";} } } exit;} ($Lok,$msg)= &convHssp2saf(@PARAMS); print "*** $scrName: final msg=\n".$msg."\n" if (! $Lok); return(1,"ok $scrName:pack"); } # end of conv_hssp2saf #=============================================================================== sub convHssp2saf { local($tmpMode) = @_ ; local($sbrName,$fhinLoc,$tmp,$Lok); $[ =1 ; #------------------------------------------------------------------------------- # convHssp2saf script to convert HSSP 2 SAF # in: file.hssp (or list, or *.hssp) # file.hssp_C for chain! # in: opt fileOut=X -> output file will be X # NOTE: only for single file! # in: opt frag=n1-n2 -> extract residues n1-n2 # in: opt extr=p1-p2,p3 -> extract proteins p1-p2,p3 # in: opt expand -> write expanded ali # in: opt noScreen -> avoid writing # out: 1|0,msg, implicit: file # err: (1,'ok'), (0,'message') #------------------------------------------------------------------------------- $tmp=$0;$tmp=~s/^.*\/|\.pl//g;$tmp.=":"; $sbrName="$tmp:lib-scr::"."convHssp2saf";$fhinLoc="FHIN_"."convHssp2saf"; # ------------------------------ # defaults @rdHsspHdr=("SEQLENGTH","ID","IDE","LALI","IFIR","ILAS"); $par{"len1Min"}= 30 if (! defined $par{"len1Min"}); # minimal length $par{"laliMin"}= 30 if (! defined $par{"laliMin"}); # minimal alignment length $par{"pideMax"}= 100 if (! defined $par{"pideMax"}); # maximal percentage sequence identity $par{"expand"}= 0 if (! defined $par{"expand"} ); # expand insertions? $par{"verbose"}= 1 if (! defined $par{"verbose"}); # $par{"verb2"}= 0 if (! defined $par{"verb2"} ); # @kwd=sort (keys %par); return if (defined $tmpMode && $tmpMode eq "ini"); # initialise variables $fhin="FHIN"; # ------------------------------ $#fileIn=$#chainIn=0; # read command line foreach $arg (@_){ if ($arg=~/^fileOut=(.*)$/) { $fileOut=$1;} elsif ($arg=~/^frag=(.*)$/) { $frag=$1; if ($frag !~/\d+\-\d+/){ print "*** arg 'frag' must be 'N1-N2'\n"; exit;}} elsif ($arg=~/^extr=(.*)$/) { $extr=$1; } elsif ($arg=~/^no[Ss]creen/) { $par{"verbose"}=$par{"verb2"}=0; } elsif ($arg=~/^expand$/) { $par{"expand"}=1; } elsif ($arg=~/^debug$/) { $par{"debug"}=1; } # elsif ($arg=~/^=(.*)$/) { $=$1; } elsif (-e $arg) { push(@fileIn,$arg); push(@chainIn,"*");} elsif ($arg=~/^(.*\.hssp)\_([A-Z0-9])/) { push(@fileIn,$1); push(@chainIn,$2);} elsif (%par && $#kwd>0) { $Lok=0; foreach $kwd (@kwd){ if ($arg =~ /^$kwd=(.+)$/){$Lok=1;$par{"$kwd"}=$1; last;}} if (! $Lok){ print "*** wrong command line arg '$arg'\n"; die;}} else { print "*** wrong command line arg '$arg'\n"; die;}} # ------------------------------ # verify 'extr' correct if (defined $extr && length($extr)>=1 && $extr=~/\d/ && $extr ne "0"){ @extr=&get_range($extr); return(&errSbr("you gave the argument 'extr=$extr', not valid!\n*** Ought to be of the form:\n". "'extr=n1-n2', or 'extr=n1,n2,n3-n4,n5'\n")) if ($#extr==0); foreach $tmp (@extr) { if ($tmp=~/\D/){ return(&errSbr("you gave the argument 'extr=$extr', not valid!\n". "*** Ought to be of the form:\n". "'extr=n1-n2', or 'extr=n1,n2,n3-n4,n5'\n")); } $extr{"$tmp"}=1; }} elsif (defined $extr) {undef $extr ; } # ------------------------------ # input file $fileIn=$fileIn[1]; die ("missing input $fileIn\n") if (! -e $fileIn); # ------------------------------ # (0) read list (if list) if (! &is_hssp($fileIn)){ # ------------------------------ print "--- $scrName: read list '$fileIn'\n"; $#fileIn=$#chainIn=0; $fhin="FHIN_$scrName"; &open_file("$fhin", "$fileIn") || die '*** $scrName ERROR opening file $fileIn'; while (<$fhin>) { $_=~s/\n|\s//g; next if (length($_)<5); if ($_=~/^(.*\.hssp)\_([A-Z0-9])/){ push(@fileIn,$1); push(@chainIn,$2);} else { push(@fileIn,$_); push(@chainIn,"*");} } close($fhin); $#fileOut=0; } else { @fileOut=($fileOut) if (defined $fileOut); $#fileOut=0 if (! defined $fileOut); } # ------------------------------ # (1) loop over file(s) # ------------------------------ foreach $itfile(1..$#fileIn){ ($Lok,$msg)= &convHssp2saf_hsspRdLoc; return(&errSbrMsg("failed reading file=$fileIn[$itfile], it=$itfile",$msg)) if (! $Lok); } if ($par{"verbose"}) { $tmp=""; foreach $file (@fileOut) { next if (! -e $file); $tmp.="$file,";} $tmp=~s/,*$//g; if (length($tmp)>2 && $tmp=~/,/){ print "--- output files:"; } elsif (length($tmp)>2){ print "--- output file:"; } print "$tmp\n";} return(1,"ok $sbrName"); } # end of convHssp2saf #=============================================================================== sub convHssp2saf_hsspRdLoc { # local($fileInLoc,$fhErrSbr) = @_ ; local($sbrName,$fhinLoc,$tmp,$Lok); $[ =1 ; #------------------------------------------------------------------------------- # convHssp2saf_hsspRdLoc reads stuff # in/out GLOBAL: all # in: $fileInLoc # out: 1|0,msg, implicit: # err: (1,'ok'), (0,'message') #------------------------------------------------------------------------------- $sbrName="lib-scr::"."convHssp2saf_hsspRdLoc"; $fhinLoc="FHIN_"."convHssp2saf_hsspRdLoc"; $fileIn=$fileIn[$itfile]; $chainIn=$chainIn[$itfile]; if (! -e $fileIn){ print "-*- WARN $scrName: no fileIn=$fileIn\n"; next;} print "--- $scrName: working on $itfile =$fileIn $chainIn\n" if ($par{"verbose"}); $pdbid= $fileIn;$pdbid=~s/^.*\/|\.hssp//g; $pdbid.="_".$chainIn if ($chainIn ne "*"); undef %tmp; # ------------------------------ if ($chainIn ne "*"){ # get chain positions ($Lok,%tmp)= &hsspGetChain($fileIn); return(&errSbr("failed on getchain($fileIn)")) if (! $Lok); foreach $it (1..$tmp{"NROWS"}){ next if ($chainIn ne $tmp{"$it","chain"}); $ifir=$tmp{"$it","ifir"}; $ilas=$tmp{"$it","ilas"}; }} else { $ifir=$ilas=0;} # ------------------------------ undef %tmp; # read header of HSSP ($Lok,%tmp)= &hsspRdHeader($fileIn,@rdHsspHdr); return(&errSbr("failed on $fileIn")) if (! $Lok); # ------------------------------ # too short -> skip return(1,"too short=".$tmp{"SEQLENGTH"}) if ($tmp{"SEQLENGTH"} < $par{"len1Min"}); $#numTake=0; # ------------------------------ # process data foreach $it (1..$tmp{"NROWS"}){ # not chain -> skip next if ($ifir && $ilas && ( ($tmp{"IFIR","$it"} > $ilas) || ($tmp{"ILAS","$it"} < $ifir) )); next if ($par{"laliMin"} > $tmp{"LALI","$it"} ); # lali too short next if ($par{"pideMax"} < 100*$tmp{"IDE","$it"} ); # pide too high next if (defined $extr && ! defined $extr{"$it"} ); # select only some proteins push(@numTake,$it); # ok -> take } # ------------------------------ undef %tmp; # read alignments if (defined $par{"expand"} && $par{"expand"}){ $kwdSeq="seqAli";} # read ali with insertions else { $kwdSeq="seqNoins";} # read ali without insertions ($Lok,%tmp)= &hsspRdAli($fileIn,@numTake,$kwdSeq); return(&errSbrMsg("failed reading alis for $fileIn, num=". join(',',@numTake),$msg)) if (! $Lok); $nali=$tmp{"NROWS"}; undef %tmp2; # ------------------------------ if (defined $frag){ # adjust for extraction (arg: frag=N1-n2) ($ibeg,$iend)=split(/\-/,$frag); # additional complication if expand: change numbers if ($kwdSeq eq "seqAli"){ $seq=$tmp{"$kwdSeq","0"}; @tmp=split(//,$seq); $ct=0; foreach $it (1..$#tmp){ next if ($tmp[$it] eq "."); # skip insertions ++$ct; # count no-insertions next if ($ct > $iend); # outside of range to read next if ($ct < $ibeg); # outside of range to read $ibeg=$it if ($ct == $ibeg); # change begin $iend=$it if ($ct == $iend);}}} # change end else { $ibeg=$iend=0;} # ---------------------------------------- # cut out non-chain, and not to read parts # ---------------------------------------- foreach $it (0..$nali){ if ($ifir && $ilas){ $tmp{"$kwdSeq","$it"}=substr($tmp{"$kwdSeq","$it"},$ifir,($ilas-$ifir+1));} if ($ibeg && $iend){ $tmp{"$kwdSeq","$it"}=substr($tmp{"$kwdSeq","$it"},$ibeg,($iend-$ibeg+1));} $ct=$it+1; $tmp2{"seq","$ct"}=$tmp{"$kwdSeq","$it"}; undef $tmp{"$kwdSeq","$it"}; $tmp2{"id","$ct"}= $tmp{"$it"};} $tmp2{"NROWS"}=$nali+1; undef %tmp; # slick-is-in! # ------------------------------ undef %tmp; # slick-is-in ! undef @numTake; # slick-is-in ! # ------------------------------ # write output file if (defined $fileOut && $#fileIn==1){ $fileOutLoc=$fileOut;} else { $fileOutLoc="$pdbid".".saf"; $fileOut.=$fileOutLoc."," if (defined $fileOut); } ($Lok,$msg)= &safWrt($fileOutLoc,%tmp2); return(&errSbrMsg("failed writing out=$fileOutLoc, for in=$fileIn",$msg)) if (! $Lok); push(@fileOut,$fileOutLoc); undef %tmp2; # slick-is-in ! return(1,"ok $sbrName"); } # end of convHssp2saf_hsspRdLoc #============================================================================== # library collected (begin) #============================================================================== #=============================================================================== sub bynumber { #------------------------------------------------------------------------------- # bynumber function sorting list by number #------------------------------------------------------------------------------- $a<=>$b; } # end of bynumber #=============================================================================== sub bynumber_high2low { #------------------------------------------------------------------------------- # bynumber_high2low function sorting list by number (start with high) #------------------------------------------------------------------------------- $b<=>$a; } # end of bynumber_high2low #============================================================================== sub errSbr {local($txtInLoc,$sbrNameLocy) = @_ ; #------------------------------------------------------------------------------- # errSbr simply writes '*** ERROR $sbrName: $txtInLoc' #------------------------------------------------------------------------------- $sbrNameLocy=$sbrName if (! defined $sbrNameLocy); $txtInLoc.="\n"; $txtInLoc=~s/\n\n+/\n/g; return(0,"*** ERROR $sbrNameLocy: $txtInLoc"); } # end of errSbr #============================================================================== sub errSbrMsg {local($txtInLoc,$msgInLoc,$sbrNameLocy) = @_ ; #------------------------------------------------------------------------------- # errSbrMsg simply writes '*** ERROR $sbrName: $txtInLoc\n'.$msg #------------------------------------------------------------------------------- $sbrNameLocy=$sbrName if (! defined $sbrNameLocy); $txtInLoc.="\n"; $txtInLoc=~s/\n\n+/\n/g; $msgInLoc.="\n"; $msgInLoc=~s/\n\n+/\n/g; return(0,"*** ERROR $sbrNameLocy: $txtInLoc".$msgInLoc); } # end of errSbrMsg #============================================================================== sub get_range { local ($range_txt,$nall) = @_; local (@range,@rangeLoc,$it,$range1,$range2); $[ =1 ; #-------------------------------------------------------------------------------- # get_range converts range=n1-n2 into @range (1,2) # in: 'n1-n2' NALL: e.g. incl=1-5,9,15 # n1= begin, n2 = end, * for wild card # NALL = number of last position # out: @takeLoc: begin,begin+1,...,end-1,end #-------------------------------------------------------------------------------- $#range=0; if (! defined $range_txt || length($range_txt)<1 || $range_txt eq "unk" || $range_txt !~/\d/ ) { print "*** ERROR in get_range: argument: range=$range_txt, nall=$nall, not digestable\n"; return(0);} $range_txt=~s/\s//g; # purge blanks $nall=0 if (! defined $nall); # already only a number return($range_txt) if ($range_txt !~/[^0-9]/); if ($range_txt !~/[\-,]/) { # no range given print "*** ERROR in get_range: argument: '$range_txt,$nall' not digestable\n"; return(0);} # ------------------------------ # dissect commata if ($range_txt =~ /\,/) { @range=split(/,/,$range_txt);} # ------------------------------ # dissect hyphens elsif ($range_txt =~ /(\d*|\*)-(\d*|\*)/) { @range=&get_rangeHyphen($range_txt,$nall);} # ------------------------------ # process further elements with hyphens $#range2=0; foreach $range (@range){ if ($range =~ /(\d*|\*)-(\d*|\*)/) { push(@range2,&get_rangeHyphen($range,$nall));} else { push(@range2,$range);}} @range=@range2; $#range2=0; # ------------------------------ if ($#range>1){ # sort @range=sort {$a<=>$b} @range;} return (@range); } # end of get_range #============================================================================== sub get_rangeHyphen { local ($range_txt,$nall) = @_ ; local (@rangeLoc,$it,$range1,$range2); $[ =1 ; #-------------------------------------------------------------------------------- # get_rangeHyphen reads 'n1-n2' # in: 'n1-n2', NALL (n1= begin, n2 = end, * for wild card) # NALL = number of last position # out: begin,begin+1,...,end-1,end #-------------------------------------------------------------------------------- if ($range_txt =~ /(\d*|\*)-(\d*|\*)/) { ($range1,$range2)=split(/-/,$range_txt); if ($range1=~/\*/) {$range1=1;} if ($range2=~/\*/) {$range2=$nall;} for($it=$range1;$it<=$range2;++$it) {push(@rangeLoc,$it);} } else { @rangeLoc=($range_txt);} return(@rangeLoc); } # end of get_rangeHyphen #============================================================================== sub hsspGetChain { local ($fileIn) = @_ ; local ($fhin,$ifirLoc,$ilasLoc,$tmp1,$tmp2, $chainLoc,$posLoc,$posRd,$chainRd,@cLoc,@pLoc,%rdLoc); $[ =1 ; #-------------------------------------------------------------------------------- # hsspGetChain extracts all chain identifiers in HSSP file # in: $file # out: $chains (ABC) ,%rdLoc # no chain -> $chains=' ' # out $rdLoc{"NROWS"},$rdLoc{"$ct","chain"}, # out $rdLoc{"$ct","ifir"},$rdLoc{"$ct","ilas"} #-------------------------------------------------------------------------------- $fhin="FhInHssp"; return(0,"no file") if (! -e $fileIn); &open_file("$fhin","$fileIn"); while(<$fhin>){ # until start of data last if ($_=~/^ SeqNo/);} $chainLoc=$posLoc=""; while(<$fhin>){ if ($_=~/^\#/ && (length($chainLoc)>1) ) { $posLoc.="$ifirLoc-$ilasLoc".","; last;} $chainRd=substr($_,13,1); $aaRd= substr($_,15,1); $posRd= substr($_,1,6);$posRd=~s/\s//g; next if ($aaRd eq "!") ; # skip over chain break if ($chainLoc !~/$chainRd/){ # new chain? $posLoc.= "$ifirLoc-$ilasLoc"."," if (length($chainLoc)>1); $chainLoc.= "$chainRd".","; $ifirLoc=$ilasLoc=$posRd;} else { $ilasLoc=$posRd;} }close($fhin); $chainLoc=~s/^,|,$//g; $posLoc=~s/\s//g;$posLoc=~s/^,|,$//g; # purge leading ',' # now split chains read undef %rdLoc; $ctLoc=0; @cLoc=split(/,/,$chainLoc); @pLoc=split(/,/,$posLoc); foreach $itLoc(1..$#cLoc){ ($tmp1,$tmp2)=split(/-/,$pLoc[$itLoc]); next if ($tmp2 == $tmp1); # exclude chains of length 1 ++$ctLoc; $rdLoc{"NROWS"}= $ctLoc; $rdLoc{"$ctLoc","chain"}=$cLoc[$itLoc]; $rdLoc{"$ctLoc","ifir"}= $tmp1; $rdLoc{"$ctLoc","ilas"}= $tmp2;} $chainLoc=~s/,//g; return($chainLoc,%rdLoc); } # end of hsspGetChain #============================================================================== sub hsspRdAli { local ($fileInLoc,@want) = @_ ; local ($sbrName,$fhinLoc,$tmp); $[ =1 ; #------------------------------------------------------------------------------- # hsspRdAli reads and writes the sequence of HSSP + 70 alis # in: $fileHssp (must exist), # @des (1) =1, 2, ..., i.e. number of sequence to be read # (2) = swiss_id1, swiss_id2, i.e. identifiers to read # (3) = all (or undefined) # NOTE: you can give ids AND numbers ('1','paho_chick','2') .. # furthermore: # if @want = 'seq|seqAli|seqNoins' # only those will be returned (e.g. $tmp{"seq","$ct"}) # default: all 3! # out: 1|0,$rd{} with: # err: (0,$msg) # overall: # $rd{"NROWS"}= : number of alis, i.e. $#want # $rd{"NRES"}=N : number of residues in guide # $rd{"SWISS"}='sw1,sw2' : list of swiss-ids read # $rd{"0"}='pdbid' : id of guide sequence (in file header) # $rd{"$it"}='sw$ct' : swiss id of the it-th alignment # $rd{"$id"}='$it' : position of $id in final list # $rd{"sec","$itres"} : secondary structure for residue itres # $rd{"acc","$itres"} : accessibility for residue itres # $rd{"chn","$itres"} : chain for residue itres # per prot: # $rd{"seqNoins","$ct"}=sequences without insertions # $rd{"seqNoins","0"}= GUIDE sequence # $rd{"seq","$ct"}=SEQW : sequences, with all insertions # but NOT aligned!!! # $rd{"seqAli","$ct"} : sequences, with all insertions, # AND aligned (all, including guide # filled up with '.' !! #------------------------------------------------------------------------------- $sbrName="lib-br:hsspRdAli"; $fhinLoc="FHIN"."$sbrName"; $fhinLoc=~tr/[a-z]/[A-Z]/; # file existing? if ((! -e $fileInLoc) || (! &is_hssp($fileInLoc))){ print "*** ERROR $sbrName no HSSP file '$fileInLoc'\n"; return(0);} # ------------------------------ # HSSP file format settings $regexpBegAli= "^\#\# ALIGNMENTS"; # begin of reading $regexpEndAli= "^\#\# SEQUENCE PROFILE"; # end of reading $regexpSkip= "^ SeqNo"; # skip lines with pattern $nmaxBlocks= 100; # maximal number of blocks considered (=7000 alis!) $regexpBegIns= "^\#\# INSERTION LIST"; # begin of reading insertion list undef %tmp; undef @seqNo; undef %seqNo; # ------------------------------ # pointers undef %ptr_id2num; # $ptr{xyz}= N : id=xyz is the Nth ali undef @ptr_num2id; # $ptr[N]= xyz : Nth ali has id= xyz undef @ptr_numWant2numFin; # $ptr[N]= M : the Nth ali is the Mth one in the list # of all numbers wanted (i.e. = $want[M]) undef @ptr_numFin2numWant; # $ptr[M]= N : see previous, the other way around! $#want=0 if (! @want); $LreadAll=0; # ------------------------------ # digest input $#tmp=0; undef %kwd; # (1) detect keywords foreach $tmp (@want){ if ($tmp=~/^(seq|seqAli|seqNoins)$/){ $kwd{$tmp}=1; next;} push(@tmp,$tmp);} if (($#want>0) && ($#want == $#tmp) ){ # default keyworkds foreach $des ("seq","seqAli","seqNoins"){ $kwd{"$des"}=1;}} @want=@tmp; # (2) all? $LreadAll=1 if ( ! @want || ! $want[1] || ($want[1] eq "all")); if (! $LreadAll){ # (3) read some $#wantNum=$#wantId=0; foreach $want (@want) { if ($want !~ /[^0-9]/){push(@wantNum,$want);} # is number else {push(@wantId,$want);}}} # is id # ------------------------------ # get numbers/ids to read ($Lok,%rdHeader)= &hsspRdHeader($fileInLoc,"SEQLENGTH","PDBID","NR","ID"); if (! $Lok){ print "*** ERROR $sbrName reading header of HSSP file '$fileInLoc'\n"; return(0);} $tmp{"NRES"}= $rdHeader{"SEQLENGTH"};$tmp{"NRES"}=~s/\s//g; $tmp{"0"}= $rdHeader{"PDBID"}; $tmp{"0"}=~s/\s//g; $idGuide= $tmp{"0"}; $#locNum=$#locId=0; # store the translation name/number foreach $it (1..$rdHeader{"NROWS"}){ $num=$rdHeader{"NR","$it"}; $id=$rdHeader{"ID","$it"}; push(@locNum,$num);push(@locId,$id); $ptr_id2num{"$id"}=$num; $ptr_num2id[$num]=$id;} push(@locNum,"1") if ($#locNum==0); # nali=1 # ------------------------------ foreach $want (@wantId){ # CASE: input=list of names $Lok=0; # -> add to @wantNum foreach $loc (@locId){ if ($want eq $loc){$Lok=1;push(@wantNum,$ptr_id2num{"$loc"}); last;}} if (! $Lok){ print "-*- WARNING $sbrName wanted id '$want' not in '$fileInLoc'\n";}} # ------------------------------ # NOW we have all numbers to get # sort the array @wantNum= sort bynumber (@wantNum); # too many wanted if (@wantNum && ($wantNum[$#wantNum] > $locNum[$#locNum])){ $#tmp=0; foreach $want (@wantNum){ if ($want <= $locNum[$#locNum]){ push(@tmp,$want)} else { print "-*- WARNING $sbrName no $want not in '$fileInLoc'\n"; exit; }} @wantNum=@tmp;} @wantNum=@locNum if ($LreadAll); if ($#wantNum==0){ print "*** ERROR $sbrName nothing to read ???\n"; return(0);} # sort the array, again @wantNum= sort bynumber (@wantNum); # ------------------------------ # assign pointers to final output foreach $it (1..$#wantNum){ $numWant=$wantNum[$it]; $ptr_numWant2numFin[$numWant]=$it; $ptr_numFin2numWant[$it]= $numWant;} # ------------------------------ # get blocks to take $wantLast=$wantNum[$#wantNum];$#wantBlock=0; foreach $ctBlock (1..$nmaxBlocks){ $beg=1+($ctBlock-1)*70; $end=$ctBlock*70; last if ($wantLast < $beg); $Ltake=0; foreach $num(@wantNum){ if ( ($beg<=$num)&&($num<=$end) ){ $Ltake=1; last;}} if ($Ltake){ $wantBlock[$ctBlock]=1;} else{ $wantBlock[$ctBlock]=0;}} # writes ids read $tmp{"SWISS"}=""; foreach $it (1..$#wantNum){ $num=$wantNum[$it]; $tmp{"$it"}= $ptr_num2id[$num]; $tmp{"SWISS"}.="$ptr_num2id[$num]".",";} $tmp{"SWISS"}=~s/,*$//g; $tmp{"NROWS"}=$#wantNum; # ------------------------------------------------------------ # # NOTATION: # $tmp{"0",$it}= $it-th residue of guide sequnec # $tmp{$itali,$it}= $it-th residue of of ali $itali # note: itali= same numbering as in 1..$#want # i.e. NOT the position in the file # $ptr_numFin2numWant[$itali]=5 may reveal that # the itali-th ali was actually the fifth in the # HSSP file!! # # ------------------------------------------------------------ # -------------------------------------------------- # read the file finally # -------------------------------------------------- $Lok=&open_file("$fhinLoc","$fileInLoc"); if (! $Lok){print "*** ERROR $sbrName opening hssp file '$fileInLoc'\n"; return(0);} # ------------------------------ # move until first alis # ------------------------------ $ctBlock=$Lread=$#takeTmp=0; while (<$fhinLoc>){ last if ($_=~/$regexpEndAli/); # ending if ($_=~/$regexpBegAli/){ # this block to take? ++$ctBlock;$Lread=0; if ($wantBlock[$ctBlock]){ $_=~s/^[^0-9]+(\d+) -\s+(\d+).*$//; $beg=$1;$end=$2;$Lread=1; $#wantTmp=0; # local numbers foreach $num (@wantNum){ if ( ($beg<=$num) && ($num<=$end) ){ $tmp=($num-$beg)+1; print "*** $sbrName negative number $tmp,$beg,$end,\n" x 3 if ($tmp<1); push(@wantTmp,$tmp);}} next;}} next if (! $Lread); # move on next if ($_=~/$regexpSkip/); # skip line $line=$_; # -------------------- if (length($line)<52){ # no alis in line $seqNo=substr($line,1,6);$seqNo=~s/\s//g; if (! defined $seqNo{$seqNo}){ $seqNo{$seqNo}=1; push(@seqNo,$seqNo);} # NOTE: $chn,$sec,$acc are returned per residue! if (! defined $tmp{"0","$seqNo"}){ ($seqNo,$pdbNo, $tmp{"chn","$seqNo"},$tmp{"0","$seqNo"}, $tmp{"sec","$seqNo"},$tmp{"acc","$seqNo"})= &hsspRdSeqSecAccOneLine($line);} foreach $num(@wantTmp){ # add insertions if no alis $pos= $num+$beg-1; $posFin= $ptr_numWant2numFin[$pos]; $tmp{"$posFin","$seqNo"}="."; } next;} # ------------------------------ # everything fine, so read ! # ------------------------------ # -------------------- # first the HSSP stuff $seqNo=substr($line,1,6);$seqNo=~s/\s//g; if (! defined $seqNo{$seqNo}){ $seqNo{$seqNo}=1; push(@seqNo,$seqNo);} # NOTE: $chn,$sec,$acc are returned per residue! if (! defined $tmp{"0","$seqNo"}){ ($seqNo,$pdbNo, $tmp{"chn","$seqNo"},$tmp{"0","$seqNo"}, $tmp{"sec","$seqNo"},$tmp{"acc","$seqNo"})= &hsspRdSeqSecAccOneLine($line);} # -------------------- # now the alignments $alis=substr($line,52); $alis=~s/\n//g; # NOTE: @wantTmp has the positions to read in current block, # e.g. want no 75, block=71-90, => 75->4 foreach $num (@wantTmp){ $pos= $num+$beg-1; # note: beg=71 in the example above $id= $ptr_num2id[$pos]; $posFin= $ptr_numWant2numFin[$pos]; $tmp{"$posFin"}= $id; $takeTmp[$pos]= 1; print "*** $sbrName neg number $pos,$beg,$num,\n" x 3 if ($pos<1); $tmp{"seq","$posFin"}= "" if (! defined $tmp{"seq","$posFin"}); if (length($alis) < $num){ $tmp{"seq","$posFin"}.= "."; $tmp{"$posFin","$seqNo"}=".";} else { $tmp{"seq","$posFin"}.= substr($alis,$num,1); $tmp{"$posFin","$seqNo"}=substr($alis,$num,1);}}} # ------------------------------ while (<$fhinLoc>){ # skip over profiles last if ($_=~/$regexpBegIns/); } # begin reading insertion list # ---------------------------------------- # store sequences without insertions!! # ---------------------------------------- if (defined $kwd{"seqNoins"} && $kwd{"seqNoins"}){ # -------------------- $seq=""; # guide sequence foreach $seqNo(@seqNo){ $seq.=$tmp{"0","$seqNo"};} $seq=~s/[a-z]/C/g; # small caps to 'C' $tmp{"seqNoins","0"}=$seq; # -------------------- # all others (by final count!) foreach $it (1..$#wantNum){ $seq=""; foreach $seqNo(@seqNo){ $seq.=$tmp{"$it","$seqNo"};} $seq=~s/\s/\./g; # fill up insertions $seq=~tr/[a-z]/[A-Z]/; # small caps to large $tmp{"seqNoins","$it"}=$seq;} } # -------------------------------------------------- # read insertion list # # syntax of insertion list: # ....,....1....,....2....,....3....,....4 # AliNo IPOS JPOS Len Sequence # 9 58 59 5 kQLGAEi # # -------------------------------------------------- undef @insMax; # note: $insMax[$seqNo]=5 means at residue 'seqNo' foreach $seqNo (@seqNo){ # the longest insertion was 5 residues $insMax[$seqNo]=0;} while (<$fhinLoc>){ $rd=$_; last if ((! defined $kwd{"seqAli"} || ! $kwd{"seqAli"}) && (! defined $kwd{"seq"} || ! $kwd{"seq"}) ); next if ($rd =~ /AliNo\s+IPOS/); # skip key last if ($rd =~ /^\//); # end next if ($rd !~ /^\s*\d+/); # should not happen (see syntax) $rd=~s/\n//g; $line=$rd; $posIns=$rd; # current insertion from ali $pos $posIns=~s/^\s*(\d+).*$/$1/; # takeTmp[$pos]=1 if $pos to be read next if (! defined $takeTmp[$posIns] || ! $takeTmp[$posIns]); # ok -> take $line=~s/^\s*|\s*$//g; # purge leading blanks @tmp=split(/\s+/,$line); $iposIns=$tmp[2]; # residue position of insertion $seqIns= $tmp[5]; # sequence at insertion 'kQLGAEi' $nresIns=(length($seqIns) - 2); # number of residues inserted $posFin= $ptr_numWant2numFin[$posIns]; # -------------------------------------------------- # NOTE: here $tmp{"$it","$seqNo"} gets more than # one residue assigned (ref=11) # -------------------------------------------------- # change 'ACinK' -> 'ACINEWNK' $tmp{"$posFin","$iposIns"}=substr($seqIns,1,(length($seqIns)-1)); # maximal number of insertions $insMax[$iposIns]=$nresIns if ($nresIns > $insMax[$iposIns]); } close($fhinLoc); # end of reading file # -------------------------------------------------- # ------------------------------ # final sequences (not aligned) # ------------------------------ if (defined $kwd{"seq"} && $kwd{"seq"}){ foreach $it (0..$tmp{"NROWS"}){ $seq=""; foreach $seqNo(@seqNo){ $seq.=$tmp{"$it","$seqNo"};} $seq=~s/[\s\.!]//g; # replace insertions $seq=~tr/[a-z]/[A-Z]/; # all capitals $tmp{"seq","$it"}=$seq; }} # ------------------------------ # fill up insertions # ------------------------------ if (defined $kwd{"seqAli"} && $kwd{"seqAli"}){ undef %ali; # temporary for storing sequences foreach $it (0..$tmp{"NROWS"}){ $ali{$it}="";} # set for all alis # ------------------------------ foreach $seqNo(@seqNo){ # loop over residues $insMax=$insMax[$seqNo]; # loop over all alis foreach $it (0..$tmp{"NROWS"}){ # (1) CASE: no insertion if ($insMax==0){ $ali{$it}.=$tmp{"$it","$seqNo"}; next;} # (2) CASE: insertions $seqHere=$tmp{"$it","$seqNo"}; $insHere=(1+$insMax-length($seqHere)); # NOTE: dirty fill them in 'somewhere' # take first residue $ali{$it}.=substr($seqHere,1,1); # fill up with dots $ali{$it}.="." x $insHere ; # take remaining residues (if any) $ali{$it}.=substr($seqHere,2) if (length($seqHere)>1); }} # ------------------------------ # now assign to final foreach $it (0..$tmp{"NROWS"}){ $ali{$it}=~s/\s/\./g; # replace ' ' -> '.' $ali{$it}=~tr/[a-z]/[A-Z]/; # all capital $tmp{"seqAli","$it"}=$ali{$it};} undef %ali; # slim-is-in! } # ------------------------------ # save memory foreach $it (0..$tmp{"NROWS"}){ if ($it == 0){ # guide $id= $idGuide; } else { # pairs $posOriginal=$ptr_numFin2numWant[$it]; $id= $ptr_num2id[$posOriginal]; } $tmp{"$id"}= $id; foreach $seqNo (@seqNo){ undef $tmp{"$it","$seqNo"};}} undef @seqNo; undef %seqNo; undef @takeTmp; undef @idLoc; undef @want; undef @wantNum; undef @wantId; undef @wantBlock; undef %rdHeader; undef %ptr_id2num; undef @ptr_num2id; undef @ptr_numWant2numFin; undef @ptr_numFin2numWant; return(1,%tmp); } # end of hsspRdAli #============================================================================== sub hsspRdHeader { local ($fileInLoc,@kwdInLoc) = @_ ; local ($sbrName,$fhinLoc,$tmp, @kwdDefHsspTopLoc,@kwdDefHsspHdrLoc,@kwdHsspTopLoc,@kwdHsspHdrLoc,@tmp, $regexpBegHeader,$regexpEndHeader,$regexpLongId,$lenStrid,$LisLongId, %ptr,$kwd,$Lok,$Lpdb,$des,$beg,$end,$mid,$ct,$id,$strid,$ptr,$tmp); $[ =1 ; #------------------------------------------------------------------------------- # hsspRdHeader reads a HSSP header # in: $fileHssp (must exist), # @kwdInLoc = one of the default keywords # (@kwdLocHsspTop,@kwdLocHsspHeader) # in: 'nopair' surpresses reading of pair information # out: for top (e.g. NALIGN): $rd{"kwd"} # for prot (e.g. LALI): $rd{"kwd","$it"} # note: for the later number of elements (it) in # $rd{"NROWS"} # special ID=ID1, $rd{"kwd","$it"} existes for ID1 and ID2 #------------------------------------------------------------------------------- $sbrName="lib-br:hsspRdHeader";$fhinLoc="FHIN"."$sbrName";$fhinLoc=~tr/[a-z]/[A-Z]/; # file existing? if (! -e $fileInLoc || ! &is_hssp($fileInLoc) ){ print "*** ERROR $sbrName no HSSP file '$fileInLoc'\n"; return(0);} # ------------------------------ # settings describing format @kwdDefHsspTopLoc= ("PDBID","DATE","SEQBASE","PARAMETER","THRESHOLD", "REFERENCE","HEADER","COMPND","SOURCE","AUTHOR", "SEQLENGTH","NCHAIN","KCHAIN","NALIGN"); @kwdDefHsspHdrLoc= ("NR","ID","STRID","IDE","WSIM","IFIR","ILAS", "JFIR","JLAS","LALI","NGAP","LGAP","LSEQ2","ACCNUM","PROTEIN"); $regexpBegHeader= "^\#\# PROTEINS"; # begin of reading $regexpEndHeader= "^\#\# ALIGNMENTS"; # end of reading $regexpLongId= "^PARAMETER LONG-ID :YES"; # identification of long id $lenStrid= 4; # minimal length to identify PDB identifiers $LisLongId= 0; # long identifier names $ptr{"IDE"}=1;$ptr{"WSIM"}=2;$ptr{"IFIR"}=3;$ptr{"ILAS"}=4;$ptr{"JFIR"}=5;$ptr{"JLAS"}=6; $ptr{"LALI"}=7;$ptr{"NGAP"}=8;$ptr{"LGAP"}=9;$ptr{"LSEQ2"}=10; $ptr{"ACCNUM"}=11; # ------------------------------ # check input arguments $#kwdHsspTopLoc=$#kwdHsspHdrLoc=$Lpdb=$LnoPair=0; foreach $kwd (@kwdInLoc){ $Lok=0; if ($kwd eq "nopair"){ $LnoPair=1; next;} $Lpdb=1 if (! $Lpdb && ($kwd =~/^PDBID/)); foreach $des (@kwdDefHsspTopLoc) { if ($kwd eq $des){ $Lok=1; push(@kwdHsspTopLoc,$kwd); last;}} next if ($Lok || $LnoPair); foreach $des (@kwdDefHsspHdrLoc){ if ($kwd eq $des){ $Lok=1; push(@kwdHsspHdrLoc,$kwd); last;} } print "-*- WARNING $sbrName input kwd=$kwd, makes no sense??\n" if (! $Lok);} # force reading of NALI push(@kwdHsspTopLoc,"PDBID") if (! $Lpdb); # get column numbers to read # ------------------------------ # now start to read $Lok=&open_file("$fhinLoc","$fileInLoc"); if (! $Lok){print "*** ERROR $sbrName HSSP file could not be opened '$fileInLoc'\n"; return(0);} undef %tmp; # save space # ------------------------------ while ( <$fhinLoc> ) { # read top last if ($_ =~ /$regexpBegHeader/); if ($_ =~ /$regexpLongId/) { $LisLongId=1;} else{$_=~s/\n//g;$arg=$_; foreach $des (@kwdHsspTopLoc){ if ($arg =~ /^$des\s+(.+)$/){ if (defined $ok{"$des"}){ # multiple lines! $tmp="$1"."\t"; if (defined $tmp{"$des"}){ $tmp{"$des"}.=$tmp;} else{$tmp{"$des"}=$tmp;}} else {$ok{"$des"}=1;$tmp{"$des"}=$1;} if ($des=~/SEQLENGTH|NCHAIN|KCHAIN|NALIGN/){ $tmp{"$des"}=~s/^(\d+)[^0-9]+.*$/$1/;} # purge blanks last;}}}} # ------------------------------ $ct=0; # read header while ( <$fhinLoc> ) { last if ($LnoPair); # supress reading pair info last if ($_ =~ /$regexpEndHeader/); next if ($_ =~ /^ NR\./); # skip descriptors $_=~s/\n//g; $lenLine=length($_); if ($LisLongId){ $maxMid=115; $maxMid=($lenLine-56) if ($lenLine < 115); $maxEnd=109; $maxEnd=$lenLine if ($lenLine < 109); $beg=substr($_,1,56); $end=0; $end=substr($_,109) if ($lenLine >=109); $mid=substr($_,57,115); } else { $maxMid= 62; $maxMid=($lenLine-28) if ($lenLine < 90); $beg=substr($_,1,28); $end=0; $end=substr($_,90) if ($lenLine >=90); $mid=substr($_,29,90); } $end=~s/^\s*|\s*$//g; # purge leading blanks $mid=~s/^\s*|\s*$//g; # purge leading blanks # SWISS accession: hack because it may be empty! if ($lenLine > 86) { $accnum=substr($_,81,6); $accnum=~s/(\s)\s+/$1/g ; } else { $accnum=0;} # begin: counter and id $beg=~s/.+ \:\s*|\s*$//g; if (! $LisLongId) {$id=$beg;$id=~s/([^\s]+).*$/$1/; $strid=$beg;$strid=~s/$id|\s//g; } else {$id=$beg;$id=~s/(.+_\S+).*/$1/; $strid=substr($_,49,6);$strid=~s/\s//g; } $tmp=$lenStrid-1; if ( (length($strid)<$lenStrid) && ($id=~/^[0-9][A-Z0-9]{$tmp,$tmp}\s*/)){ $strid=substr($id,1,$lenStrid); } ++$ct; $tmp{"ID","$ct"}= $id; $tmp{"NR","$ct"}= $ct; $tmp{"STRID","$ct"}= $strid; # correct for ID = PDBid $tmp{"STRID","$ct"}= $id if ($strid=~/^\s*$/ && &is_pdbid($id)); $tmp{"PROTEIN","$ct"}=$end; $tmp{"ID1","$ct"}=$tmp{"PDBID"}; $tmp{"ACCNUM","$ct"}=$accnum; # middle all info $#tmp=0;@tmp=split(/\s+/,$mid); foreach $_ (@tmp) {$_=~s/\s//g;} foreach $des (@kwdHsspHdrLoc){ next if ( ! defined $ptr{"$des"}); next if ( $des =~/^ACCNUM/); $ptr=$ptr{"$des"}; $tmp{"$des","$ct"}=$tmp[$ptr]; }}close($fhinLoc); $tmp{"NROWS"}=$ct; # clean up $#kwdInLoc=$#kwdDefHsspHdrLoc=$#kwdHsspTopLoc=$#tmp= $#kwdDefHsspTopLoc=$#kwdHsspHdrLoc=0; undef %ptr; return(1,%tmp); } # end of hsspRdHeader #============================================================================== sub hsspRdSeqSecAccOneLine { local ($inLine) = @_ ; local ($sbrName,$fhinLoc,$seqNo,$pdbNo,$chn,$seq,$sec,$acc,$tmp); $[ =1 ; #------------------------------------------------------------------------------- # hsspRdSeqSecAccOneLine reads begin of one HSSP line #------------------------------------------------------------------------------- $sbrName="hsspRdSeqSecAccOneLine"; $seqNo=substr($inLine,1,6);$seqNo=~s/\s//g; $pdbNo=substr($inLine,7,5);$pdbNo=~s/\s//g; $chn= substr($inLine,13,1); $seq= substr($inLine,15,1); $sec= substr($inLine,18,1); $acc= substr($inLine,36,4);$acc=~s/\s//g; return($seqNo,$pdbNo,$chn,$seq,$sec,$acc) } # end of hsspRdSeqSecAccOneLine #============================================================================== sub is_hssp { local ($fileInLoc) = @_ ;local ($fh,$Lis); #-------------------------------------------------------------------------------- # is_hssp checks whether or not file is in HSSP format # in: $file # out: 1 if is hssp; 0 else #-------------------------------------------------------------------------------- return (0) if (! defined $fileInLoc || ! -e $fileInLoc) ; $fh="FHIN_CHECK_HSSP"; &open_file("$fh", "$fileInLoc") || return(0); $Lis=0; while ( <$fh> ) {$Lis=1 if (/^HSSP/) ; last; }close($fh); return $Lis; } # end of is_hssp #============================================================================== sub is_pdbid { local ($id) = @_ ; #-------------------------------------------------------------------------------- # is_pdbid checks whether or not id is a valid PDBid (number 3 char) # in: $file # out: 1 if is DBid, 0 else #-------------------------------------------------------------------------------- return 1 if ((length($id) <= 6) && ($id=~/^[0-9][0-9a-z]{3,3}[^0-9a-z]?/)); return 0; } # end of is_pdbid #============================================================================== sub open_file { local ($file_handle,$file_name,$log_file) = @_ ; local ($temp_name) ; #------------------------------------------------------------------------------- # open_file opens file, writes warning asf #------------------------------------------------------------------------------- $temp_name = $file_name ; $temp_name =~ s/^>>|^>//g ; if ( ($file_name =~ /^>>/ ) && ( ! -e $temp_name ) ) { print "*** INFO (open_file): append file=$temp_name, does not exist-> create it\n" ; open ($file_handle, ">$temp_name") || ( do { warn "***\t Cannot create new file: $temp_name\n" ; if ( $log_file ) { print $log_file "***\t Cannot create new file: $temp_name\n" ;} return (0); } ); close ("$file_handle") ;} open ($file_handle, "$file_name") || ( do { warn "*** ERROR lib-br:open_file: Cannot open file '$file_name'\n" ; if ( $log_file ) { print $log_file "*** lib-br:open_file: Cannot create new file '$file_name'\n" ;} return(0); } ); return(1); } # end of open_file #============================================================================== sub safWrt { local($fileOutLoc,%tmp) = @_ ; local(@nameLoc,@stringLoc,$tmp,$sbrName,$Lok); $[ =1 ; #-------------------------------------------------------------------------------- # safWrt writing an SAF formatted file of aligned strings # in: $fileOutLoc output file # = "STDOUT" -> write to screen # in: $tmp{"NROWS"} number of alignments # in: $tmp{"id", "$it"} name for $it # in: $tmp{"seq","$it"} sequence for $it # in: $tmp{"PER_LINE"} number of res per line (def=50) # in: $tmp{"HEADER"} 'line1\n,line2\n'.. # with line1= '# NOTATION ..' # out: 1|0,msg implicit: file # err: ok-> 1,ok | error -> 0,message #-------------------------------------------------------------------------------- $sbrName="lib-br:safWrt"; $fhoutLoc="FHOUT_safWrt"; # check input return(0,"*** ERROR $sbrName: no acceptable output file ($fileOutLoc) defined\n") if (! defined $fileOutLoc || length($fileOutLoc)<1 || $fileOutLoc !~/\w/); return(0,"*** ERROR $sbrName: no input given (or not input{NROWS})\n") if (! %tmp || ! defined $tmp{"NROWS"} ); return(0,"*** ERROR $sbrName: tmp{NROWS} < 1\n") if ($tmp{"NROWS"} < 1); $tmp{"PER_LINE"}=50 if (! defined $tmp{"PER_LINE"}); $fhoutLoc="STDOUT" if ($fileOutLoc eq "STDOUT"); # ------------------------------ # open new file if ($fhoutLoc ne "STDOUT") { &open_file("$fhoutLoc",">$fileOutLoc") || return(0,"*** ERROR $sbrName: failed opening fileOut=$fileOutLoc\n"); } # ------------------------------ # write header # ------------------------------ print $fhoutLoc "# SAF (Simple Alignment Format)\n","\# \n"; print $fhoutLoc $tmp{"HEADER"} if (defined $tmp{"HEADER"}); # ------------------------------ # write data into file # ------------------------------ for($itres=1; $itres<=length($tmp{"seq","1"}); $itres+=$tmp{"PER_LINE"}){ foreach $itpair (1..$tmp{"NROWS"}){ printf $fhoutLoc "%-20s",$tmp{"id","$itpair"}; # chunks of $tmp{"PER_LINE"} $chunkEnd=$itres + ($tmp{"PER_LINE"} - 1); foreach $itchunk ($itres .. $chunkEnd){ last if (length($tmp{"seq","$itpair"}) < $itchunk); print $fhoutLoc substr($tmp{"seq","$itpair"},$itchunk,1); # add blank every 10 print $fhoutLoc " " if ($itchunk != $itres && (int($itchunk/10)==($itchunk/10))); } print $fhoutLoc "\n"; } print $fhoutLoc "\n"; } print $fhoutLoc "\n"; close($fhoutLoc); $#nameLoc=$#stringLoc=0; # save space return(0,"*** ERROR $sbrName: failed to write file $fileOutLoc\n") if (! -e $fileOutLoc); return(1,"ok $sbrName"); } # end of safWrt #============================================================================== # library collected (end) #============================================================================== 1;