Unconfigured Ad

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

    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
              Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
              by SEQadmin2


              Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

              The systematic characterization of the human proteome has
              ...
              07-20-2026, 11:48 AM
            • SEQadmin2
              Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
              by SEQadmin2



              Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
              ...
              07-09-2026, 11:10 AM
            • SEQadmin2
              Cancer Drug Resistance: The Lingering Barrier to Rising Survival
              by SEQadmin2



              Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

              There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
              07-08-2026, 05:17 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by SEQadmin2, Today, 11:41 AM
            0 responses
            8 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 07-20-2026, 11:10 AM
            0 responses
            21 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 07-13-2026, 10:26 AM
            0 responses
            34 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 07-09-2026, 10:04 AM
            0 responses
            44 views
            0 reactions
            Last Post SEQadmin2  
            Working...