Explore BrainMass
Share

# Java - Magic Square

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

See the attached file.
Magic squares. An n × n matrix that is filled with the numbers 1, 2, 3, ... , n2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value. For example,

Write a program that reads in n2 values from the keyboard and tests whether they form a magic square when arranged as a square matrix. You need to test three features:
• Did the user enter n2 numbers for some n?
• Do each of the numbers 1, 2, ... , n2 occur exactly once in the user input?
• When the numbers are put into a square, are the sums of the rows, columns, and diagonals equal to each other?
If the size of the input is a square, test whether all numbers between 1 and n2 are present. Then compute the row, column, and diagonal sums. Implement a class Square with methods

public boolean isMagic()
Here is a sample program run:
Enter a sequence of integers, followed by Q:
16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1
Q
It is a magic square.
Use the following class as your main class:
import java.util.ArrayList;
import java.util.Scanner;

/**
This class tests whether a sequence of inputs forms a magic square.
*/
public class MagicSquareChecker
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
Square sq = new Square();

System.out.println("Enter a sequence of integers, followed by Q: ");
while (in.hasNextInt())
{
}

if(sq.isMagic())
System.out.println("It is a magic square.");
else
System.out.println("It is not a magic square.");
}
}
You need to supply the following class in your solution:
Square.

https://brainmass.com/computer-science/arrays/java-magic-square-467521

#### Solution Summary

Java magic squares are examined in the solution.

\$2.19

## Microarray Installing MAGIC Software

SECTION #1. In this section of the lab, we will use the MAGIC software to extract data from scanned microarray images. You will be guided through the process of downloading and installing the MAGIC software, and then we will use this software to analyze example microarray scan images. We will practice extracting data from an example microarray images using the gridding and image analysis tools provided in MAGIC.

1. Go to the website for the MAGIC software, which can be found at the following webpage: http://www.bio.davidson.edu/projects/MAGIC/MAGIC.html

3. Scroll to the bottom of the page, and click on the 'I accept' button to agree to the software license.

5. Unzip the MagicTool_2-1.zip file, and place the unzipped folder (MagicTool_2-1) in an appropriate directory (or the desktop) of your computer.

