Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CrLs
    Junior Member
    • Jan 2014
    • 6

    #1

    Slicing genbank file using biopython [problem]

    Hello, i'd like to slice multiple genbank files using biopython at different location:
    slice genome 1 at location 1. I have already coded this :
    >>> ident = 'AE009948','AE009947'
    >>> coor = '1256617:1311411','1973169:2005648'
    >>> for i in ident:
    from Bio import Entrez, SeqIO
    Entrez.email = "[email protected]"
    handle = Entrez.efetch(db="nucleotide", id=i, rettype="gb")
    record = SeqIO.read(handle, "gb")
    >>> for j in coor:
    sub_record = record[j]
    Problem is : i get this error : ValueError: Invalid index
    or TypeError: 'SeqRecord' object is not callable if i try with : sub_record = record(j)
    Can someone help me?
    Thanks by advance
  • dpryan
    Devon Ryan
    • Jul 2011
    • 3478

    #2
    You have a couple problems. Firstly the values inside "coor" are strings, not ranges. So trying to use them directly as ranges won't work. You could try:

    Code:
    coors = [[1256617, 1311411], [1973169, 2005648]]
    for bounds in coors :
        sub_record = record[bounds[0]:bounds[1]]
    and that would likely work. Of course, then you run into the problem that the coordinates you gave are beyond the end of the sequence you retrieved. Also, you ask for two records and then overwrite the first with the second. I presume you want the "foo j in coor :" loop inside the "for i in indent :" loop.

    Comment

    • CrLs
      Junior Member
      • Jan 2014
      • 6

      #3
      Yeah you are right, i want to loop "for bounds in coors" inside the "for i in ident", i ll try your suggestion then tell you if it works. Anyway, i thank you for you time !

      Edit : i want to slice the first genome with locations one, then slice second genome with the second locations ( later it will be 100 genome and 100 locations )

      Anyway i'll try with your suggestion and come back later !
      Last edited by CrLs; 01-20-2014, 04:58 AM.

      Comment

      • dpryan
        Devon Ryan
        • Jul 2011
        • 3478

        #4
        Ah, then just get rid of the "for j in coor" loop, since you're already setting the index for coor if you nest that within the "for i in indent" loop.

        Comment

        • CrLs
          Junior Member
          • Jan 2014
          • 6

          #5
          well, at the moment it give me back this error :
          TypeError: slice indices must be integers or None or have an __index__ method
          Should i change my coor for something else ?
          And about to remove the "for j in coor loop" , how can i nest that with the "for i in ident" loop ? something like for i in ident and for bounds in coors: ?

          Again, thanks a lot for your answer !

          Edit : i changed my coor, i forgot to put the '[ ]', my bad !

          Comment

          • maubp
            Peter (Biopython etc)
            • Jul 2009
            • 1544

            #6
            Watch out for different counting conventions when you do the slicing...

            Also, you could ask the NCBI to pre-slice the records when you call Entrez.efetch by including the optional seq_start and seq_end arguments, see: http://www.ncbi.nlm.nih.gov/books/NB...hapter4.EFetch

            Comment

            • CrLs
              Junior Member
              • Jan 2014
              • 6

              #7
              Hello
              Yep thank you, i ll check it !
              Hmm, to use optionals arguments , i should put 3 loops ? one with genome, one with start and one with stop right ?( i want to slice the first genome with the first location, second genome with 2 location ect )

              Comment

              • maubp
                Peter (Biopython etc)
                • Jul 2009
                • 1544

                #8
                I would use ONE loop, something like this:

                Code:
                from Bio import Entrez, SeqIO
                Entrez.email = "[email protected]"
                for i, start, end in [('AE009948', 1256617, 1311411),
                                      ('AE009947', 1973169, 2005648)]:
                    print("Fetching %s:%i-%i now..." % (i, start, end))
                    #code here using Entrez.efetch(...)
                Last edited by maubp; 01-20-2014, 09:00 AM. Reason: typo

                Comment

                • CrLs
                  Junior Member
                  • Jan 2014
                  • 6

                  #9
                  Well, thanks you for your answer, i'll try your way and the old way, i ll keep the faster ! ( i dont know if one take more memory than the other )
                  Anyway, Thanks you a lot ! I come back with a working code when i'm done with it

                  Comment

                  • CrLs
                    Junior Member
                    • Jan 2014
                    • 6

                    #10
                    Ok Peter and Ryan thanks you for your help !
                    This is the working code, get you all the product ( or everything else you need ) between the location you want
                    Code:
                    >>> for i, start, end in [('AE009948', 1256617, 1311411),
                                          ('AE009948', 1973169, 2005648)]:
                    	handle = Entrez.efetch(db="nucleotide", id=i, seq_start=start,
                                seq_stop=end, rettype="gb")
                    	results2 = open('resultsRegion_note.csv', 'a')
                    	for seq_record in SeqIO.parse(handle, "gb"):
                    		results2.write('\n')
                    	for feature in seq_record.features:
                    			if feature.type=="CDS":
                    				results2.write(str(feature.qualifiers.get('product'))[1:-1])
                    	results2.close()
                    feel free to use (even if i think a lot of people can do the same )
                    Last edited by CrLs; 01-20-2014, 09:14 AM.

                    Comment

                    Latest Articles

                    Collapse

                    • SEQadmin2
                      Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
                      by SEQadmin2



                      Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

                      Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
                      ...
                      Yesterday, 09:55 AM
                    • 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
                      ...
                      09-28-2026, 10:25 AM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by SEQadmin2, Today, 10:52 AM
                    0 responses
                    8 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, Yesterday, 05:39 AM
                    0 responses
                    18 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 10-13-2026, 09:56 AM
                    0 responses
                    15 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 10-09-2026, 11:14 AM
                    0 responses
                    27 views
                    0 reactions
                    Last Post SEQadmin2  
                    Working...