def main(argv=None): if argv is None: argv=sys.argv[1:] parser = argparse.ArgumentParser(description="A program to count the number of expected amplifications for a set of forward and reverse primer landing sites in multiple strand displacement amplification. The command generates a csv file (default: output.csv, use `-o` or `--output` to change) with 3 columns; start of region, end of region, expected amplifications.") parser.add_argument("-v","--verbose", help="increase output verbosity", action="store_true") parser.add_argument("-f","--forwardPrimers", help="a text file containing the 1-based position of the first base of all primer landing sites on the forward strand separated by space or new lines",type=check_file,required=True) parser.add_argument("-r","--reversePrimers", help="a text file containing the 1-based position of the last base of all primer landing sites on the reverse strand separated by space or new lines",type=check_file,required=True) parser.add_argument("-l","--maxLength", help="an integer giving the maximum length expected for the polymerase ",type=check_positive_int,default=30000) parser.add_argument("-g","--genomeSize", help="an integer giving the maximum position possible for primers (if < 1 then set to the maximum position covered by primers)",type=int,default=-1) parser.add_argument("-o","--outFile", help="file to write to ",default="out.csv") args=parser.parse_args(argv) if args.verbose: print("Arguments: ") for key, value in vars(args).items(): print(" "+key+": "+str(value)) if args.genomeSize<1: genomeSize=float("inf") else: genomeSize=args.genomeSize if args.verbose: print('Reading forwards') forwards=readBindingSites(args.forwardPrimers) if args.verbose: print('Reading reverses') reverses=readBindingSites(args.reversePrimers) if args.verbose: print('Predicting forward amplifications') predictedAmps=predictAmplifications(forwards,reverses,args.maxLength,genomeSize) if args.verbose: print('Writing to '+args.outFile) with open(args.outFile, 'w') as f: f.write("start,end,amps\n") for start,end,amp in predictedAmps: f.write("%d,%d,%d\n" % (start,end,amp)) if args.verbose: print('All done. Thanks')
def test_predictAmplications(): assert max([x[2] for x in ampcountpy.predictAmplifications([1,2,3],[4,5,6])]) == 38 assert all([x[0]==y[0] and x[1]==y[1] and x[2]==y[2] for x,y in zip(ampcountpy.predictAmplifications([1,2,3],[4,5,6]),ampcountpy.predictAmplifications([3,2,1],[6,5,4]))]) assert all([x[0]==y[0] and x[1]==y[1] and x[2]==y[2] for x,y in zip(ampcountpy.predictAmplifications([1,3,2],[5,6,4]),ampcountpy.predictAmplifications([3,2,1],[6,5,4]))]) assert len(ampcountpy.predictAmplifications([1,2,3],[4,5,6],3)) == 6 assert len(ampcountpy.predictAmplifications([1,2,3],[4,5,6],10)) == 8 assert len(ampcountpy.predictAmplifications([1],[3],3)) == 1 assert len(ampcountpy.predictAmplifications([1],[])) == 1 assert len(ampcountpy.predictAmplifications([],[1])) == 1 assert len(ampcountpy.predictAmplifications(range(1,101,1),[])) == 199 assert len(ampcountpy.predictAmplifications([x+1e6 for x in range(1,101,1)],[])) == 199 assert ampcountpy.predictAmplifications([1],[])[0][2] == 1 assert ampcountpy.predictAmplifications([],[1])[0][2] == 1 assert ampcountpy.predictAmplifications([1],[3],3)[0][2] == 2 assert all([x[2]==y for x,y in zip(ampcountpy.predictAmplifications([1,3],[3],3),[2,4,1])]) assert all([x[2]==y for x,y in zip(ampcountpy.predictAmplifications([1,3],[3,5],3),[2,10,2])]) assert all([x[0]==y for x,y in zip(ampcountpy.predictAmplifications([1,3],[3,5],3),[1,3,4])]) assert all([x[1]==y for x,y in zip(ampcountpy.predictAmplifications([1,3],[3,5],3),[2,3,5])]) assert all([x[2]==y for x,y in zip(ampcountpy.predictAmplifications([1,2],[15],10),[1,2,3,2,1])]) assert all([x[2]==y for x,y in zip(ampcountpy.predictAmplifications([1,2],[15,16],10),[1,2,3,4,3,2,1])]) with pytest.raises(IndexError): ampcountpy.predictAmplifications([x+1 for x in range(ampcountpy.ampcount._MAXLOOKUP+1)],[1]) with pytest.raises(IndexError): ampcountpy.predictAmplifications([1],[x+1 for x in range(ampcountpy.ampcount._MAXLOOKUP+1)])