Recent

Author Topic: How to determine if a result is an integer? [SOLVED]  (Read 18920 times)

BornAgain

  • New Member
  • *
  • Posts: 34
Re: How to determine if a result is an integer?
« Reply #30 on: September 02, 2021, 07:56:06 pm »
Thank you, @bytebites. I had tried this, but it didn't work:

Code: Pascal  [Select][+][-]
  1.         for J := 0 to ORFList.Count - 2 do
  2.         begin
  3.           s := Length(ORFList[J]);
  4.           for K := (J+1) to ORFList.Count-1 do
  5.           begin
  6.             t := Length(ORFList[ORFList.Count - 1]);
  7.             if s < t then ORFList[J] := ORFList[ORFList.Count - 1]
  8.             else continue;
  9.           end;
  10.         end;    

I tried your code, (which seems incredibly simple!), but it wasn't clear what I pass to the function for the Index1 and Index2. Also, if the two indexes are constants, how does the single line of code in the function find the longest string?

BornAgain

  • New Member
  • *
  • Posts: 34
Re: How to determine if a result is an integer?
« Reply #31 on: September 02, 2021, 08:47:40 pm »
Thank you, @y.ivanov. Really appreciate your help. I finally couldn't resist the temptation of just running your code. I didn't want to do so since I didn't understand much of it. But now I finally did :-). It gave me a ElnoutError (File not open). I was wondering about that when I saw a WriteLn statement. Perhaps that was obvious that I needed to have opened Text file? And the WriteLn was to this text file? Sorry for the newbie questions?

alpine

  • Hero Member
  • *****
  • Posts: 1037
Re: How to determine if a result is an integer?
« Reply #32 on: September 02, 2021, 10:16:54 pm »
It must be compiled as "Simple console program". Then WriteLn with no specified file as 1-st argument writes to the standard output, which is the console.

Edit:
Sorry,  I had to assume that you're Pascal novice (you've asked about modulo operation).

The EInOutError is probably because you're trying the code inside a GUI program and the standard INPUT and OUTPUT files are not open in that case. Those are assumed when you use Read/ReadLn or Write/WriteLn without Text file as 1-st argument. See https://www.freepascal.org/docs-html/rtl/system/write.html, the second remark in yellow.

As an alternative (in GUI) you can use:
Code: Pascal  [Select][+][-]
  1. // msg declared as:
  2. //    var msg: String;
  3. WriteStr(msg, 'Frame +', (2 + FN) mod 3 + 1, // 0->3, 1->1, 2->2
  4.               ', Start: ', Start[FN],
  5.               ', End: ', I,
  6.               ', Seq: ', Copy(AData, Start[FN], FLen));
  7. ShowMessage(msg);
  8.  
« Last Edit: September 03, 2021, 04:52:17 pm by y.ivanov »
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

BornAgain

  • New Member
  • *
  • Posts: 34
Re: How to determine if a result is an integer?
« Reply #33 on: September 03, 2021, 07:46:59 pm »
Thanks, @y.ivanov. I certainly am! So thanks for the explanation. You are right - I was trying it inside the GUI program I'd written (the only type I know). I'll try your modification for the GUI. I wish there was a REAL beginner's manual or book to help someone like me understand what they are doing! For example, I have no idea what the initial parts of a program even are (type, public, private, implementation, etc.). I just blindly follow an example that works! Anyway, thanks for being patient with me.