6. Return to the MAGIC web page (http://www.bio.davidson.edu/projects/MAGIC/MAGIC.html). Scroll down the page, and click the link for 'Download small sample files' (1 grid and 4 grid) for practice.

7. When the Sample_Files.zip file is finished downloading, unzip the file to generate the Sample_Files Directory. Move the Sample_Files directory into the MagicTool_2-1 directory.

8. Open the MagicTool_2-1 folder. This folder contains the MAGIC software programs and pdf files containing a user's guide and installation guide. If you have difficulty installing or running the MAGIC, please consult these files for more help.

9. If you are using a Windows PC, double click the Magic_launch.bat file in the MagicTool_2-1 directory. If you are using a Macintosh computer, double click the MAGIC_launch file. If you are using a different operating system, consult the installation guide for instructions on starting MAGIC.

10. The MAGIC software should start. If you encounter problems in starting MAGIC, please consult the installation guide and user guide for more assistance.

B. Addressing the Grid to Sample Microarray Images
1. In the MAGIC software window, select the 'New Project' option under the Project Menu. You will be prompted to save the project in a folder on your computer. Save the new project as Test_grid1 and select a folder in which to save the file (e.g., under the Sample_Files directory).

2. Select the 'Load Image Pair' option under the Build Expression File Menu. Select the 'Red' option, and load the file Red_4grid.tif which is located in the Sample_Files directory. Next, select the 'Green' option and load the file Green_4grid.tif which is also located in the Sample_Files directory. Note that Red refers to the Cy5 microarray scan, and Green refers to the Cy3 microarray scan.

3. Select the 'Load Gene List' option under the Build Expression File Menu. Select the 4Grid_MT_genelist.txt file, which is located in the Sample_Files directory.

4. Select the 'Addressing/Gridding' option under the Build Expression File Menu. Select the Create/Edit Grid option.

5. In the 'Grid Setup' dialog box, type the number 4 in the blank next to 'How many grids?' Keep the default options for grid set-up, and click 'OK'.

6. You should see a picture of the combined Cy3 and Cy5 microarray scans. There are four subgrids, and each subgrid should contain 23 rows and 24 columns. The subgrids are separated by spaces. The spots were printed in duplicate; duplicate gene spots are in adjacent columns. The red and green colors indicate the Cy5 and Cy3 fluorescent intensities for each spot, corresponding to the relative expression level of the corresponding gene in the Cy5 and Cy3 experimental samples.

Why are some spots yellow in color? What does this indicate about the relative expression levels of that gene in the Cy5 versus Cy3 experimental samples?

7. Move the slider on the 'Percent contrast change' box to 500. How did the microarray image change?________________________________________________________________

8. Click the 'Zoom in' button in the top left corner of the window. Click on the top left corner of the microarray image twice. You should zoom in on the top left grid of the microarray image.

9. The next step is to align a grid that matches the spot positions for the microarray. We will align a grid for each of the four subgrids that are present on the microarray. We will start with the grid in the upper left corner (Grid 1). A grid is aligned by selecting the middle of the spot in the (1) upper left corner of the grid (row 1, column 1 of the subgrid), (2) the spot in the upper right corner of the grid (row 1, column 24 of the subgrid), and (3) any spot in the bottom row of the subgrid (row 23).

10. Click the 'Set Top Left Spot' button on the left side of the window. Then click in the middle of the spot in the top left corner of the first subgrid (row 1, column 1). Note that the signal from this spot is very weak, but you should still be able to see the spot with the contrast set to 500. What coordinates appear in the 'x' and 'y' boxes after clicking the spot?

x coordinate? ___________ y coordinate? ______________

11. Next, click the 'Set Top Right Spot' button on the left side of the window. Then click in the middle of the spot in the top right corner of the first subgrid (row 1, column 24). Again, the signal from this spot will be relatively weak. Make sure the spot is still in subgrid #1 (i.e., don't click the spot in the top right corner of the whole microarray image, as this will be in subgrid #2).

12. Finally, click the 'Set Bottom Row' button on the left side of the window. Then click in the middle of any spot in the last row of the first subgrid (row 23). Make sure that bottom row is still in the first subgrid. There should now be x and y coordinate values for the top left, top right and bottom row spots.

13. On the left of the window, type the number 23 in the blank next to Rows, and type the number 24 in the blank next to Columns. These blanks specify the number of rows and columns in the subgrid.
This database contains a variety of information about prokaryote genomes and proteomes.

14. Click the UPDATE button. A grid of squares should appear over the first subgrid in the microarray. Each spot should be in the middle of a square. If the grid is not correctly aligned, you can move the grid by clicking on it and dragging it to the correct position, and by using the 'Rotate Grid' buttons in the bottom left corner of the window.

15. Mouse over (or point at) the square in the top left corner of the grid. The X and Y coordinates and gene name of this spot will be listed in the gray border at the bottom of the window.

What is the Gene name for the spot/square in row 1, column 1 (top left corner)? _____________

What is the Gene name for the spot/square in row 1, column 2? ________________

Why are the Gene names the same (hint: see the first part of step #6 above)?

C. Addressing the Other Subgrids in the Microarray Image.
1. On the left side of the window, there are four tabs numbered 1, 2, 3, and 4. You should be on tab 1, corresponding to the first subgrid. Click on tab 2. This tab corresponds to the second subgrid, which is located in the top right corner of the microarray image.

2. Click the 'Set Top Left Spot' button on the left side of the window. Then click in the middle of the spot in the top left corner of subgrid #2. Note that subgrid #2 is the subgrid located in the top right corner of the image. The x and y coordinates of the top left spot of subgrid #2 should be approximately: x = 468, y = 15.

3. Click the button 'Apply from Grid' and select 1 (subgrid 1). A grid should appear over subgrid #2. If the grid is not correctly aligned, you can move the grid by clicking on it and dragging it to the correct position, and by using the 'Rotate Grid' buttons in the bottom left corner of the window.

4. Mouse over (or point at) the square in the top left corner of subgrid #2. What is the Gene name for the spot/square in row 1, column 1 of subgrid #2? _____________________

5. Click on tab 3. This tab corresponds to the third subgrid, which is located in the bottom left corner of the microarray image.

6. Click the 'Set Top Left Spot' button on the left side of the window. Then click in the middle of the spot in the top left corner of subgrid #3. Note that this spot is very faint, and can be difficult to see. The x and y coordinates of the top left spot of subgrid #3 should be approximately: x = 19, y = 469.

7. Click the button 'Apply from Grid' and select 1 (subgrid 1). A grid should appear over subgrid #3. If the grid is not correctly aligned, you can move the grid by clicking on it and dragging it to the correct position, and by using the 'Rotate Grid' buttons in the bottom left corner of the window.

8. Mouse over (or point at) the square in the top left corner of subgrid #3. What is the Gene name for the spot/square in row 1, column 1 of subgrid #3? _____________________

9. Click on tab 4. This tab corresponds to the fourth subgrid, which is located in the bottom right corner of the microarray image.

10. Click the 'Set Top Left Spot' button on the left side of the window. Then click in the middle of the spot in the top left corner of subgrid #4. The x and y coordinates of the top left spot of subgrid #4 should be approximately: x = 464, y = 465.

11. Click the button 'Apply from Grid' and select 1 (subgrid 1). A grid should appear over subgrid #4. If the grid is not correctly aligned, you can move the grid by clicking on it and dragging it to the correct position, and by using the 'Rotate Grid' buttons in the bottom left corner of the window.

12. Mouse over (or point at) the square in the top left corner of subgrid #4. What is the Gene name for the spot/square in row 1, column 1 of subgrid #4? _____________________

13. Click the 'Done!' button to finish gridding.

14. How many genes have you gridded and named? ____________________

15. Save the grid file as 478_grid.

D. Segmenting/Extracting Data from Microarray Image.
1. Select the 'Segmentation' option under the Build Expression File Menu. This tool will define the key parameters for extracting the fluorescence intensity data for each spot from the microarray image.

2. In the left panel, click the button 'Jump to Gene Name'. In the pop-up window, enter the gene name: YAL041W_rep1

3. The images shown to the left are close-up views of the signal intensity of the YAL041W_rep1 spot in the red (Cy5) and green (Cy3) channels. The red circle indicates the region that is being used to extract signal intensity data. Signal inside the red circle is included in the fluorescent intensity of the spot. Signal outside the red circle is taken for the background.

4. Examine the box on the left labeled 'Data for: YAL041W_rep1'. The Red FG Total gives the total signal intensity for the spot in the red channel (Cy5). The Green FG Total gives the total signal for the spot in the green (Cy3) channel. The Red BG Total and Green BG Total values give the local background intensity for this spot.

What is the total signal intensity for the red channel (Cy5) for YAL041W_rep1? ________________

What is the background intensity for the red channel (Cy5)? ___________________________

What is the ratio of red intensity/green intensity? (Hint: see 'Ratio' entry) ____________________
What is the background-subtracted intensity for the red channel for YAL041W_rep1? (hint: calculate

this from the values above). _______________________

5. In the menu under 'Choose Ratio Method:', select the option 'Total Signal BG subtraction'. This option subtracts the background intensities prior to calculating the ratio of red intensity/green intensity.

What is the new ratio of red intensity/green intensity? ______________________________

6. In the menu under 'Choose Ratio Method:', select the option 'Average Signal BG subtraction'.

What is the average intensity (FG AVG) for the green channel for YAL041W_rep1? ______________

What is the average background intensity (BG AVG) for the green channel? ____________________

7. In the Parameters Window, change the (Fixed) Radius to 5 pixels.

8. Click the 'Update Data' button. The red circle in the image on the right should shrink in size.

What is the new average intensity (FG AVG) for the green channel? ____________________

Briefly explain why the average intensity of the green channel increased with a smaller fixed radius.

9. In the menu under the header 'Choose Segmentation Method', select the option 'Adaptive Circle'. Click the Update Data button. A new fixed circle should appear in the image on the right.

What is the new average intensity (FG AVG) for the green channel? ____________________

10. In the menu under the header 'Choose Segmentation Method', select the option 'Seeded Region Growing'. Click the Update Data button. Red squares should appear in the image on the right. These are the pixels that define the spot intensity.

What is the new average intensity (FG AVG) for the green channel? ____________________
11. Which methods appear to do a better job of defining the spot and calculating an accurate signal intensity? Explain your reasoning.

12. In the menu under the header 'Choose Segmentation Method', select the option 'Fixed Circle'. Set the radius to six pixels. Click the Update Data button. A new fixed circle should appear in the image on the right.

E. Flagging Low Intensity Spots and Extracting the Gene Expression Intensity Data.
1. Use the scroll bar between the images and the options (on the left) to scroll down to click the 'Automatic Flagging Options' button.

2. Click/check the boxes next to Red Foreground and Green Foreground. Type the number 10,000 in the blanks next to Red Foreground and Green Foreground. Click OK and then Yes. This option flags spots whose total red or green signal intensity is less than 10,000. These low intensity spots are likely to be very dim or missing in the microarray, and thus it is important to flag them.

How many spots were flagged automatically? ________________________

What percentage of the spots on the microarray were flagged? __________________________

3. Click the 'MA Plot' button, near the bottom of the page (you may need to scroll down). Inspect the MA Plot.

4. Click the Create Expression File button, near the bottom of the page (you may need to scroll down).

5. In the blank next to Enter Expression Filename, type 478_expression_data

6. In the blank next to Enter Column Name, type 478_ratio

7. Click OK.

8. We are finished extracting data from the microarray image. Exit the MAGIC program by selecting the 'Exit' option under the Project Menu. Make sure to keep the files handy, as we will use the expression data and MAGIC program in Microarray Analysis II.

View Full Posting Details