On Monday, April 24, 2017 at 3:52:09 PM UTC-4, Peter Otten wrote:
> Unaiza Batool wrote:
>
> > i'm confused here as the script gives an error saying simple_to_fasta and
> > fasta_to_mafft are not defined.
>
> You have to write this functions yourself (I gave one example) and make sure
> that they are defined before the 'for barcode' loop.
>
> > How do I combine the part of infile,
> > outfile with the conversion. You said it should go in the for barcode
> > loop? Or just it just go after infname has it's correct value or just
> > before each command when the new output file is needed?
>
> A sketch of the final script (pseudo code, not runnable Python):
>
> for barcode in barcodes
> write simple file
> convert simple file to fasta
> convert fasta file to mafft
> etc
>
> To illustrate the idea here's a runnable example that reads words from a
> file into individual files, then converts them to upper case, then
> intersperses them with "-":
>
> $ ls
> demo.py words.txt
> $ cat words.txt
> the
> quick
> brown
> fox
> $ cat demo.py
> def convert_to_upper(infile, outfile):
> with open(infile) as instream:
> with open(outfile, "w") as outstream:
> outstream.write(instream.read().upper())
>
> def convert_to_interspersed(infile, outfile):
> with open(infile) as instream:
> with open(outfile, "w") as outstream:
> outstream.write("-".join(instream.read()))
>
> with open("words.txt") as words:
> for word in words:
> word = word.strip()
> filename = word
> with open(filename, "w") as f:
> f.write(word)
> convert_to_upper(filename, filename + ".upper")
> convert_to_interspersed(
> filename + ".upper",
> filename + ".interspersed"
> )
> $ python demo.py
> $ ls
> brown fox quick.interspersed the.upper
> brown.interspersed fox.interspersed quick.upper words.txt
> brown.upper fox.upper the
> demo.py quick the.interspersed
> $ cat quick.interspersed
> Q-U-I-C-K$
Oh my god, thank you so much. You have no idea how much you literally saved my
life. Pretty much all I changed was increasing indentation on everything to
make sure it's within the for barcode in barcodefile loop and now my script is
running for all output files!
--
https://mail.python.org/mailman/listinfo/python-list