Just checked by placing your code inside my GUI code - and it works. Thank you! When I try with a real sequence, however, it is giving me an error during compilation: "String exceeds line" (the sequence is 1501 characters, but I thought "string" essentially had no limit to the length.
« Last Edit: September 03, 2021, 08:09:12 pm by BornAgain »

alpine

  • Hero Member
  • *****
  • Posts: 1037
Re: How to determine if a result is an integer?
« Reply #34 on: September 03, 2021, 08:18:33 pm »
@BornAgain
Probably the compiler itself has a limit when parsing the source file. Try splitting the string in smaller chunks:
Code: Pascal  [Select][+][-]
  1. Data: String =
  2.   'ACTGCTAATGA...' +
  3.   'TTTGGACTTGG...' +
  4.   'TAGCGTTACCTG...' +
  5.   ...
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to determine if a result is an integer?
« Reply #35 on: September 03, 2021, 09:34:46 pm »
Hi!

Turbo Pascal had a limitation of 132 chars per line.

fpc allows AnsiStrings which can contain up to 2GB bytes.

Must be enough to put a whole unit in only one line.
Delete the lineEndings ....

And enough for very long DNA strings.

Winni

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to determine if a result is an integer?
« Reply #36 on: September 03, 2021, 10:54:31 pm »
Just checked by placing your code inside my GUI code - and it works. Thank you! When I try with a real sequence, however, it is giving me an error during compilation: "String exceeds line" (the sequence is 1501 characters, but I thought "string" essentially had no limit to the length.

Hi!

This message tells you that there is a closing '  at the end of the line is missing.
Nothing else.

Winni

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: How to determine if a result is an integer?
« Reply #37 on: September 03, 2021, 11:26:42 pm »
Going to the beginning.
Create an artificial string.
Tally all the ATG and get their positions
Tally all the TAG and get their positions
Compare positions, if they suit (multiple of three apart), then write the relevant parts of the original string.
Code: Pascal  [Select][+][-]
  1. program tally;
  2.  
  3. Type  
  4.   intArray = Array of integer;
  5.  
  6. // =========  number of partstring in somestring =============//
  7.  function tally(somestring:pchar;partstring:pchar;var arr: intarray ):integer;
  8. var
  9. i,j,ln,lnp,count,num:integer ;
  10. filler:boolean;
  11. label
  12. skip ,start,return;
  13. begin
  14.  ln:=length(somestring);
  15. lnp:=length(partstring);
  16. filler:=false;
  17. start:
  18. count:=0;
  19. i:=-1;
  20. repeat
  21. i:=i+1;
  22.    if somestring[i] <> partstring[0] then goto skip ;
  23.      if somestring[i] = partstring[0] then
  24.      begin
  25.      for j:=0 to lnp-1 do
  26.      begin
  27.      if somestring[j+i]<>partstring[j] then goto skip;
  28.      end;
  29.       count:=count+1;
  30.       if filler = true then arr[count]:=i+1 ;
  31.       i:=i+lnp-1;
  32.      end ;
  33.    skip:
  34.    until i>=ln-1 ;
  35. SetLength(arr,count); // size is now known, repeat the operation to fil arr
  36. arr[0]:=count;        // save tally in [0]
  37. num:=count;
  38. if filler=true then goto return;
  39. filler:=true;
  40.   goto start;
  41.    return:
  42.   result:=num;
  43. end; {tally}
  44.  
  45.     //=========== Use =========== //
  46.  
  47.  var
  48.  arr,arr2:intarray;
  49.  p:pchar;
  50.  s,s2,s3:ansistring;
  51.  i,j,num,diff:integer;
  52.  comma:string;
  53.  label
  54.  lbl;
  55.  
  56.  begin
  57.  s:='ACTGCTAATGATTTGGACTTGGTAGCGTTACCTG';
  58.  s2:='XACTGCTAXATTTGGACTTGGTAGCGTTACCTG';
  59.  s3:='XYACTGCTAATGATTTGGACTTGGTAGCGTTACCTG';
  60.  for i:=1 to 3 do
  61.  begin
  62.  s:=s+s2+s3;
  63.  end;
  64.  
  65.  p:=pchar(s);        // cast
  66.  writeln('The string',' length = ',length(s));
  67.  writeln(s);
  68.  writeln;
  69.  num:=tally(p,'ATG',arr);
  70.  writeln('Tally of ATG  ',num);
  71.  
  72.  
  73.  writeln('Positions:');
  74.   for i:=1 to arr[0] do
  75.   begin
  76.   if i<arr[0] then comma:=',' else comma:='';
  77.  write(arr[i],comma);
  78.  end;
  79.  writeln;
  80.  writeln;
  81.  
  82.  num:=tally(p,'TAG',arr2);
  83.  writeln('Tally of TAG  ',num);
  84.  
  85.  
  86.  writeln('Positions:');
  87.   for i:=1 to arr2[0] do
  88.   begin
  89.   if i<arr2[0] then comma:=',' else comma:='';
  90.  write(arr2[i],comma);
  91.  end;
  92.   writeln;
  93.   writeln;
  94.  
  95.  for i:=1 to arr[0]  do
  96.  for j:=1 to arr2[0] do
  97.  begin
  98.  begin
  99.  if ((i>arr[0]) or (j>arr2[0])) then goto lbl; // outwith bounds.
  100.    diff:= abs(arr[i]-arr2[j]);
  101.  if (( diff mod 3=0) and (arr[i] < arr2[j])) then writeln(s[arr[i] .. arr2[j]+2],'   ',arr[i],' to ',arr2[j]+2);
  102.  end ;
  103.  end;
  104.   lbl:
  105.   writeln;
  106.  writeln('Press enter to end');
  107.  
  108.    readln;
  109.  end.
  110.  
  111.      
« Last Edit: September 03, 2021, 11:32:03 pm by BobDog »

alpine

  • Hero Member
  • *****
  • Posts: 1037
Re: How to determine if a result is an integer?
« Reply #38 on: September 04, 2021, 12:57:16 am »
@BobDog
Projecting i occurrences of ATG over j occurrences of TAG in:
Code: Pascal  [Select][+][-]
  1.  for i:=1 to arr[0]  do
  2.  for j:=1 to arr2[0] do
  3.  begin
  4.  begin
  5.    ...
Will give you two sequences in the case of:
Code: [Select]
ATG xxx TAG xxx TAGInstead of one (the 2-nd TAG has no start codon).

The projection wouldn't do the job, there is no point to scan ATG, TAG positions separately.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: How to determine if a result is an integer?
« Reply #39 on: September 04, 2021, 02:34:18 am »

Hello y.ivanof.
I really have to bundle the two arrays to get all starts and stops.
If I make the initial string shorter and on one line then things look clearer.
Code: Pascal  [Select][+][-]
  1. program tally;
  2.    uses
  3.    crt;
  4. Type  
  5.   intArray = Array of integer;
  6.  
  7. // =========  number of partstring in somestring =============//
  8.  function tally(somestring:pchar;partstring:pchar;var arr: intarray ):integer;
  9. var
  10. i,j,ln,lnp,count,num:integer ;
  11. filler:boolean;
  12. label
  13. skip ,start,return;
  14. begin
  15.  ln:=length(somestring);
  16. lnp:=length(partstring);
  17. filler:=false;
  18. start:
  19. count:=0;
  20. i:=-1;
  21. repeat
  22. i:=i+1;
  23.    if somestring[i] <> partstring[0] then goto skip ;
  24.      if somestring[i] = partstring[0] then
  25.      begin
  26.      for j:=0 to lnp-1 do
  27.      begin
  28.      if somestring[j+i]<>partstring[j] then goto skip;
  29.      end;
  30.       count:=count+1;
  31.       if filler = true then arr[count]:=i+1 ;
  32.       i:=i+lnp-1;
  33.      end ;
  34.    skip:
  35.    until i>=ln-1 ;
  36. SetLength(arr,count); // size is now known, repeat the operation to fil arr
  37. arr[0]:=count;        // save tally in [0]
  38. num:=count;
  39. if filler=true then goto return;
  40. filler:=true;
  41.   goto start;
  42.    return:
  43.   result:=num;
  44. end; {tally}
  45.  
  46.     //=========== Use =========== //
  47.  
  48.  var
  49.  arr,arr2:intarray;
  50.  p:pchar;
  51.  s,s2,s3:ansistring;
  52.  i,j,num,diff:integer;
  53.  comma:string;
  54.  label
  55.  lbl;
  56.  
  57.  begin
  58.  s:='ACTGCTAATGATTTGGACTTGGTAGCGTTACCTG';
  59.  s2:='XACTGCTAXATTTGGACTTGGTAGCGTTACCTG';
  60.  s3:='XYACTGCTAATGATTTGGACTTGGTAGCGTTACCTG';
  61.  for i:=1 to 1 do
  62.  begin
  63.  s:=s+s2+s3;
  64.  end;
  65.  
  66.  p:=pchar(s);        // cast
  67.  writeln('The string',' length = ',length(s));
  68.  writeln(s);
  69.  writeln;
  70.  num:=tally(p,'ATG',arr);
  71.  writeln('Tally of ATG  ',num);
  72.  
  73.  
  74.  writeln('Positions:');
  75.   for i:=1 to arr[0] do
  76.   begin
  77.   if i<arr[0] then comma:=',' else comma:='';
  78.  write(arr[i],comma);
  79.  end;
  80.  writeln;
  81.  writeln;
  82.  
  83.  num:=tally(p,'TAG',arr2);
  84.  writeln('Tally of TAG  ',num);
  85.  
  86.  
  87.  writeln('Positions:');
  88.   for i:=1 to arr2[0] do
  89.   begin
  90.   if i<arr2[0] then comma:=',' else comma:='';
  91.  write(arr2[i],comma);
  92.  end;
  93.   writeln;
  94.   writeln;
  95.  
  96.  for i:=1 to arr[0]  do
  97.  for j:=1 to arr2[0] do
  98.  begin
  99.  begin
  100.  if ((i>arr[0]) or (j>arr2[0])) then goto lbl; // outwith bounds.
  101.    diff:= abs(arr[i]-arr2[j]);
  102.  if (( diff mod 3=0) and (arr[i] < arr2[j])) then writeln(s[arr[i] .. arr2[j]+2],'   ',arr[i],' to ',arr2[j]+2);
  103.  end ;
  104.  end;
  105.   lbl:
  106.   writeln;
  107.    for i:=1 to length(s) do
  108.    begin
  109.    TextColor(white);
  110.    if (i>=8) and (i<=25) then textcolor(green);
  111.    write(s[i]);
  112.    end;
  113.    writeln;
  114.  
  115.    for i:=1 to length(s) do
  116.    begin
  117.    TextColor(white);
  118.    if (i>=8) and (i<=58) then textcolor(green);
  119.    write(s[i]);
  120.    end;
  121.    writeln;
  122.  
  123.     for i:=1 to length(s) do
  124.    begin
  125.    TextColor(white);
  126.    if (i>=8) and (i<=94) then textcolor(green);
  127.    write(s[i]);
  128.    end;
  129.    writeln;
  130.  
  131.     for i:=1 to length(s) do
  132.    begin
  133.    TextColor(white);
  134.    if (i>=77) and (i<=94) then textcolor(green);
  135.    write(s[i]);
  136.    end;
  137.    writeln;
  138.  
  139.   writeln;
  140.  writeln('Press enter to end');
  141.  
  142.    readln;
  143.  end.
  144.  
  145.      
If you could give an example of your method (console, I don't use Lazarus or forms), maybe I'll see what you mean.



alpine

  • Hero Member
  • *****
  • Posts: 1037
Re: How to determine if a result is an integer?
« Reply #40 on: September 04, 2021, 10:43:07 am »
@BobDog,
I've already wrote it in my Reply #26. If you have time to read the last few posts, you'll see that BornAgain had some difficulties to try it in console mode.

My user name is y.ivanov, not y.ivanof
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: How to determine if a result is an integer?
« Reply #41 on: September 04, 2021, 11:30:01 am »

Thanks y.ivanov, I see your method now.

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: How to determine if a result is an integer?
« Reply #42 on: September 04, 2021, 08:22:40 pm »
I am unsure how long a DNA sequence can be.
Forensic detectives (on telly), doesn't go so deeply into the subject, catching villains is their priority.
However, as a test I have created quite a long fake sequence.
And tested my parser to cope with it.
Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. program tally;
  4.  
  5.    type
  6.  stringsegment=record
  7.  seg:ansistring;
  8.  pos:int32;
  9.  lngth:int32;
  10.  end;
  11.  
  12. Type  
  13.   intArray = Array of int32;
  14.   segarray = array of stringsegment;
  15.  
  16. // =========  number of partstring in somestring =============//
  17.  function tally(somestring:pchar;partstring:pchar;var arr: intarray ):integer;
  18. var
  19. i,j,ln,lnp,count,num:integer ;
  20. filler:boolean;
  21. label
  22. skip ,start,return;
  23. begin
  24.  ln:=length(somestring);
  25. lnp:=length(partstring);
  26. filler:=false;
  27. start:
  28. count:=0;
  29. i:=-1;
  30. repeat
  31. i:=i+1;
  32.    if somestring[i] <> partstring[0] then goto skip ;
  33.      if somestring[i] = partstring[0] then
  34.      begin
  35.      for j:=0 to lnp-1 do
  36.      begin
  37.      if somestring[j+i]<>partstring[j] then goto skip;
  38.      end;
  39.       count:=count+1;
  40.       if filler = true then arr[count]:=i+1 ;
  41.       i:=i+lnp-1;
  42.      end ;
  43.    skip:
  44.    until i>=ln-1 ;
  45. SetLength(arr,count); // size is now known, repeat the operation to fil arr
  46. arr[0]:=count;        // save tally in [0]
  47. num:=count;
  48. if filler=true then goto return;
  49. filler:=true;
  50.   goto start;
  51.    return:
  52.   result:=num;
  53. end; {tally}
  54.  
  55.  
  56.  
  57. procedure dubblesort(var arr :array of stringsegment);
  58. var
  59. n1,n2:int32;
  60. temp:stringsegment;
  61. begin
  62. for n1:=low(arr) to high(arr)-1 do
  63. begin
  64.  for n2:=n1+1 to high(arr)  do
  65.  begin
  66.  if length(arr[n1].seg) > length(arr[n2].seg) then
  67.  begin
  68.   temp:=arr[n1];
  69.     arr[n1]:=arr[n2];
  70.     arr[n2]:=temp;
  71.     end;
  72.  end;
  73.  end;
  74.   // now sort the start pos
  75.  for n1:=low(arr) to high(arr)-1 do
  76. begin
  77.  for n2:=n1+1 to high(arr)  do
  78.  begin
  79.  if ((length(arr[n1].seg) = length(arr[n2].seg)) and (arr[n1].pos > arr[n2].pos))  then
  80.  begin
  81.   temp:=arr[n1];
  82.     arr[n1]:=arr[n2];
  83.     arr[n2]:=temp;
  84.     end;
  85.  end;
  86.  end;
  87.  
  88. end;
  89.  
  90.  
  91.  
  92. procedure getsegments(s:ansistring;first:ansistring;second:ansistring;var segs:segarray);
  93. var
  94. p:pchar;
  95. arr,arr2: array of integer;
  96. i,j,diff,counter:int32;
  97. label
  98. lbl;
  99. begin
  100.  counter:=0;
  101.  diff:=0;
  102. p:=pchar(s);
  103.   tally(p,pchar(first),arr);
  104.   tally(p,pchar(second),arr2);
  105.   for i:=1 to arr[0]  do
  106.  for j:=1 to arr2[0] do
  107.  begin
  108.  begin
  109.  if ((i>arr[0]) or (j>arr2[0])) then goto lbl; // outwith bounds.
  110.    diff:= abs(arr[i]-arr2[j]);
  111.  if (( diff mod 3=0) and (arr[i] < arr2[j])) then
  112.    begin
  113.     setlength(segs,counter+1);
  114.    segs[counter].seg:=s[arr[i] .. arr2[j]+2];
  115.    segs[counter].pos:=arr[i];
  116.    segs[counter].lngth:=length(segs[counter].seg);
  117.    counter:=counter+1;
  118.    end;
  119.  
  120.  end ;
  121.  end;
  122.  
  123.   lbl:
  124.     dubblesort(segs);
  125. end;
  126.  
  127.     //=========== Use =========== //
  128.  
  129.  var
  130.  arr,arr2:intarray;
  131.  p:pchar;
  132.  s,s1,s2,s3:ansistring;
  133.  i,j,num,diff,lastlength:int32;
  134.  
  135.  
  136.  segs:array of stringsegment;
  137.  label
  138.  lbl;
  139.  
  140.  begin
  141.  s1:= 'ACTGCTAATGATTTGGACTTGGTAGCGTTACCTG';
  142.  s:= 'GTCTCGTGGGCTCGGAGATGTGTATAAGAGACAG';
  143.  s2:='ACTGCTAXATTTGGACTTGGTAGCGTTACCTG';
  144.  s3:='ACTGCTAATGATTTGGACTTGGTAGCGTTACCTG';
  145.  for i:=1 to 70 do
  146.  begin
  147.  s:=(s1+s2+s3+s);
  148.  end;
  149.  
  150.     writeln ('The string');
  151.    writeln(s);
  152.    writeln('Length = ',length(s));
  153.    writeln;
  154.  
  155.  
  156.   getsegments(s,'ATG','TAG',segs);
  157.  
  158.   for i:=low(segs) to high(segs) do
  159.   begin
  160.   if ( length(segs[i].seg) < 100 ) then
  161.   write(segs[i].seg,' [start = ':5,segs[i].pos:4,', length = ',segs[i].lngth,']');
  162.  
  163.   if ( length(segs[i].seg) >= 100 ) then
  164.   begin
  165.    if (lastlength <>   length(segs[i].seg)) then writeln;
  166.   write('. . . [start = ':5,segs[i].pos:4,', length = ',segs[i].lngth,']');
  167.    end;
  168.   lastlength:= length(segs[i].seg);
  169.   writeln;
  170.   end;
  171.  
  172.  writeln('Press enter to end');
  173.  
  174.    readln;
  175.  end.
  176.  
  177.      
Or if the end triplet is not repeated in the segment:
Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. program tally;
  4.  
  5.    type
  6.  stringsegment=record
  7.  seg:ansistring;
  8.  pos:int32;
  9.  lngth:int32;
  10.  end;
  11.  
  12. Type  
  13.   intArray = Array of int32;
  14.   segarray = array of stringsegment;
  15.  
  16. // =========  number of partstring in somestring =============//
  17.  function tally(somestring:pchar;partstring:pchar;var arr: intarray ):int32;
  18. var
  19. i,j,ln,lnp,count,num:integer ;
  20. filler:boolean;
  21. label
  22. skip ,start,return;
  23. begin
  24.  ln:=length(somestring);
  25. lnp:=length(partstring);
  26. filler:=false;
  27. start:
  28. count:=0;
  29. i:=-1;
  30. repeat
  31. i:=i+1;
  32.    if somestring[i] <> partstring[0] then goto skip ;
  33.      if somestring[i] = partstring[0] then
  34.      begin
  35.      for j:=0 to lnp-1 do
  36.      begin
  37.      if somestring[j+i]<>partstring[j] then goto skip;
  38.      end;
  39.       count:=count+1;
  40.       if filler = true then arr[count]:=i+1 ;
  41.       i:=i+lnp-1;
  42.      end ;
  43.    skip:
  44.    until i>=ln-1 ;
  45. SetLength(arr,count); // size is now known, repeat the operation to fil arr
  46. arr[0]:=count;        // save tally in [0]
  47. num:=count;
  48. if filler=true then goto return;
  49. filler:=true;
  50.   goto start;
  51.    return:
  52.   result:=num;
  53. end; {tally}
  54.  
  55.  
  56.  
  57. procedure dubblesort(var arr :array of stringsegment);
  58. var
  59. n1,n2:int32;
  60. temp:stringsegment;
  61. begin
  62. for n1:=low(arr) to high(arr)-1 do
  63. begin
  64.  for n2:=n1+1 to high(arr)  do
  65.  begin
  66.  if length(arr[n1].seg) > length(arr[n2].seg) then
  67.  begin
  68.   temp:=arr[n1];
  69.     arr[n1]:=arr[n2];
  70.     arr[n2]:=temp;
  71.     end;
  72.  end;
  73.  end;
  74.   // now sort the start pos
  75.  for n1:=low(arr) to high(arr)-1 do
  76. begin
  77.  for n2:=n1+1 to high(arr)  do
  78.  begin
  79.  if ((length(arr[n1].seg) = length(arr[n2].seg)) and (arr[n1].pos > arr[n2].pos))  then
  80.  begin
  81.   temp:=arr[n1];
  82.     arr[n1]:=arr[n2];
  83.     arr[n2]:=temp;
  84.     end;
  85.  end;
  86.  end;
  87.  
  88. end;
  89.  
  90. procedure getsegments(s:ansistring;first:ansistring;second:ansistring;var segs:segarray);
  91. var
  92. p:pchar;
  93. arr,arr2: array of integer;
  94. i,j,diff,counter,t2:int32;
  95. label
  96. lbl;
  97. begin
  98.  counter:=0;
  99.  diff:=0;
  100. p:=pchar(s);
  101.   tally(p,pchar(first),arr);
  102.   tally(p,pchar(second),arr2);
  103.   for i:=1 to arr[0]  do
  104.  for j:=1 to arr2[0] do
  105.  begin
  106.  begin
  107.  if ((i>arr[0]) or (j>arr2[0])) then goto lbl; // outwith bounds.
  108.    diff:= abs(arr[i]-arr2[j]);
  109.    t2:=pos(second,s[arr[i] .. arr2[j]]);
  110.  if (( diff mod 3=0) and (arr[i] < arr2[j])) and (t2=0)    then
  111.    begin
  112.     setlength(segs,counter+1);
  113.    segs[counter].seg:=s[arr[i] .. arr2[j]+2];
  114.    segs[counter].pos:=arr[i];
  115.    segs[counter].lngth:=length(segs[counter].seg);
  116.    counter:=counter+1;
  117.    end;
  118.  
  119.  end ;
  120.  end;
  121.  
  122.   lbl:
  123.     dubblesort(segs);
  124. end;
  125.  
  126.     //=========== Use =========== //
  127.  
  128.  var
  129.  arr,arr2:intarray;
  130.  p:pchar;
  131.  s,s1,s2,s3:ansistring;
  132.  i,j,num,diff,lastlength:int32;
  133.  
  134.  
  135.  segs:array of stringsegment;
  136.  label
  137.  lbl;
  138.  
  139.  begin
  140.  s1:='ACTGCTAATGATTTGGACTTGGTAGCGTTACCTG';
  141.  s:= 'ACTGCTAATGATTTGGAATTTGGACTTGGTAGCGTTACCTG';
  142.  s2:='ACTGCTAATGATTTGGACTTTGGAATTTGGACTTGGGTAGCGTTACCTG';
  143.  s3:='ACTGCTAATGATTTGGACTTGGACTTGGTAGCGTTACCTG';
  144.  for i:=1 to 70 do
  145.  begin
  146.  s:=(s1+s2+s3+s);
  147.  end;
  148.  
  149.     writeln ('The string');
  150.    writeln(s);
  151.    writeln('Length = ',length(s));
  152.    writeln;
  153.  
  154.  
  155.   getsegments(s,'ATG','TAG',segs);
  156.  
  157.   for i:=low(segs) to high(segs) do
  158.   begin
  159.   if ( length(segs[i].seg) < 100 ) then
  160.   write(segs[i].seg,' [start = ':5,segs[i].pos:4,', length = ',segs[i].lngth,']');
  161.  
  162.   if ( length(segs[i].seg) >= 100 ) then
  163.   begin
  164.    if (lastlength <>   length(segs[i].seg)) then writeln;
  165.   write('. . . [start = ':5,segs[i].pos:4,', length = ',segs[i].lngth,']');
  166.    end;
  167.   lastlength:= length(segs[i].seg);
  168.   writeln;
  169.   end;
  170.     writeln;
  171.  
  172.  writeln('Press enter to end');
  173.  
  174.    readln;
  175.  end.
  176.  
  177.      
« Last Edit: September 04, 2021, 10:43:11 pm by BobDog »

alpine

  • Hero Member
  • *****
  • Posts: 1037
Re: How to determine if a result is an integer?
« Reply #43 on: September 07, 2021, 10:43:28 am »
@BobDog,
Regarding your extensive use of goto statement instead of else clauses - I am just curious, have you started programming on a Basic language?

@BornAgain,
Quote
I  wish there was a REAL beginner's manual or book to help someone like me understand what they are doing! For example, I have no idea what the initial parts of a program even are (type, public, private, implementation, etc.). I just blindly follow an example that works!
I can't recommend a single book or course on Free Pascal, but you can browse at: https://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines, maybe you can find something helpful.
Since FPC is mostly compatible with the Delphi, perhaps you can try some of Marco Cantù's  books from the "Mastering Delphi" sequence, or "Essential Pascal". 
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Jonvro

  • Newbie
  • Posts: 4
Re: How to determine if a result is an integer?
« Reply #44 on: September 07, 2021, 11:40:53 am »
@BornAgain: I found a useful PDF where all this stuff is explained to some extent https://pdfcoffee.com/learningpdf-learninghowardpageclark-blanc-pdf-free.html.
« Last Edit: September 07, 2021, 04:50:06 pm by Jonvro »

 

TinyPortal © 2005-2018