Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extremely Long String Help
#2
I suggest to convert the file externally by a C program for speed
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
/* This is a C program */
int main()
{
      FILE *fp1, *fp2;
      char ch;
      fp1 = fopen("source.txt", "r");
      if (fp1 == NULL)
      {
            puts("Cannot open source.txt");
            exit(1);
      }
      fp2 = fopen("target.txt", "w");
      if (fp2 == NULL)
      {
            puts("Cannot open target.txt");
            fclose(fp1);
            exit(1);
      }
      while((ch=fgetc(fp1))!=EOF)
      {
          switch(ch){
              case 'a':
              case 'c':
              case 'g':
              case 't':
              case 'A':
              case 'C':
              case 'G':
              case 'T':
                ch = toupper(ch);
                fputc(ch,fp2);
          }
      }
      printf("File successfully converted.\n");
      return 0;
}
Edit: Actually, using fgetc() is much slower than using fread(). This can be improved a lot but on my computer it takes only 0.1 second for 10 MB..
Reply


Messages In This Thread
Extremely Long String Help - by Destry23000 - Aug-29-2018, 10:46 AM
RE: Extremely Long String Help - by Gribouillis - Aug-29-2018, 12:21 PM
RE: Extremely Long String Help - by buran - Aug-29-2018, 12:55 PM
RE: Extremely Long String Help - by buran - Aug-29-2018, 02:06 PM
RE: Extremely Long String Help - by Gribouillis - Aug-29-2018, 02:21 PM
RE: Extremely Long String Help - by Destry23000 - Aug-29-2018, 02:46 PM
RE: Extremely Long String Help - by Gribouillis - Aug-29-2018, 02:47 PM
RE: Extremely Long String Help - by Gribouillis - Aug-29-2018, 04:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Isolate a word from a long string nicocorico 2 1,604 Feb-25-2022, 01:12 PM
Last Post: nicocorico
  Split a long string into other strings with no delimiters/characters krewlaz 4 2,883 Nov-15-2019, 02:48 PM
Last Post: ichabod801
  How to create a long string by concatenating two lists nikhilkumar 11 7,681 Jul-12-2017, 05:36 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020