[BioPython] suggestion on Fasta.index_file()
CL WU
anewgene at hotpop.com
Mon Nov 24 12:59:09 EST 2003
I see. I think giving a optional filename argument is more flexible.
Thanks, Brad.
Chunlei
Brad Chapman wrote:
>Hi Chunlei;
>
>
>
>>However, the generated index file stores the absolute path for
>>fasta_seq_file,
>>
>>
>
>It should just store the filename for whatever you pass to the
>index_file function. The relevant code from Bio/Fasta/__init__.py
>is:
>
>def index_file(filename, indexname, rec2key=None):
> [...]
> index[Dictionary._Dictionary__filename_key] = filename
>
>So, if you just pass relative paths, you shouldn't have any problem
>with absolute file names. A solution you could use in your code
>without needing to modify Biopython is to do:
>
>start_dir = os.getcwd()
>os.chdir("whatever/the/directory/is")
>index_file("the_file.fasta", "the_index.idx")
>os.chdir(start_dir)
>
>Then you would have an index with a relative path and you could
>change into this directory later to open the index.
>
>os.chdir("whatever/the/directory/is")
>dict = Fasta.Dictionary("the_index.idx")
>
>
>
>>For my case, I store fasta_seq_file and its index file at a network
>>drive and I need to access it from both windows and linux server. The
>>original index file can not be used for both environments. To solve this
>>problem, I modified two lines of Bio/Fasta/__init__.py as below. As the
>>result, it require the index file is placed at the same directory of
>>fasta_seq_file.
>>
>>
>[...]
>
>
>>Do you it's worth to make this modification? Or, any better solution?
>>
>>
>
>I'm not a big fan of restricting the index file and fasta file to
>the same directory. A backwards compatible solution would be to
>allow Dictionary to take a filename the index points to as an
>optional argument.
>
> def __init__(self, indexname, parser=None, filename = None):
> self._index = Index.Index(indexname)
> if filename:
> self._handle = open(filename)
> else:
> self._handle = open(self._index[Dictionary.__filename_key])
> self._parser = parser
>
>Does this solution seem reasonable? Or will the os.chdir solution
>work for you?
>
>Hope this helps.
>Brad
>_______________________________________________
>BioPython mailing list - BioPython at biopython.org
>http://biopython.org/mailman/listinfo/biopython
>
>
>
More information about the BioPython
mailing list