Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Python

    Hi, I must work with strings and i have this problem:

    I have a file with variables like this.
    a = 3234
    b = 4545
    c = 2343
    d = 7653
    e = 9237
    f = 6545
    g = 5697
    h = 1248

    I need a script that import this file and put it in rage of values.

    Is there anyone who can help me?

  • #2
    Your exact needs are not clear enough. Do you just want those values to be sorted?
    In science, "fact" can only mean "confirmed to such a degree that it would be perverse to withhold provisional assent." I suppose that apples might start to rise tomorrow, but the possibility does not merit equal time in physics classrooms.
    --Stephen Jay Gould

    Comment


    • #3
      In fact, It's not so clear.

      I just need to put in of increasing value

      Comment


      • #4
        Well if your file is formatted EXACTLY like your example, you should be able to use this python script to give you what you need.

        Code:
        python sort_example.py.py input_file > output_file
        You will need to make sure that ``sort_example.py`` and your file are in the same folder.


        The contents of ``sort_example.py`` are:


        Code:
        import sys
        
        
        in_file = sys.argv[1]
        
        in_data = open(in_file, 'rU')
        
        data_list = []
        
        # separate and organize the data into fields
        for line in in_data:
            data_list.append([x.strip() for x in line.strip('\n').split('=')])
        
        # convert the number parts to actual numbers vs strings
        for each in data_list:
            each[1] = float(each[1])
        
        
        data_list.sort(key=lambda x: x[1])
        
        for each in data_list:
            print '%s = %s' % (each[0],each[1])
        In science, "fact" can only mean "confirmed to such a degree that it would be perverse to withhold provisional assent." I suppose that apples might start to rise tomorrow, but the possibility does not merit equal time in physics classrooms.
        --Stephen Jay Gould

        Comment


        • #5
          or if you don't need to use Python you could always just do this...

          Code:
          sort -t ' ' -k3,3n myfile.txt
          /* Shawn Driscoll, Gene Expression Laboratory, Pfaff
          Salk Institute for Biological Studies, La Jolla, CA, USA */

          Comment

          Latest Articles

          Collapse

          • seqadmin
            Essential Discoveries and Tools in Epitranscriptomics
            by seqadmin




            The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
            04-22-2024, 07:01 AM
          • seqadmin
            Current Approaches to Protein Sequencing
            by seqadmin


            Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
            04-04-2024, 04:25 PM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by seqadmin, 04-11-2024, 12:08 PM
          0 responses
          59 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 04-10-2024, 10:19 PM
          0 responses
          57 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 04-10-2024, 09:21 AM
          0 responses
          51 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 04-04-2024, 09:00 AM
          0 responses
          56 views
          0 likes
          Last Post seqadmin  
          Working...
          X