Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kapoormanav
    Junior Member
    • Jul 2010
    • 9

    #1

    Re: New to programming need help for inserting text

    Hi all

    I am new to programming. I have two very big files

    File 1: (>80,000 lines)

    CCDS635.1_0 123 G S 255 33 1.00 63 60 G 255 C
    CCDS635.1_0 175 C S 255 51 0.94 63 62 C 243 G
    CCDS635.1_8 259 G R 90 254 1.00 63 62 G 255 A
    CCDS635.1_14 328 A T 39 4 0.00 63 36 N 158 N
    CCDS635.1_16 80 G K 139 22 1.00 63 62 G 255 T

    File 2:

    CCDS635.1_0 1 67162857
    CCDS635.1_1 1 67143396
    CCDS635.1_2 1 67131424
    CCDS635.1_3 1 67129349
    CCDS635.1_4 1 67112976

    I want to insert all three columns of File 2 to File one at the
    respective positions according to column 1 of File 1.

    e.g.

    File 3 should be

    CCDS635.1_0 1 67162857 123 G S 255 33 1.00 63 60 G 255 C
    CCDS635.1_0 1 67162857 175 C S 255 51 0.94 63 62 C 243 G

    Can anyone help me with this?

    Manav
  • adamdeluca
    Member
    • Jul 2010
    • 95

    #2
    join 2.txt 1.txt > 3.txt

    on mac/linux

    Comment

    • kapoormanav
      Junior Member
      • Jul 2010
      • 9

      #3
      Thanks for replying.
      I tried to join but it gives error:

      join: file 1 is not in sorted order
      join: file 2 is not in sorted order

      There is another problem also..These both files have different number of lines.
      I don't want exactly merging of file, I want to create new file where
      the similar identifier get replaced by three columns of 2nd file. If
      similar identifier occurs in 4 rows of 1st file then the next 2
      columns of the same identifier in file 2 get inserted before 2nd
      column of file one for all 4 rows. It can be like find and replace
      where identifier "CCDS635.1_0" will be replaced by "CCDS635.1_0
      1 67162857" in all rows. I can do it with "sed" command of unix
      but then "sed" will do one identifier at one time and I have >1000.
      And everytime sed will create new file. So I was looking for solution
      where "identifier" replaced by new identifier with 3 columns.

      Manav

      Comment

      • kapoormanav
        Junior Member
        • Jul 2010
        • 9

        #4
        Thanks...It worked I given the option join --nocheck-order

        Manav

        Comment

        • Jose Blanca
          Member
          • Aug 2009
          • 70

          #5
          Maybe somthing like this would work:

          Code:
          #!/bin/env python
             
          def merge_files(fname1, fname2, out_fname):
            
               #read file 2 into memory
               file2 = {}
               for line in open(fname2):
                   line = line.strip()
                   if not line:
                       continue
                   line_name = line.split()[0]
                   file2[line_name] = line
           
               #now create the output
               output_fhand = open(out_fname, 'w')
               for line in open(fname1):
                   line = line.strip()
                   line_name, line = line.split(' ', 1)
                   line_name = file2[line_name]
                   output_fhand.write(' '.join((line_name, line, '\n')))
             
             if __name__ == '__main__':
                 merge_files('file1.txt', 'file2.txt', 'merged.txt')

          Comment

          • kapoormanav
            Junior Member
            • Jul 2010
            • 9

            #6
            Thanks for the help.

            awk 'BEGIN{FS=OFS="\t"}FNR==NR{a[$1]=$2}FNR!=NR{print $1,a[$1],a[$2],$2,$3,$4,$5,$6,$7,$8,$9}' exonlegth.txt coor.txt > coor1.txt

            worked for me and I was able to join the two files without sorting.

            Thanks all for help

            Manav

            Comment

            Latest Articles

            Collapse

            • SEQadmin2
              New Genomics Technologies Take Aim at Long-Standing Limits
              by SEQadmin2


              Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

              We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
              ...
              Yesterday, 10:25 AM
            • SEQadmin2
              How Immunogenomics Decodes Immunity’s Genetic Blueprint
              by SEQadmin2




              The immune system’s power comes from its genetic diversity, allowing myriad threats to be neutralized through first recognizing foreign antigens. That diversity is also what makes the immune system so difficult to study. Recent advances in sequencing technology and computational biology, however, are giving researchers new tools to understand immune responses and immune-related diseases in greater detail.

              This convergence of genetics, immunology, and computation...
              09-01-2026, 05:41 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by SEQadmin2, 09-25-2026, 09:06 AM
            0 responses
            29 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 09-23-2026, 11:05 AM
            0 responses
            24 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 09-18-2026, 11:37 AM
            1 response
            46 views
            0 reactions
            Last Post pekgio
            by pekgio
             
            Started by SEQadmin2, 09-16-2026, 10:23 AM
            1 response
            55 views
            0 reactions
            Last Post pekgio
            by pekgio
             
            Working...