def testSubtractNothing(self): """ When two input files have no overlap, subtraction must result in the same reads as are in the first input. """ fasta1 = '\n'.join([ '>one', 'agtcagtcagtc', '>two', 'acctg', '>three', 'atgggtc', '>four', 'atggctattgaactgtatct', ]) fasta2 = '\n'.join([ '>five', 'agtcagtcagtc', '>six', 'acctg', ]) result = list(fastaSubtract([StringIO(fasta1), StringIO(fasta2)])) self.assertEqual(['four', 'one', 'three', 'two'], sorted([seq.id for seq in result]))
def testThreeFiles(self): """ Subtraction of three files must work correctly. """ fasta1 = '\n'.join([ '>one', 'agtcagtcagtc', '>two', 'acctg', '>three', 'atgggtc', '>four', 'atggctattgaactgtatct', ]) fasta2 = '\n'.join([ '>one', 'agtcagtcagtc', ]) fasta3 = '\n'.join([ '>two', 'acctg', '>three', 'atgggtc', ]) result = list(fastaSubtract([StringIO(fasta1), StringIO(fasta2), StringIO(fasta3)])) self.assertEqual(len(result), 1) self.assertEqual(str(result[0].seq), 'atggctattgaactgtatct') self.assertEqual(str(result[0].id), 'four')
def testThreeFiles(self): """ Subtraction of three files must work correctly. """ fasta1 = '\n'.join([ '>one', 'agtcagtcagtc', '>two', 'acctg', '>three', 'atgggtc', '>four', 'atggctattgaactgtatct', ]) fasta2 = '\n'.join([ '>one', 'agtcagtcagtc', ]) fasta3 = '\n'.join([ '>two', 'acctg', '>three', 'atgggtc', ]) result = list( fastaSubtract( [StringIO(fasta1), StringIO(fasta2), StringIO(fasta3)])) self.assertEqual(len(result), 1) self.assertEqual(str(result[0].seq), 'atggctattgaactgtatct') self.assertEqual(str(result[0].id), 'four')
def testSubtractFromNothing(self): """ When the first file is empty, the result shoud be too. """ fasta1 = '' fasta2 = '\n'.join([ '>five', 'agtcagtcagtc', '>six', 'acctg', ]) result = list(fastaSubtract([StringIO(fasta1), StringIO(fasta2)])) self.assertEqual([], result)
def testOneFile(self): """ When just one file is passed we should get a result that has as many reads as was in the single input file. """ fasta1 = '\n'.join([ '>one', 'agtcagtcagtc', '>two', 'acctg', '>three', 'atgggtc', '>four', 'atggctattgaactgtatct', ]) result = list(fastaSubtract([StringIO(fasta1)])) self.assertEqual(len(result), 4)
def testSubtractEverything(self): """ When two input files have the same reads, subtraction must result in an empty (no reads) output. """ fasta1 = '\n'.join([ '>one', 'agtcagtcagtc', '>two', 'acctg', '>three', 'atgggtc', '>four', 'atggctattgaactgtatct', ]) result = list(fastaSubtract([StringIO(fasta1), StringIO(fasta1)])) self.assertEqual([], result)
#!/usr/bin/env python import sys from Bio import SeqIO from dark import fasta if __name__ == '__main__': if len(sys.argv) == 1: print >>sys.stderr, 'Usage: %s 1.fasta, 2.fasta, ... > seq.fasta' % ( sys.argv[0]) sys.exit(1) else: reads = fasta.fastaSubtract(map(open, sys.argv[1:])) SeqIO.write(reads, sys.stdout, 'fasta')
#!/usr/bin/env python from __future__ import print_function import sys from Bio import SeqIO from dark import fasta if __name__ == '__main__': if len(sys.argv) == 1: print('Usage: %s 1.fasta, 2.fasta, ... > seq.fasta' % (sys.argv[0]), file=sys.stderr) sys.exit(1) else: reads = fasta.fastaSubtract(map(open, sys.argv[1:])) SeqIO.write(reads, sys.stdout, 'fasta')