Hi Massa, This worked amazing yesterday after changing a few little things.
Opening it up today to try it out again and now each file grows by the size of threshold and I can't figure out what has changed, same input file same script. Could you have a quick look please?
FileInput = input('What is full address of the file you need to work with?, alternately save this script to your working directory. ' )
FileOutPut = input('What is the address of the Directory you want saving to? (ending with a /)')
OrganismOI = input('What organism are you looking at? ')
ChunkSize = int(input("What is the chunk size (in bp) you want per file? "))
File = open(FileInput, 'r')
Read = File.readline()
ToWrite = []
Length = 0
Counter = 0
while Read:
ToWrite.append(Read)
Length += len(Read)-1
if Length > ChunkSize:
with open(FileOutPut + OrganismOI + '|{}'.format(Counter) + '.fa', 'w') as o:
o.write(''.join(ToWrite))
Counter += 1
to_write = []
Length = 0
Read = File.readline()
with open(FileOutPut + OrganismOI + '|{}'.format(Counter) + '.fa', 'w') as o:
o.write(''.join(ToWrite))
Can you clarify, is this meant to segregate whole sequences into numbered chunks (e.g. a file with 30 sequences, splits those sequences in to 3 files of 10 sequences), or is the intention to chop up the seqeunces themselves in to windows (e.g. a file with 30 sequences, split in to 30 files, each containing one sequence, broken into windows of length n)?
To you last point, really any number of books and websites exist to help learn, but I am personally an advocate of just learning-by-doing. For me at least, its the fastest way. Write code. Write lots. Write bad code. Pick up new and better habits from code you find online. Make the bad code a bit less bad. Rinse and repeat.
Of course, I have the whole genome for Salmonella CT18 in a basic non annotated nucleotide FASTA format. Say I want to break it into chunks of 50kb to ease processing downstream. I think later on, it will be use full to break it into chunks with a number of gene sequences but not yet.
And thanks, that's what I'm trying to do but i'm clearly going wrong somewhere.
Not directly since BioStar handbook does not cover python programming. If you do purchase the book you get access to "Python programming in 100 hours", a separate series of video lectures that Prof. Istvan Alberts is including with the book. Unfortunately he has not completed that series yet since there are only 4 videos currently available.