-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-version-ctrl.txt
More file actions
166 lines (133 loc) · 5.37 KB
/
git-version-ctrl.txt
File metadata and controls
166 lines (133 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# 3
gene_list = ["AT1G0010", "AT1G0020", "AT1G0030", "AT1G0040", "AT1G0050",
"AT1G0060", "AT1G0070", "AT1G0080"]
for genes in gene_list:
print(genes)
#5
# Create reverse DNA sequence
def reverse(s):
"""
Function to create a DNA reverse sequence, starting from the end.
Parameters:
s (str): A string is taken as the input
Returns:
s (str): A reverse version of the input string is returned
"""
return (s[::-1])
# Complement function
def complement(s):
"""
The function creates a complementary DNA sequence
Parameters:
s(str): A string of DNA sequences is taken as the input
Returns:
Letters (str): A list consisting of the complementary DNA sequence
"""
# A dictionary that associates each string character (nucleotide) to its complementary character: A to T, C to G
basecomplement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A', 'a': 't', 'c': 'g',
'g': 'c', 't': 'a', 'M': 'K', 'K': 'M', 'R': 'Y', 'Y': 'R', 'W': 'W', 'S': 'S',
'V': 'B', 'B': 'V', 'H': 'D', 'D': 'H', 'N': 'N', '-': '-' }
# Create a list using the input string
letters = list(s)
# For loop to iterate through each base/letter in the list
letters = [basecomplement[base] for base in letters]
# Return statement to join each character in the list
return ''.join(letters)
# Reverse and Complementary function
def revcom(s):
"""
The function is a combination of the reverse and complement functions.
The input string is first reversed from the end, then the complementary string of the reversed string is produced
Parameters:
s(str): input
Return:
s (str): reversed and complementary string
"""
return complement(s[::-1])
#6
# Write a function that will parse a fasta file and produce a reverse complement.
def fasta_reverse_complement(fasta_file: str) -> dict[str, str]:
"""
Parses a FASTA file and produces the reverse complement of each DNA sequence.
Parameters:
fasta_file (str): The path to the FASTA file.
Returns:
dict[str, str]: A dictionary where keys are sequence identifiers (keys) and values are their reverse complements.
"""
# Create an empty dictionary to query
reverse_complements = {}
# Open the file
with open(fasta_file, 'r') as file:
sequence_id = None
# Create an empty list
sequence = []
# For Loop to iterate through the lines
for line in file:
# Strip whitespaces
line = line.strip()
# IF statement to specify a header
if line.startswith('>'):
# If we have a previous sequence, process it
if sequence_id is not None:
# join the sequences
full_sequence = ''.join(sequence)
# Use revcom function
reverse_complements[sequence_id] = revcom(full_sequence)
# Get the sequence identifier
sequence_id = line[1:]
# Reset the sequence list for the new sequence
sequence = []
else:
# append the sequences
sequence.append(line)
# Process the last sequence in the file
if sequence_id is not None:
full_sequence = ''.join(sequence)
reverse_complements[sequence_id] = revcom(full_sequence)
return reverse_complements
# Example usage:
fasta_file_path = 'Downloads/AB_test_dta.fasta'
reverse_complement_dict = fasta_and_reverse_complement(fasta_file_path)
for seq_id, rev_comp in reverse_complement_dict.items():
print(f"{seq_id}: {rev_comp}")
#7
def sort_numerical_list(numbers_list):
"""
This function takes a list of numerical strings and returns a list of sorted integers.
Parameters:
numbers_list (list): A list of strings representing numbers.
Returns:
list: A sorted list of integers in numerical order.
"""
# Convert strings to integers
numbers_as_integers = [int(num) for num in numbers_list]
# Sort the list
sorted_numbers = sorted(numbers_as_integers)
return sorted_numbers
# Corrected input list
numbers_list = ['98', '67', '112', '4', '45', '78', '99', '100', '-1', '7', '0']
# Call the function and print the result
sorted_numbers = sort_numerical_list(numbers_list)
print(sorted_numbers)
# 8
# Write a function that draws a number at random from the list given in Question 7
# Import random module
import random
# Create a function to draw numbers randomly from a list
def draw_random_number(numbers_list):
"""
This function draws a random number from the given list of numerical strings.
Parameters:
numbers_list (list): A list of strings representing numbers.
Returns:
int: A randomly selected number from the list.
"""
# Convert strings to integers because the list here has numerical strings
numbers_as_ints = [int(num) for num in numbers_list]
# Draw a random number
random_number = random.choice(numbers_as_ints)
return random_number
# Corrected input list
numbers_list = ['98', '67', '112', '4', '45', '78', '99', '100', '-1', '7', '0']
random_number = draw_random_number(numbers_list)
print("Randomly Selected Number:", random_number)