Conditions | 1 |
Total Lines | 51 |
Code Lines | 20 |
Lines | 51 |
Ratio | 100 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | #!/usr/bin/env python |
||
22 | View Code Duplication | def get_parser(): |
|
|
|||
23 | parser = argparse.ArgumentParser( |
||
24 | description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) |
||
25 | |||
26 | #parser.add_argument('-', "--", help="", default="") |
||
27 | |||
28 | parser.add_argument('--save-to-file', help='<pdb>.fa', action='store_true') |
||
29 | |||
30 | parser.add_argument('--compact', |
||
31 | help=textwrap.dedent("""with --get-seq, get it in compact view' |
||
32 | $ rna_pdb_tools.py --get-seq --compact *.pdb |
||
33 | # 20_Bujnicki_1 |
||
34 | ACCCGCAAGGCCGACGGCGCCGCCGCUGGUGCAAGUCCAGCCACGCUUCGGCGUGGGCGCUCAUGGGU # A:1-68 |
||
35 | # 20_Bujnicki_2 |
||
36 | ACCCGCAAGGCCGACGGCGCCGCCGCUGGUGCAAGUCCAGCCACGCUUCGGCGUGGGCGCUCAUGGGU # A:1-68 |
||
37 | # 20_Bujnicki_3 |
||
38 | ACCCGCAAGGCCGACGGCGCCGCCGCUGGUGCAAGUCCAGCCACGCUUCGGCGUGGGCGCUCAUGGGU # A:1-68 |
||
39 | # 20_Bujnicki_4 |
||
40 | |||
41 | """), action='store_true') |
||
42 | |||
43 | parser.add_argument('--color-seq', help='color seq, works with --get-seq', action='store_true') |
||
44 | |||
45 | parser.add_argument('--chain-first', help="", action='store_true') |
||
46 | |||
47 | parser.add_argument('--fasta', |
||
48 | help= textwrap.dedent("""with --get-seq, show sequences in fasta format, |
||
49 | can be combined with --compact (mind, chains will be separated with ' ' in one line) |
||
50 | |||
51 | $ rna_pdb_tools.py --get-seq --fasta --compact input/20_Bujnicki_1.pdb |
||
52 | > 20_Bujnicki_1 |
||
53 | ACCCGCAAGGCCGACGGC GCCGCCGCUGGUGCAAGUCCAGCCACGCUUCGGCGUGGGCGCUCAUGGGU |
||
54 | |||
55 | """), action='store_true') |
||
56 | parser.add_argument('--oneline', help="", action='store_true') |
||
57 | |||
58 | |||
59 | parser.add_argument('--uniq', help=textwrap.dedent(""" |
||
60 | rna_pdb_tools.py --get-seq --uniq '[:5]' --compact --chain-first * | sort |
||
61 | A:1-121 ACCUUGCGCAACUGGCGAAUCCUGGGGCUGCCGCCGGCAGUACCC...CA # rp13nc3295_min.out.1 |
||
62 | A:1-123 ACCUUGCGCGACUGGCGAAUCCUGAAGCUGCUUUGAGCGGCUUCG...AG # rp13cp0016_min.out.1 |
||
63 | A:1-123 ACCUUGCGCGACUGGCGAAUCCUGAAGCUGCUUUGAGCGGCUUCG...AG # zcp_6537608a_ALL-000001_AA |
||
64 | A:1-45 57-71 GGGUCGUGACUGGCGAACAGGUGGGAAACCACCGGGGAGCGACCCGCCGCCCGCCUGGGC # solution |
||
65 | """)) |
||
66 | |||
67 | parser.add_argument('--renum-atoms', help='renumber atoms, tested with --get-seq', |
||
68 | action='store_true') |
||
69 | parser.add_argument("-v", "--verbose", |
||
70 | action="store_true", help="be verbose") |
||
71 | parser.add_argument("file", help="", default="") # nargs='+') |
||
72 | return parser |
||
73 | |||
136 |