Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:40:26+00:00 2026-06-09T15:40:26+00:00

This is a program which grabs lines which contains the $position AND $amino value

  • 0

This is a program which grabs lines which contains the $position AND $amino value in the first two columns.

Code:

#!/usr/bin/perl

my $id = $ARGV[0];
my $position = $ARGV[1]; # POSITION OF THE RESIDUE
my $amino= $ARGV[2]; #THREE LETTER AMINO ACID CODE IN CAPITALS
my @grabbed;

open (FILE, $id.$amino.$position.".hb2");

#CREATES AN ARRAY WITH ONLY THE VALUES FROM THE HB2 FILE. REMOVES THE HEADER OF THE FILE.

while (<FILE>) {
    if (/^-/) {
            push @grabbed, $_;
            while (<FILE>) {
            last if /^$/;
            push @grabbed, $_;
            }

    }
}
close (FILE);


for ( @grabbed ) {
my @f = split;
if (( $f[2] == "-"."00".$position."-".$amino ) or ($f[0] == "-"."00".$position."-".$amino)) {
    push @line, $id.$amino.$position, " ",$_;
}
}
print @line;

Partial input data :

-0007-ARG NH2 -0009-GLN OE1 3.24 SS   2  6.00 143.3  2.38 105.9  95.8     1 #CASE 1
-0008-GLU N   -0008-GLU OE1 2.62 MS   0 -1.00 120.8  1.96 102.3 103.4     2
-0011-ILE N   -0117-ARG O   2.87 MM 106  4.90 144.0  2.00 127.5 139.0     3 
-0117-ARG N   -0011-ILE O   2.75 MM 106  4.90 160.4  1.79 153.2 148.6     4 #CASE 2
-0016-SER N   -0012-THR O   2.89 MM   4  6.00 156.2  1.95 149.8 154.8     5 #CASE 3
-0017-ALA N   -0013-LEU O   3.10 MM   4  6.24 152.8  2.17 143.4 149.7     6
-0018-GLU N   -0014-ARG O   3.04 MM   4  6.24 154.1  2.11 147.2 154.2     7
-0019-ILE N   -0015-GLY O   2.90 MM   4  6.16 155.8  1.96 150.7 156.2     8
-0016-SER OG  -0188-THR OG1 2.72 SS 172  5.92 172.0  1.73  98.9  99.6     9
-0188-THR OG1 -0016-SER OG  2.72 SS 172  5.92 163.7  1.75 116.4 115.1    10

Question :

In order to generalize the program I made the match as :

( $f[2] == "-"."00".$position."-".$amino ) or ($f[0] == "-"."00".$position."-".$amino)

The format is always four digits after “-” before $amino (-0188-THR). I suddenly realized that my code wouldnt work if the $position input is “one digit(like CASE 1)” or “three digit (like CASE 2, column 1)”. Since I hard coded it as format as “-” followed by two zeros and THEN position, it has to always be two digit input to work.

I am stumped to generalize this code so that I could put in 1/2/3 digits. The remaining digits would always be replaced by zeros.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:40:27+00:00Added an answer on June 9, 2026 at 3:40 pm

    First, == operator in perl used only for comparing arithmetic expressions
    To compare strings you should use eq operator
    Second, to format strings from digits you can use sprintf function.

    if ($f[2] eq "-".sprintf("%04d", $position)."-".$amino ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a program which runs. This is part of the code: FileName
Alright, I have this program to sparse code in Newick Format, which extracts both
I wrote this short program which has a tiny GUI. Its supposed to allow
I'm a newbie and I know that this C program which I got somewhere
I have this program in Python which should save text files to a folder
This program I'm doing is about a social network, which means there are users
I got a C# program which opens a EventWaitHandle like this to get triggered
Is there a program which I can run like this: py2py.py < orig.py >
I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have a program which does a system call: latex somefile.latex This runs ok,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.